diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-07-20 14:08:10 -0400 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-07-25 19:53:20 -0400 |
| commit | 94018d1f753d62ba75f3262f2c2fcdb1ee7f731b (patch) | |
| tree | a2fe7a9136168ecd1192bd5d5e116655ceaebe7d /nova/compute | |
| parent | f5289971b7da19111ca6a68bb46c1108ea46664b (diff) | |
Send a full instance via rpc for (un)pause_instance.
Change the pause_instance and unpause_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: Ia7e31428c7d2edb9a0c4d0958f1c7774742ea1cd
Diffstat (limited to 'nova/compute')
| -rw-r--r-- | nova/compute/manager.py | 28 | ||||
| -rw-r--r-- | nova/compute/rpcapi.py | 14 |
2 files changed, 25 insertions, 17 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index cced8509b..9ebfe496b 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -297,7 +297,7 @@ def _get_additional_capabilities(): class ComputeManager(manager.SchedulerDependentManager): """Manages the running instances from creation to destruction.""" - RPC_API_VERSION = '1.4' + RPC_API_VERSION = '1.5' def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -1713,17 +1713,18 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def pause_instance(self, context, instance_uuid): + def pause_instance(self, context, instance=None, instance_uuid=None): """Pause an instance on this host.""" context = context.elevated() - instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) + if not instance: + instance = self.db.instance_get_by_uuid(context, instance_uuid) - LOG.audit(_('Pausing'), context=context, instance=instance_ref) - self.driver.pause(instance_ref) + LOG.audit(_('Pausing'), context=context, instance=instance) + self.driver.pause(instance) - current_power_state = self._get_power_state(context, instance_ref) + current_power_state = self._get_power_state(context, instance) self._instance_update(context, - instance_ref['uuid'], + instance['uuid'], power_state=current_power_state, vm_state=vm_states.PAUSED, task_state=None) @@ -1731,17 +1732,18 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def unpause_instance(self, context, instance_uuid): + def unpause_instance(self, context, instance=None, instance_uuid=None): """Unpause a paused instance on this host.""" context = context.elevated() - instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) + if not instance: + instance = self.db.instance_get_by_uuid(context, instance_uuid) - LOG.audit(_('Unpausing'), context=context, instance=instance_ref) - self.driver.unpause(instance_ref) + LOG.audit(_('Unpausing'), context=context, instance=instance) + self.driver.unpause(instance) - current_power_state = self._get_power_state(context, instance_ref) + current_power_state = self._get_power_state(context, instance) self._instance_update(context, - instance_ref['uuid'], + instance['uuid'], power_state=current_power_state, vm_state=vm_states.ACTIVE, task_state=None) diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index e480ee20d..d5de04452 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -60,6 +60,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): 1.2 - Adds check_can_live_migrate_[destination|source] 1.3 - Adds change_instance_metadata() 1.4 - Remove instance_uuid, add instance argument to reboot_instance() + 1.5 - Remove instance_uuid, add instance argument to pause_instance(), + unpause_instance() ''' BASE_RPC_API_VERSION = '1.0' @@ -211,9 +213,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): _compute_topic(self.topic, ctxt, host, None)) def pause_instance(self, ctxt, instance): + instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('pause_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.5') def power_off_instance(self, ctxt, instance): self.cast(ctxt, self.make_msg('power_off_instance', @@ -361,9 +365,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): topic=_compute_topic(self.topic, ctxt, None, instance)) def unpause_instance(self, ctxt, instance): + instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('unpause_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.5') def unrescue_instance(self, ctxt, instance): self.cast(ctxt, self.make_msg('unrescue_instance', |
