diff --git a/confluent_client/bin/nodepower b/confluent_client/bin/nodepower index 4eea87ae..a795f63d 100755 --- a/confluent_client/bin/nodepower +++ b/confluent_client/bin/nodepower @@ -34,6 +34,9 @@ import confluent.client as client argparser = optparse.OptionParser( usage="Usage: %prog [options] noderange " "([status|on|off|shutdown|boot|reset])") +argparser.add_option('-p', '--showprevious', dest='previous', + action='store_true', default=False, + help='Show previous power state') (options, args) = argparser.parse_args() try: noderange = args[0] @@ -54,5 +57,19 @@ if setstate not in (None, 'on', 'off', 'shutdown', 'boot', 'reset'): session = client.Command() exitcode = 0 session.add_precede_key('oldstate') -sys.exit( - session.simple_noderange_command(noderange, '/power/state', setstate)) \ No newline at end of file + +if options.previous: + # get previous states + prev = {} + for rsp in session.read("/noderange/{0}/power/state".format(noderange)): + # gets previous (current) states + + databynode = rsp["databynode"] + + for node in databynode: + prev[node] = databynode[node]["state"]["value"] + + # add dictionary to session + session.add_precede_dict(prev) + +sys.exit(session.simple_noderange_command(noderange, '/power/state', setstate)) \ No newline at end of file diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index aa4b2224..abf7c577 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -88,6 +88,9 @@ class Command(object): def add_precede_key(self, keyname): self._prevkeyname = keyname + def add_precede_dict(self, dict): + self._prevdict = dict + def handle_results(self, ikey, rc, res, errnodes=None): if 'error' in res: if errnodes is not None: @@ -120,6 +123,9 @@ class Command(object): if self._prevkeyname and self._prevkeyname in res[node]: cprint('{0}: {2}->{1}'.format( node, val, res[node][self._prevkeyname]['value'])) + elif self._prevdict and node in self._prevdict: + cprint('{0}: {2}->{1}'.format( + node, val, self._prevdict[node])) else: cprint('{0}: {1}'.format(node, val)) return rc