From caba650143c36ca88cb3e580c6c4effda5f7faa8 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 11 May 2022 14:59:54 -0400 Subject: [PATCH] Add nodepower arguments for PDU operations --- confluent_client/bin/nodepower | 16 ++++++++++------ confluent_client/confluent/client.py | 3 +++ confluent_client/doc/man/nodepower.ronn | 3 +++ .../plugins/hardwaremanagement/geist.py | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/confluent_client/bin/nodepower b/confluent_client/bin/nodepower index b21314b3..59d55b13 100755 --- a/confluent_client/bin/nodepower +++ b/confluent_client/bin/nodepower @@ -33,7 +33,7 @@ import confluent.client as client argparser = optparse.OptionParser( usage="Usage: %prog [options] " - "([status|on|off|shutdown|boot|reset])") + "([status|on|off|shutdown|boot|reset|pdu_status|pdu_off|pdu_on])") argparser.add_option('-p', '--showprevious', dest='previous', action='store_true', default=False, help='Show previous power state') @@ -53,20 +53,24 @@ setstate = None if len(args) > 1: if setstate == 'softoff': setstate = 'shutdown' - elif not args[1] in ('stat', 'state', 'status'): - setstate = args[1] -if setstate not in (None, 'on', 'off', 'shutdown', 'boot', 'reset'): +if setstate not in (None, 'on', 'off', 'shutdown', 'boot', 'reset', 'pdu_status', 'pdu_stat', 'pdu_on', 'pdu_off'): argparser.print_help() sys.exit(1) session = client.Command() exitcode = 0 session.add_precede_key('oldstate') +powurl = 'state' +if setstate and setstate.startswith('pdu_'): + setstate = setstate.replace('pdu_', '') + powurl = 'inlets/all' +if setstate in ('status', 'state', 'stat'): + setstate = None if options.previous: # get previous states prev = {} - for rsp in session.read("/noderange/{0}/power/state".format(noderange)): + for rsp in session.read("/noderange/{0}/power/{1}".format(noderange, powurl)): # gets previous (current) states databynode = rsp["databynode"] @@ -77,4 +81,4 @@ if options.previous: # add dictionary to session session.add_precede_dict(prev) -sys.exit(session.simple_noderange_command(noderange, '/power/state', setstate, promptover=options.maxnodes)) +sys.exit(session.simple_noderange_command(noderange, '/power/{0}'.format(powurl), setstate, promptover=options.maxnodes, key='state')) diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index bee16f00..47eaa494 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -245,6 +245,9 @@ class Command(object): node, val, self._prevdict[node])) else: cprint('{0}: {1}'.format(node, val)) + elif ikey == 'state': + for k in res[node]: + cprint('{0}: {1}: {2}'.format(node, k, res[node][k])) return rc def simple_noderange_command(self, noderange, resource, input=None, diff --git a/confluent_client/doc/man/nodepower.ronn b/confluent_client/doc/man/nodepower.ronn index e2d90dd1..bdf303f3 100644 --- a/confluent_client/doc/man/nodepower.ronn +++ b/confluent_client/doc/man/nodepower.ronn @@ -24,6 +24,9 @@ respond. * `reset`: Request immediate reset of nodes of the noderange. Nodes that are off will not react to this request. * `status`: Behave identically to having no argument passed at all. +* `pdu_status`: Query state of associated PDU outlets, if configured. +* `pdu_on`: Energize all PDU outlets associated with the noderange. +* `pdu_off`: De-energize all PDU outlets associated with the noderange. ## OPTIONS diff --git a/confluent_server/confluent/plugins/hardwaremanagement/geist.py b/confluent_server/confluent/plugins/hardwaremanagement/geist.py index 979550f5..0181b39d 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/geist.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/geist.py @@ -85,7 +85,7 @@ class GeistClient(object): raise Exception('Multiple PDUs not supported per pdu') pduname = list(rsp)[0] outlet = rsp[pduname]['outlet'][str(int(outlet) - 1)] - state = outlet['state'] + state = outlet['state'].split('2')[-1] return state def set_outlet(self, outlet, state):