Manage existing BMs: Part-2

Add the adopt baremetal node API.

Change-Id: I1897129930bface6a6c4a179e02d6107ff3811af
Implements: bp manage-existing-bms
This commit is contained in:
Tao Li
2017-07-07 16:56:38 +08:00
parent 93da16d88f
commit 26508fd131
16 changed files with 725 additions and 49 deletions

View File

@@ -146,6 +146,30 @@ class BaseEngineDriver(object):
"""
raise NotImplementedError()
def get_manageable_node(self, node_uuid):
"""Get the manageable node information by uuid
:param node_uuid: The manageable node uuid.
:return: A dict of manageable node information.
"""
raise NotImplementedError()
def manage(self, server, node_uuid):
"""Manage an existing bare metal node.
:param server: The bare metal server object.
:param node_uuid: The manageable bare metal node uuid.
"""
raise NotImplementedError()
def unmanage(self, server, node_uuid):
"""Unmanage a bare metal node.
:param server: The bare metal server object.
:param node_uuid: The manageable bare metal node uuid.
"""
raise NotImplementedError()
def load_engine_driver(engine_driver):
"""Load a engine driver module.

View File

@@ -754,3 +754,80 @@ class IronicDriver(base_driver.BaseEngineDriver):
'portgroups': node.get('portgroups'),
'image_source': node.get('image_source')})
return manageable_nodes
def get_manageable_node(self, node_uuid):
try:
node = self.ironicclient.call('node.get', node_uuid)
except ironic_exc.NotFound:
raise exception.NodeNotFound(node=node_uuid)
if (node.instance_uuid is not None or
node.provision_state != ironic_states.ACTIVE or
node.resource_class is None):
LOG.error("The node's instance uuid is %(instance_uuid)s, "
"node's provision state is %(provision_state)s, "
"node's resource class is %(resource_class)s",
{"instance_uuid": node.instance_uuid,
"provision_state": node.provision_state,
"resource_class": node.resource_class})
raise exception.NodeNotAllowedManaged(node_uuid=node_uuid)
# Retrieves ports
params = {
'limit': 0,
'fields': ('uuid', 'node_uuid', 'extra', 'address',
'internal_info')
}
port_list = self.ironicclient.call("port.list", **params)
portgroup_list = self.ironicclient.call("portgroup.list", **params)
# Add ports to the associated node
node.ports = [self._port_or_group_resource(port)
for port in port_list
if node.uuid == port.node_uuid]
# Add portgroups to the associated node
node.portgroups = [self._port_or_group_resource(portgroup)
for portgroup in portgroup_list
if node.uuid == portgroup.node_uuid]
node.power_state = map_power_state(node.power_state)
manageable_node = self._node_resource(node)
manageable_node['uuid'] = node_uuid
return manageable_node
def manage(self, server, node_uuid):
"""Manage an existing bare metal node.
:param server: The bare metal server object.
:param node_uuid: The manageable bare metal node uuid.
"""
# Associate the node with a server
patch = [{'path': '/instance_uuid', 'op': 'add', 'value': server.uuid}]
try:
self.ironicclient.call('node.update', node_uuid, patch,
retry_on_conflict=False)
except ironic_exc.BadRequest:
msg = (_("Failed to update parameters on node %(node)s "
"when provisioning the server %(server)s")
% {'node': node_uuid, 'server': server.uuid})
LOG.error(msg)
raise exception.ServerDeployFailure(msg)
def unmanage(self, server, node_uuid):
"""unmanage a bare metal node.
:param server: The bare metal server object.
:param node_uuid: The manageable bare metal node uuid.
"""
patch = [{'path': '/instance_uuid', 'op': 'remove'}]
try:
self.ironicclient.call('node.update', node_uuid, patch)
except ironic_exc.BadRequest as e:
LOG.warning("Failed to remove deploy parameters from node "
"%(node)s when unprovisioning the server "
"%(server)s: %(reason)s",
{'node': node_uuid, 'server': server.uuid,
'reason': six.text_type(e)})