From a73f090fe21908a5f7063cd7c387471f3d847056 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 3 Jan 2016 17:13:06 -0600 Subject: [PATCH] cli: Add wake subcommand --- src/rouse/cli.py | 18 ++++++++++++++++++ src/rouse/client.py | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/rouse/cli.py b/src/rouse/cli.py index 412beae..ae4e0f3 100644 --- a/src/rouse/cli.py +++ b/src/rouse/cli.py @@ -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() diff --git a/src/rouse/client.py b/src/rouse/client.py index 55f4723..92947fe 100644 --- a/src/rouse/client.py +++ b/src/rouse/client.py @@ -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))