From 99f6c32bf8a5204da0e07137486c61cdba5318a3 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Mon, 30 Jul 2012 15:39:18 -0400 Subject: Send a full instance in set_admin_password. Change the set_admin_password 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: Iddcc7cb068090faa98f0bb87307e09d5b0ebf0c2 --- nova/compute/manager.py | 30 ++++++++++++++++-------------- nova/compute/rpcapi.py | 8 ++++++-- 2 files changed, 22 insertions(+), 16 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 426577d5c..6d8a52d16 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -272,7 +272,7 @@ def _get_image_meta(context, image_ref): class ComputeManager(manager.SchedulerDependentManager): """Manages the running instances from creation to destruction.""" - RPC_API_VERSION = '1.32' + RPC_API_VERSION = '1.33' def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -1221,7 +1221,8 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault - def set_admin_password(self, context, instance_uuid, new_pass=None): + def set_admin_password(self, context, instance=None, instance_uuid=None, + new_pass=None): """Set the root/admin password for an instance on this host. This is generally only called by API password resets after an @@ -1234,43 +1235,44 @@ class ComputeManager(manager.SchedulerDependentManager): # Generate a random password new_pass = utils.generate_password(FLAGS.password_length) + if not instance: + instance = self.db.instance_get_by_uuid(context, instance_uuid) + max_tries = 10 for i in xrange(max_tries): - instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) - - current_power_state = self._get_power_state(context, instance_ref) + current_power_state = self._get_power_state(context, instance) expected_state = power_state.RUNNING if current_power_state != expected_state: - self._instance_update(context, instance_ref['uuid'], + self._instance_update(context, instance['uuid'], task_state=None) _msg = _('Failed to set admin password. Instance %s is not' - ' running') % instance_ref["uuid"] + ' running') % instance["uuid"] raise exception.Invalid(_msg) else: try: - self.driver.set_admin_password(instance_ref, new_pass) - LOG.audit(_("Root password set"), instance=instance_ref) + self.driver.set_admin_password(instance, new_pass) + LOG.audit(_("Root password set"), instance=instance) self._instance_update(context, - instance_ref['uuid'], + instance['uuid'], task_state=None) break except NotImplementedError: # NOTE(dprince): if the driver doesn't implement # set_admin_password we break to avoid a loop LOG.warn(_('set_admin_password is not implemented ' - 'by this driver.'), instance=instance_ref) + 'by this driver.'), instance=instance) self._instance_update(context, - instance_ref['uuid'], + instance['uuid'], task_state=None) break except Exception, e: # Catch all here because this could be anything. - LOG.exception(e, instance=instance_ref) + LOG.exception(e, instance=instance) if i == max_tries - 1: self._set_instance_error_state(context, - instance_ref['uuid']) + instance['uuid']) # We create a new exception here so that we won't # potentially reveal password information to the # API caller. The real exception is logged above diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index c3b7f068d..15d1db81a 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -104,6 +104,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): 1.31 - Remove instance_uuid, add instance argument to revert_resize() 1.32 - Remove instance_id, add instance argument to rollback_live_migration_at_destination() + 1.33 - Remove instance_uuid, add instance argument to + set_admin_password() ''' BASE_RPC_API_VERSION = '1.0' @@ -395,9 +397,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): version='1.32') def set_admin_password(self, ctxt, instance, new_pass): + instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('set_admin_password', - instance_uuid=instance['uuid'], new_pass=new_pass), - topic=_compute_topic(self.topic, ctxt, None, instance)) + instance=instance_p, new_pass=new_pass), + topic=_compute_topic(self.topic, ctxt, None, instance), + version='1.33') def set_host_enabled(self, ctxt, enabled, host): topic = _compute_topic(self.topic, ctxt, host, None) -- cgit