Merge "Move all rpc call to engine api"
This commit is contained in:
commit
80983ab56b
@ -32,7 +32,6 @@ def setup_app(pecan_config=None, extra_hooks=None):
|
||||
app_hooks = [hooks.ConfigHook(),
|
||||
hooks.DBHook(),
|
||||
hooks.ContextHook(pecan_config.app.acl_public_routes),
|
||||
hooks.RPCHook(),
|
||||
hooks.NoExceptionTracebackHook(),
|
||||
hooks.PublicUrlHook()]
|
||||
if extra_hooks:
|
||||
|
@ -32,8 +32,6 @@ from nimble.common.i18n import _
|
||||
from nimble.common.i18n import _LW
|
||||
from nimble.common import policy
|
||||
from nimble.engine import api as engineapi
|
||||
from nimble.engine.baremetal.ironic import get_node_by_instance
|
||||
from nimble.engine.baremetal.ironic import get_node_list
|
||||
from nimble.engine.baremetal import ironic_states as ir_states
|
||||
from nimble import objects
|
||||
|
||||
@ -123,8 +121,8 @@ class InstanceStatesController(rest.RestController):
|
||||
"""
|
||||
rpc_instance = self._resource or self._get_resource(instance_uuid)
|
||||
|
||||
rpc_states = pecan.request.rpcapi.instance_states(
|
||||
pecan.request.context, rpc_instance)
|
||||
rpc_states = self.engine_api.states(pecan.request.context,
|
||||
rpc_instance)
|
||||
return InstanceStates(**rpc_states)
|
||||
|
||||
@policy.authorize_wsgi("nimble:instance", "set_power_state")
|
||||
@ -149,8 +147,7 @@ class InstanceStatesController(rest.RestController):
|
||||
raise exception.InvalidActionParameterValue(
|
||||
value=target, action="power",
|
||||
instance=instance_uuid)
|
||||
pecan.request.rpcapi.set_power_state(pecan.request.context,
|
||||
rpc_instance, target)
|
||||
self.engine_api.power(pecan.request.context, rpc_instance, target)
|
||||
# At present we do not catch the Exception from ironicclient.
|
||||
# Such as Conflict and BadRequest.
|
||||
# varify provision_state, if instance is being cleaned,
|
||||
@ -285,10 +282,9 @@ class InstanceController(rest.RestController):
|
||||
|
||||
if fields is None or 'power_state' in fields:
|
||||
try:
|
||||
node_list = get_node_list(
|
||||
associated=True, limit=0,
|
||||
fields=_NODE_FIELDS)
|
||||
|
||||
nodes = self.engine_api.get_ironic_node_list(
|
||||
pecan.request.context, fields=_NODE_FIELDS)
|
||||
node_list = nodes['nodes']
|
||||
except Exception as e:
|
||||
LOG.warning(
|
||||
_LW("Failed to retrieve node list from"
|
||||
@ -296,8 +292,7 @@ class InstanceController(rest.RestController):
|
||||
node_list = []
|
||||
|
||||
if node_list:
|
||||
node_dict = {node.instance_uuid: node.to_dict()
|
||||
for node in node_list}
|
||||
node_dict = {node['instance_uuid']: node for node in node_list}
|
||||
# Merge nimble instance info with ironic node power state
|
||||
for instance_data in instances_data:
|
||||
uuid = instance_data['uuid']
|
||||
@ -339,8 +334,10 @@ class InstanceController(rest.RestController):
|
||||
# Only fetch node info if fields parameter is not specified
|
||||
# or node fields is not requested.
|
||||
try:
|
||||
node = get_node_by_instance(instance_uuid, _NODE_FIELDS)
|
||||
instance_data['power_state'] = node.power_state
|
||||
node = self.engine_api.get_ironic_node(pecan.request.context,
|
||||
instance_uuid,
|
||||
_NODE_FIELDS)
|
||||
instance_data['power_state'] = node['power_state']
|
||||
except Exception as e:
|
||||
LOG.warning(
|
||||
_LW("Failed to retrieve node by instance_uuid"
|
||||
@ -404,8 +401,7 @@ class InstanceController(rest.RestController):
|
||||
:param instance_uuid: UUID of a instance.
|
||||
"""
|
||||
rpc_instance = self._resource or self._get_resource(instance_uuid)
|
||||
pecan.request.rpcapi.delete_instance(pecan.request.context,
|
||||
rpc_instance)
|
||||
self.engine_api.delete(pecan.request.context, rpc_instance)
|
||||
|
||||
|
||||
def _check_create_body(body):
|
||||
|
@ -21,7 +21,6 @@ from six.moves import http_client
|
||||
from nimble.common import context
|
||||
from nimble.common import policy
|
||||
from nimble.db import api as dbapi
|
||||
from nimble.engine import rpcapi
|
||||
|
||||
|
||||
class ConfigHook(hooks.PecanHook):
|
||||
@ -92,13 +91,6 @@ class ContextHook(hooks.PecanHook):
|
||||
state.response.headers['Openstack-Request-Id'] = request_id
|
||||
|
||||
|
||||
class RPCHook(hooks.PecanHook):
|
||||
"""Attach the rpcapi object to the request so controllers can get to it."""
|
||||
|
||||
def before(self, state):
|
||||
state.request.rpcapi = rpcapi.EngineAPI()
|
||||
|
||||
|
||||
class NoExceptionTracebackHook(hooks.PecanHook):
|
||||
"""Workaround rpc.common: deserialize_remote_exception.
|
||||
|
||||
|
@ -15,10 +15,14 @@
|
||||
|
||||
"""Handles all requests relating to compute resources"""
|
||||
|
||||
from oslo_log import log
|
||||
|
||||
from nimble.engine import rpcapi
|
||||
from nimble.engine import status
|
||||
from nimble import objects
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class API(object):
|
||||
"""API for interacting with the engine manager."""
|
||||
@ -96,3 +100,25 @@ class API(object):
|
||||
image_uuid, name, description,
|
||||
availability_zone, extra,
|
||||
requested_networks)
|
||||
|
||||
def _delete_instance(self, context, instance):
|
||||
self.engine_rpcapi.delete_instance(context, instance)
|
||||
|
||||
def delete(self, context, instance):
|
||||
"""Delete an instance."""
|
||||
LOG.debug("Going to try to delete instance %s", instance.uuid)
|
||||
self._delete_instance(context, instance)
|
||||
|
||||
def states(self, context, instance):
|
||||
return self.engine_rpcapi.instance_states(context, instance)
|
||||
|
||||
def power(self, context, instance, target):
|
||||
self.engine_rpcapi.set_power_state(context, instance, target)
|
||||
|
||||
def get_ironic_node(self, context, instance_uuid, fields):
|
||||
return self.engine_rpcapi.get_ironic_node(context,
|
||||
instance_uuid,
|
||||
fields)
|
||||
|
||||
def get_ironic_node_list(self, context, fields):
|
||||
return self.engine_rpcapi.get_ironic_node_list(context, fields)
|
||||
|
@ -243,3 +243,13 @@ class EngineManager(base_manager.BaseEngineManager):
|
||||
LOG.debug("set power state...")
|
||||
|
||||
return self._set_power_state(context, instance, state)
|
||||
|
||||
def get_ironic_node(self, context, instance_uuid, fields):
|
||||
node = ironic.get_node_by_instance(self.ironicclient,
|
||||
instance_uuid, fields)
|
||||
return node.to_dict()
|
||||
|
||||
def get_ironic_node_list(self, context, fields):
|
||||
nodes = ironic.get_node_list(self.ironicclient, associated=True,
|
||||
limit=0, fields=fields)
|
||||
return {'nodes': [node.to_dict() for node in nodes]}
|
||||
|
@ -73,3 +73,16 @@ class EngineAPI(object):
|
||||
# need return?
|
||||
return cctxt.call(context, 'set_power_state',
|
||||
instance=instance, state=state)
|
||||
|
||||
def get_ironic_node(self, context, instance_uuid, fields):
|
||||
"""Signal to engine service to get a ironic node."""
|
||||
cctxt = self.client.prepare(topic=self.topic, server=CONF.host)
|
||||
return cctxt.call(context, 'get_ironic_node',
|
||||
instance_uuid=instance_uuid,
|
||||
fields=fields)
|
||||
|
||||
def get_ironic_node_list(self, context, fields):
|
||||
"""Signal to engine service to get ironic node list."""
|
||||
cctxt = self.client.prepare(topic=self.topic, server=CONF.host)
|
||||
return cctxt.call(context, 'get_ironic_node_list',
|
||||
fields=fields)
|
||||
|
Loading…
Reference in New Issue
Block a user