diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-07-25 14:19:40 -0400 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-07-25 20:10:39 -0400 |
| commit | 8dac75fa0b6bb16adfdca2198703031249722f3d (patch) | |
| tree | cfb3f28b9d9309b3462c1087e38c49da0e2c98b7 /nova | |
| parent | 5547d08b28a7edc3e162174670cca892ae15e290 (diff) | |
| download | nova-8dac75fa0b6bb16adfdca2198703031249722f3d.tar.gz nova-8dac75fa0b6bb16adfdca2198703031249722f3d.tar.xz nova-8dac75fa0b6bb16adfdca2198703031249722f3d.zip | |
Send a full instance via rpc for attach_volume.
Change the attach_volume method 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: I85ad29e84b5e97a3f918059b10e2309312756050
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/compute/manager.py | 22 | ||||
| -rw-r--r-- | nova/compute/rpcapi.py | 7 | ||||
| -rw-r--r-- | nova/tests/compute/test_rpcapi.py | 8 |
3 files changed, 22 insertions, 15 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 097905788..afe8cae51 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.8' + RPC_API_VERSION = '1.9' def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -1961,15 +1961,17 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def attach_volume(self, context, instance_uuid, volume_id, mountpoint): + def attach_volume(self, context, volume_id, mountpoint, instance_uuid=None, + instance=None): """Attach a volume to an instance.""" volume = self.volume_api.get(context, volume_id) 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(_('Attaching volume %(volume_id)s to %(mountpoint)s'), - locals(), context=context, instance=instance_ref) + locals(), context=context, instance=instance) try: - connector = self.driver.get_volume_connector(instance_ref) + connector = self.driver.get_volume_connector(instance) connection_info = self.volume_api.initialize_connection(context, volume, connector) @@ -1978,28 +1980,28 @@ class ComputeManager(manager.SchedulerDependentManager): msg = _("Failed to connect to volume %(volume_id)s " "while attaching at %(mountpoint)s") LOG.exception(msg % locals(), context=context, - instance=instance_ref) + instance=instance) self.volume_api.unreserve_volume(context, volume) try: self.driver.attach_volume(connection_info, - instance_ref['name'], + instance['name'], mountpoint) except Exception: # pylint: disable=W0702 with excutils.save_and_reraise_exception(): msg = _("Failed to attach volume %(volume_id)s " "at %(mountpoint)s") LOG.exception(msg % locals(), context=context, - instance=instance_ref) + instance=instance) self.volume_api.terminate_connection(context, volume, connector) self.volume_api.attach(context, volume, - instance_ref['uuid'], + instance['uuid'], mountpoint) values = { - 'instance_uuid': instance_ref['uuid'], + 'instance_uuid': instance['uuid'], 'connection_info': jsonutils.dumps(connection_info), 'device_name': mountpoint, 'delete_on_termination': False, diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index 726b520b5..b11b17144 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -67,6 +67,7 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): get_console_output() 1.8 - Remove instance_uuid, add instance argument to add_fixed_ip_to_instance() + 1.9 - Remove instance_uuid, add instance argument to attach_volume() ''' BASE_RPC_API_VERSION = '1.0' @@ -97,10 +98,12 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): version='1.8') def attach_volume(self, ctxt, instance, volume_id, mountpoint): + instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('attach_volume', - instance_uuid=instance['uuid'], volume_id=volume_id, + instance=instance_p, volume_id=volume_id, mountpoint=mountpoint), - topic=_compute_topic(self.topic, ctxt, None, instance)) + topic=_compute_topic(self.topic, ctxt, None, instance), + version='1.9') def check_can_live_migrate_destination(self, ctxt, instance, destination, block_migration, disk_over_commit): diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py index b5319d257..ee74f2c6b 100644 --- a/nova/tests/compute/test_rpcapi.py +++ b/nova/tests/compute/test_rpcapi.py @@ -49,8 +49,9 @@ class ComputeRpcAPITestCase(test.TestCase): ctxt = context.RequestContext('fake_user', 'fake_project') methods_with_instance = [ - 'add_fixed_ip_to_instance', 'get_console_output', 'pause_instance', - 'reboot_instance', 'suspend_instance', 'unpause_instance' + 'add_fixed_ip_to_instance', 'attach_volume', 'get_console_output', + 'pause_instance', 'reboot_instance', 'suspend_instance', + 'unpause_instance' ] if 'rpcapi_class' in kwargs: @@ -126,7 +127,8 @@ class ComputeRpcAPITestCase(test.TestCase): def test_attach_volume(self): self._test_compute_api('attach_volume', 'cast', - instance=self.fake_instance, volume_id='id', mountpoint='mp') + instance=self.fake_instance, volume_id='id', mountpoint='mp', + version='1.9') def test_check_can_live_migrate_destination(self): self._test_compute_api('check_can_live_migrate_destination', 'call', |
