2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 09:32:21 +00:00

Clean up nodepower

nodepower boot and reset output was misleading.
This commit is contained in:
Jarrod Johnson 2017-02-02 17:00:09 -05:00
parent ecc6bcf96c
commit 9e593f0554
4 changed files with 30 additions and 3 deletions

View File

@ -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))

View File

@ -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,

View File

@ -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([

View File

@ -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):