From 3a03a9c46ad20b1c0f44497e9e23b9ef7be465e7 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Thu, 26 Jul 2012 17:37:34 -0400 Subject: Send a full instance in power_off_instance and stop_instance. Change the power_off_instance and stop_instance methods of the compute rpc API to take a full instance over rpc instead of just the instance UUID. This cuts down on database access needed by nova-compute. Part of blueprint no-db-messaging. Change-Id: I641d5e7941c7de430c0ca3c9b961f967d947d963 --- nova/compute/manager.py | 12 +++++++----- nova/compute/rpcapi.py | 14 ++++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/manager.py b/nova/compute/manager.py index d25405ce3..b2744e03d 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -295,7 +295,7 @@ def _get_additional_capabilities(): class ComputeManager(manager.SchedulerDependentManager): """Manages the running instances from creation to destruction.""" - RPC_API_VERSION = '1.20' + RPC_API_VERSION = '1.21' def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -940,11 +940,12 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def stop_instance(self, context, instance_uuid): + def stop_instance(self, context, instance=None, instance_uuid=None): """Stopping an instance on this host. Alias for power_off_instance for compatibility""" - self.power_off_instance(context, instance_uuid, + self.power_off_instance(context, instance=instance, + instance_uuid=instance_uuid, final_state=vm_states.STOPPED) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @@ -959,10 +960,11 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def power_off_instance(self, context, instance_uuid, + def power_off_instance(self, context, instance=None, instance_uuid=None, final_state=vm_states.SOFT_DELETED): """Power off an instance on this host.""" - instance = self.db.instance_get_by_uuid(context, instance_uuid) + if not instance: + instance = self.db.instance_get_by_uuid(context, instance_uuid) self._notify_about_instance_usage(context, instance, "power_off.start") self.driver.power_off(instance) current_power_state = self._get_power_state(context, instance) diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index 7243e37c5..2c84e3a10 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -84,6 +84,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): inject_network_info() 1.20 - Remove instance_id, add instance argument to post_live_migration_at_destination() + 1.21 - Remove instance_uuid, add instance argument to + power_off_instance() and stop_instance() ''' BASE_RPC_API_VERSION = '1.0' @@ -251,9 +253,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): version='1.20') def power_off_instance(self, ctxt, instance): + instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('power_off_instance', - instance_uuid=instance['uuid']), - topic=_compute_topic(self.topic, ctxt, None, instance)) + instance=instance_p), + topic=_compute_topic(self.topic, ctxt, None, instance), + version='1.21') def power_on_instance(self, ctxt, instance): self.cast(ctxt, self.make_msg('power_on_instance', @@ -381,9 +385,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): def stop_instance(self, ctxt, instance, cast=True): rpc_method = self.cast if cast else self.call + instance_p = jsonutils.to_primitive(instance) return rpc_method(ctxt, self.make_msg('stop_instance', - instance_uuid=instance['uuid']), - topic=_compute_topic(self.topic, ctxt, None, instance)) + instance=instance), + topic=_compute_topic(self.topic, ctxt, None, instance), + version='1.21') def suspend_instance(self, ctxt, instance): instance_p = jsonutils.to_primitive(instance) -- cgit