Use a dict to translate node power states to json data.
The input of set_power_state() is different from the real string it sends to Ironic service in json data. The power states were translated in set_power_state(). Using a dict to map the translation is more clear, and easier to add new power states. Change-Id: I8c7dac1ac39f92b2031e7f1fa95cd5c398a708d5 Implements: blueprint enhance-power-interface-for-soft-reboot-and-nmi Related-to: blueprint soft-reboot-poweroff Related-to: blueprint instance-crash-dump
This commit is contained in:
parent
65f2b18c33
commit
5d0de8f392
@ -25,6 +25,13 @@ CREATION_ATTRIBUTES = ['chassis_uuid', 'driver', 'driver_info', 'extra',
|
||||
'uuid', 'properties', 'name']
|
||||
|
||||
|
||||
_power_states = {
|
||||
'on': 'power on',
|
||||
'off': 'power off',
|
||||
'reboot': 'rebooting',
|
||||
}
|
||||
|
||||
|
||||
class Node(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<Node %s>" % self._info
|
||||
@ -264,11 +271,7 @@ class NodeManager(base.Manager):
|
||||
|
||||
def set_power_state(self, node_id, state):
|
||||
path = "%s/states/power" % node_id
|
||||
if state in ['on', 'off']:
|
||||
state = "power %s" % state
|
||||
if state in ['reboot']:
|
||||
state = "rebooting"
|
||||
target = {'target': state}
|
||||
target = {'target': _power_states.get(state, state)}
|
||||
return self._update(self._path(path), target, method='PUT')
|
||||
|
||||
def validate(self, node_uuid):
|
||||
|
Loading…
x
Reference in New Issue
Block a user