diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-08-02 15:34:00 -0400 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-08-06 15:09:33 -0400 |
| commit | 2ee42aafde64af6d64a1f34a6204fd80e7dd01fd (patch) | |
| tree | fac26bea8720c878cd8b899002cf16249f3db3a6 /nova/compute | |
| parent | 6b42978eb4bf740f148a6bb200b331660755b53b (diff) | |
Reduce db access in prep_resize in the compute manager.
This patch changes the arguments passed to prep_resize in the compute
manager. Previously it took instance and instance_type IDs. It now
receives a full dict for both of these. This cuts down on database
access needed on the compute node.
This method was not previously in the compute rpcapi module, so it has
been added there. The scheduler had a bit of work done ot get it to use
the rpcapi module for prep_resize, as well.
Part of blueprint no-db-messaging.
Change-Id: Idadbf4fc624d5d1b128f758a46c61b3c840b9898
Diffstat (limited to 'nova/compute')
| -rw-r--r-- | nova/compute/manager.py | 44 | ||||
| -rw-r--r-- | nova/compute/rpcapi.py | 12 |
2 files changed, 37 insertions, 19 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 22f30d66b..a8d325b4b 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -273,7 +273,7 @@ def _get_image_meta(context, image_ref): class ComputeManager(manager.SchedulerDependentManager): """Manages the running instances from creation to destruction.""" - RPC_API_VERSION = '1.37' + RPC_API_VERSION = '1.38' def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -1481,7 +1481,8 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def prep_resize(self, context, instance_uuid, instance_type_id, image): + def prep_resize(self, context, image, instance=None, instance_uuid=None, + instance_type=None, instance_type_id=None): """Initiates the process of moving a running instance to another host. Possibly changes the RAM and disk size in the process. @@ -1489,44 +1490,49 @@ class ComputeManager(manager.SchedulerDependentManager): """ context = context.elevated() - instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) - with self.error_out_instance_on_exception(context, instance_uuid): + if not instance: + instance = self.db.instance_get_by_uuid(context, instance_uuid) + + if not instance_type: + instance_type = instance_types.get_instance_type(instance_type_id) + + with self.error_out_instance_on_exception(context, instance['uuid']): compute_utils.notify_usage_exists( - context, instance_ref, current_period=True) + context, instance, current_period=True) self._notify_about_instance_usage( - context, instance_ref, "resize.prep.start") + context, instance, "resize.prep.start") - same_host = instance_ref['host'] == FLAGS.host + same_host = instance['host'] == FLAGS.host if same_host and not FLAGS.allow_resize_to_same_host: - self._set_instance_error_state(context, instance_uuid) + self._set_instance_error_state(context, instance['uuid']) msg = _('destination same as source!') raise exception.MigrationError(msg) - old_instance_type_id = instance_ref['instance_type_id'] + # TODO(russellb): no-db-compute: Send the old instance type info + # that is needed via rpc so db access isn't required here. + old_instance_type_id = instance['instance_type_id'] old_instance_type = instance_types.get_instance_type( old_instance_type_id) - new_instance_type = instance_types.get_instance_type( - instance_type_id) migration_ref = self.db.migration_create(context, - {'instance_uuid': instance_ref['uuid'], - 'source_compute': instance_ref['host'], + {'instance_uuid': instance['uuid'], + 'source_compute': instance['host'], 'dest_compute': FLAGS.host, 'dest_host': self.driver.get_host_ip_addr(), 'old_instance_type_id': old_instance_type['id'], - 'new_instance_type_id': instance_type_id, + 'new_instance_type_id': instance_type['id'], 'status': 'pre-migrating'}) - LOG.audit(_('Migrating'), context=context, instance=instance_ref) - self.compute_rpcapi.resize_instance(context, instance_ref, + LOG.audit(_('Migrating'), context=context, instance=instance) + self.compute_rpcapi.resize_instance(context, instance, migration_ref['id'], image) extra_usage_info = dict( - new_instance_type=new_instance_type['name'], - new_instance_type_id=new_instance_type['id']) + new_instance_type=instance_type['name'], + new_instance_type_id=instance_type['id']) self._notify_about_instance_usage( - context, instance_ref, "resize.prep.end", + context, instance, "resize.prep.end", extra_usage_info=extra_usage_info) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index aa3d32e34..517cfca4d 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -113,6 +113,10 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): change_instance_metadata() 1.37 - Remove instance_uuid, add instance argument to terminate_instance() + 1.38 - Changes to prep_resize(): + - remove instance_uuid, add instance + - remove instance_type_id, add instance_type + - remove topic, it was unused ''' BASE_RPC_API_VERSION = '1.0' @@ -308,6 +312,14 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): disk=disk), _compute_topic(self.topic, ctxt, host, None), version='1.23') + def prep_resize(self, ctxt, image, instance, instance_type, host): + instance_p = jsonutils.to_primitive(instance) + instance_type_p = jsonutils.to_primitive(instance_type) + self.cast(ctxt, self.make_msg('prep_resize', + instance=instance_p, instance_type=instance_type_p, + image=image), _compute_topic(self.topic, ctxt, host, None), + version='1.38') + def reboot_instance(self, ctxt, instance, reboot_type): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('reboot_instance', |
