From bc1947d2e9c21c19735a9470a498234b94b8d9c4 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Thu, 26 Jul 2012 17:57:45 -0400 Subject: Send a full instance in power_on_instance and start_instance. Change the power_on_instance and start_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: I5a95e72c6441f47f014dbcd52f346e8d2e94069c --- 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 b2744e03d..ef1bdbcc6 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.21' + RPC_API_VERSION = '1.22' def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -951,11 +951,12 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def start_instance(self, context, instance_uuid): + def start_instance(self, context, instance=None, instance_uuid=None): """Starting an instance on this host. Alias for power_on_instance for compatibility""" - self.power_on_instance(context, instance_uuid) + self.power_on_instance(context, instance=instance, + instance_uuid=instance_uuid) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @@ -978,9 +979,10 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def power_on_instance(self, context, instance_uuid): + def power_on_instance(self, context, instance=None, instance_uuid=None): """Power on 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_on.start") self.driver.power_on(instance) current_power_state = self._get_power_state(context, instance) diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index 2c84e3a10..a99c8f492 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -86,6 +86,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): post_live_migration_at_destination() 1.21 - Remove instance_uuid, add instance argument to power_off_instance() and stop_instance() + 1.22 - Remove instance_uuid, add instance argument to + power_on_instance() and start_instance() ''' BASE_RPC_API_VERSION = '1.0' @@ -260,9 +262,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): version='1.21') def power_on_instance(self, ctxt, instance): + instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('power_on_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.22') def pre_live_migration(self, ctxt, instance, block_migration, disk, host): @@ -379,9 +383,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): topic=_compute_topic(self.topic, ctxt, None, instance)) def start_instance(self, ctxt, instance): + instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('start_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.22') def stop_instance(self, ctxt, instance, cast=True): rpc_method = self.cast if cast else self.call -- cgit