wake_command

This commit is contained in:
mwiegand 2022-02-12 18:23:09 +01:00
parent 78b324903d
commit 6727fcf404
2 changed files with 21 additions and 13 deletions

View file

@ -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( @metadata_reactor.provides(
'apt/packages/ethtool', 'apt/packages/ethtool',
'systemd/units/enable-wol', 'systemd/units/enable-wol',
'systemd/services/enable-wol.service', 'systemd/services/enable-wol.service',
) )
def systemd(metadata): def systemd(metadata):
interfaces = set( interface = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/interface")
conf['interface']
for conf in metadata.get('network').values()
if conf.get('wol', False)
)
if not interfaces:
return {}
return { return {
'apt': { 'apt': {
@ -28,10 +39,7 @@ def systemd(metadata):
'Service': { 'Service': {
'Type': 'oneshot', 'Type': 'oneshot',
'RemainAfterExit': 'yes', 'RemainAfterExit': 'yes',
'ExecStart': set( 'ExecStart': f'ethtool -s {interface} wol g',
f"ethtool -s {interface} wol g"
for interface in interfaces
),
}, },
'Install': { 'Install': {
'WantedBy': 'multi-user.target', 'WantedBy': 'multi-user.target',

View file

@ -20,7 +20,6 @@
'ipv4': '10.0.0.5/24', 'ipv4': '10.0.0.5/24',
'gateway4': '10.0.0.1', 'gateway4': '10.0.0.1',
'mac': 'd8:cb:8a:e7:be:c6', 'mac': 'd8:cb:8a:e7:be:c6',
'wol': True,
}, },
}, },
'backup-server': { 'backup-server': {
@ -38,6 +37,7 @@
}, },
}, },
'wol-sleeper': { 'wol-sleeper': {
'network': 'internal',
'waker': 'home.server', 'waker': 'home.server',
}, },
'zfs-mirror': { 'zfs-mirror': {