diff --git a/confluent_client/bin/nodepower b/confluent_client/bin/nodepower index 6711aea0..5dd0b007 100755 --- a/confluent_client/bin/nodepower +++ b/confluent_client/bin/nodepower @@ -45,5 +45,6 @@ if len(sys.argv) > 2: 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 diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index 38ff2bbf..aa30e6a1 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -44,6 +44,7 @@ def _parseserver(string): class Command(object): def __init__(self, server=None): + self._prevkeyname = None self.connection = None if server is None: if 'CONFLUENT_HOST' in os.environ: @@ -74,6 +75,9 @@ class Command(object): if authdata['authpassed'] == 1: self.authenticated = True + def add_precede_key(self, keyname): + self._prevkeyname = keyname + def handle_results(self, ikey, rc, res): if 'error' in res: sys.stderr.write('Error: {0}\n'.format(res['error'])) @@ -93,7 +97,12 @@ class Command(object): else: rc |= 1 elif ikey in res[node]: - print('{0}: {1}'.format(node, res[node][ikey]['value'])) + if self._prevkeyname and self._prevkeyname in res[node]: + print('{0}: {2}->{1}'.format( + node, res[node][ikey]['value'], + res[node][self._prevkeyname]['value'])) + else: + print('{0}: {1}'.format(node, res[node][ikey]['value'])) return rc def simple_noderange_command(self, noderange, resource, input=None, diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 4f43abe1..fc4a7df2 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -797,6 +797,11 @@ class PowerState(ConfluentChoiceMessage): ]) keyname = 'state' + def __init__(self, node, state, oldstate=None): + super(PowerState, self).__init__(node, state) + if oldstate is not None: + self.kvpairs[node]['oldstate'] = {'value': oldstate} + class BMCReset(ConfluentChoiceMessage): valid_values = set([ diff --git a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py index d929b2df..ce92b869 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py @@ -795,10 +795,22 @@ class IpmiHandler(object): return elif 'update' == self.op: powerstate = self.inputdata.powerstate(self.node) + oldpower = None + if powerstate == 'boot': + oldpower = self.ipmicmd.get_power() + if 'powerstate' in oldpower: + oldpower = oldpower['powerstate'] self.ipmicmd.set_power(powerstate, wait=30) - power = self.ipmicmd.get_power() + if powerstate == 'boot' and oldpower == 'on': + power = {'powerstate': 'reset'} + else: + power = self.ipmicmd.get_power() + if powerstate == 'reset' and power['powerstate'] == 'on': + power['powerstate'] = 'reset' + self.output.put(msg.PowerState(node=self.node, - state=power['powerstate'])) + state=power['powerstate'], + oldstate=oldpower)) return def handle_reset(self):