@zwei
2016-04-22T09:43:34.000000Z
字数 1850
阅读 2159
nova
在nova 的liberty 版本中 修改 admin password 的方法和线上产品修改passowd 的方法
def set_admin_password(self, context, instance, new_pass):"""Set the root/admin password for an instance on this host.This is generally only called by API password resets after animage has been built.@param context: Nova auth context.@param instance: Nova instance object.@param new_pass: The admin password for the instance."""import pdb;pdb.set_trace()context = context.elevated()if new_pass is None:# Generate a random passwordnew_pass = utils.generate_password()current_power_state = self._get_power_state(context, instance)expected_state = power_state.RUNNINGif current_power_state != expected_state:instance.task_state = Noneinstance.save(expected_task_state=task_states.UPDATING_PASSWORD)_msg = _('instance %s is not running') % instance.uuidraise exception.InstancePasswordSetFailed(instance=instance.uuid, reason=_msg)try:self.driver.set_admin_password(instance, new_pass)LOG.info(_LI("Root password set"), instance=instance)instance.task_state = Noneinstance.save(expected_task_state=task_states.UPDATING_PASSWORD)except NotImplementedError:LOG.warning(_LW('set_admin_password is not implemented ''by this driver or guest instance.'),instance=instance)instance.task_state = Noneinstance.save(expected_task_state=task_states.UPDATING_PASSWORD)raise NotImplementedError(_('set_admin_password is not ''implemented by this driver or guest ''instance.'))except exception.UnexpectedTaskStateError:# interrupted by another (most likely delete) task# do not retryraiseexcept Exception:# Catch all here because this could be anything.LOG.exception(_LE('set_admin_password failed'),instance=instance)self._set_instance_obj_error_state(context, instance)# 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_msg = _('error setting admin password')raise exception.InstancePasswordSetFailed(instance=instance.uuid, reason=_msg)