cli: Add wake subcommand
parent
e5315a6792
commit
a73f090fe2
|
@ -78,6 +78,18 @@ def set_host(args):
|
|||
print_host(host)
|
||||
|
||||
|
||||
def wake_host(args):
|
||||
rouse = client.Rouse()
|
||||
keywords={}
|
||||
keywords['macaddr'] = args.hint
|
||||
keywords['ipaddr'] = args.hint
|
||||
keywords['hostname'] = args.hint
|
||||
hosts = client.Host.find(rouse=rouse, **keywords)
|
||||
for host in hosts:
|
||||
print('Sending WOL magic packet to {}'.format(host.macaddr))
|
||||
host.wake()
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
sp = parser.add_subparsers(metavar='command')
|
||||
|
@ -116,6 +128,12 @@ def parse_args():
|
|||
help='Hostname')
|
||||
p_set.set_defaults(func=set_host)
|
||||
|
||||
p_wake = sp.add_parser('wake', help='Wake host')
|
||||
p_wake.add_argument('hint',
|
||||
help='Hostname, IP address, or MAC address of host to'
|
||||
'wake')
|
||||
p_wake.set_defaults(func=wake_host)
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
|
|
|
@ -128,3 +128,6 @@ class Host(host.Host):
|
|||
|
||||
def update(self):
|
||||
self.rouse.put('/{}'.format(self.id), **self.as_dict())
|
||||
|
||||
def wake(self):
|
||||
self.rouse.post('/{}/wake'.format(self.id))
|
||||
|
|
Loading…
Reference in New Issue