nova liberty

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  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 an
image 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 password
new_pass = utils.generate_password()

current_power_state = self._get_power_state(context, instance)
expected_state = power_state.RUNNING

if current_power_state != expected_state:
instance.task_state = None
instance.save(expected_task_state=task_states.UPDATING_PASSWORD)
_msg = _('instance %s is not running') % instance.uuid
raise 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 = None
instance.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 = None
instance.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 retry
raise
except 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)

总结:
在openstack L 版本中 libvirt >= 1.2.16 就已经实现了 qemu set_admin_password 的功能
注意: vm 必须是running 状态。
线上的实现方法是: 利用 libvirt_qemu 模块进行命令修改。