[关闭]
@zwei 2016-04-22T09:43:34.000000Z 字数 1850 阅读 1996

nova liberty 版本中 修改 admin passowd 的流程分析

nova


在nova 的liberty 版本中 修改 admin password 的方法和线上产品修改passowd 的方法

  1. def set_admin_password(self, context, instance, new_pass):
  2. """Set the root/admin password for an instance on this host.
  3. This is generally only called by API password resets after an
  4. image has been built.
  5. @param context: Nova auth context.
  6. @param instance: Nova instance object.
  7. @param new_pass: The admin password for the instance.
  8. """
  9. import pdb;pdb.set_trace()
  10. context = context.elevated()
  11. if new_pass is None:
  12. # Generate a random password
  13. new_pass = utils.generate_password()
  14. current_power_state = self._get_power_state(context, instance)
  15. expected_state = power_state.RUNNING
  16. if current_power_state != expected_state:
  17. instance.task_state = None
  18. instance.save(expected_task_state=task_states.UPDATING_PASSWORD)
  19. _msg = _('instance %s is not running') % instance.uuid
  20. raise exception.InstancePasswordSetFailed(
  21. instance=instance.uuid, reason=_msg)
  22. try:
  23. self.driver.set_admin_password(instance, new_pass)
  24. LOG.info(_LI("Root password set"), instance=instance)
  25. instance.task_state = None
  26. instance.save(
  27. expected_task_state=task_states.UPDATING_PASSWORD)
  28. except NotImplementedError:
  29. LOG.warning(_LW('set_admin_password is not implemented '
  30. 'by this driver or guest instance.'),
  31. instance=instance)
  32. instance.task_state = None
  33. instance.save(
  34. expected_task_state=task_states.UPDATING_PASSWORD)
  35. raise NotImplementedError(_('set_admin_password is not '
  36. 'implemented by this driver or guest '
  37. 'instance.'))
  38. except exception.UnexpectedTaskStateError:
  39. # interrupted by another (most likely delete) task
  40. # do not retry
  41. raise
  42. except Exception:
  43. # Catch all here because this could be anything.
  44. LOG.exception(_LE('set_admin_password failed'),
  45. instance=instance)
  46. self._set_instance_obj_error_state(context, instance)
  47. # We create a new exception here so that we won't
  48. # potentially reveal password information to the
  49. # API caller. The real exception is logged above
  50. _msg = _('error setting admin password')
  51. raise exception.InstancePasswordSetFailed(
  52. instance=instance.uuid, reason=_msg)
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注