diff --git a/bundles/wol-sleeper/metadata.py b/bundles/wol-sleeper/metadata.py index a3f0852..d770675 100644 --- a/bundles/wol-sleeper/metadata.py +++ b/bundles/wol-sleeper/metadata.py @@ -1,17 +1,28 @@ +from ipaddress import ip_interface + + +@metadata_reactor.provides( + 'wol-sleeper/wake_command', +) +def wake_command(metadata): + waker_hostname = repo.get_node(metadata.get('wol-sleeper/waker')).hostname + mac = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/mac") + ip = ip_interface(metadata.get(f"network/{metadata.get('wol-sleeper/network')}/ipv4")).ip + + return { + 'wol-sleeper': { + 'wake_command': f"ssh wol@{waker_hostname} 'wakeonlan {mac} && while ! ping {ip} -c1 -W3; do true; done'", + }, + } + + @metadata_reactor.provides( 'apt/packages/ethtool', 'systemd/units/enable-wol', 'systemd/services/enable-wol.service', ) def systemd(metadata): - interfaces = set( - conf['interface'] - for conf in metadata.get('network').values() - if conf.get('wol', False) - ) - - if not interfaces: - return {} + interface = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/interface") return { 'apt': { @@ -28,10 +39,7 @@ def systemd(metadata): 'Service': { 'Type': 'oneshot', 'RemainAfterExit': 'yes', - 'ExecStart': set( - f"ethtool -s {interface} wol g" - for interface in interfaces - ), + 'ExecStart': f'ethtool -s {interface} wol g', }, 'Install': { 'WantedBy': 'multi-user.target', diff --git a/nodes/home.backups.py b/nodes/home.backups.py index 09c92cd..527785d 100644 --- a/nodes/home.backups.py +++ b/nodes/home.backups.py @@ -20,7 +20,6 @@ 'ipv4': '10.0.0.5/24', 'gateway4': '10.0.0.1', 'mac': 'd8:cb:8a:e7:be:c6', - 'wol': True, }, }, 'backup-server': { @@ -38,6 +37,7 @@ }, }, 'wol-sleeper': { + 'network': 'internal', 'waker': 'home.server', }, 'zfs-mirror': {