1. 位于nova/compute/api.py
def start(self, context, instance):
首先保存当前虚拟机的任务状态,为正在开机,powering_on
instance.task_state = task_states.POWERING_ON
instance.save(expected_task_state=[None])
其次调用日志保存:
self._record_action_start(context, instance, instance_actions.START)
2. RPC调用:
start_instance(context, instance)
位于nova/compute/manager.py文件中:
def start_instance(self, context, instance):
"""Starting an instance on this host."""
#这个不知道是什么意思
self._notify_about_instance_usage(context, instance, "power_on.start")
#这个和前面的调用链是一致的,表示开始
compute_utils.notify_about_instance_action(context, instance,
self.host, action=fields.NotificationAction.POWER_ON,
phase=fields.NotificationPhase.START)
#这个是开启虚拟机的主要函数
self._power_on(context, instance)
#对虚拟机的状态进行更新
instance.power_state = self._get_power_state(context, instance)
instance.vm_state = vm_states.ACTIVE
instance.task_state = None
#这个还不知道是什么意思
# Delete an image(VM snapshot) for a shelved instance
snapshot_id = instance.system_metadata.get('shelved_image_id')
if snapshot_id:
self._delete_snapshot_of_shelved_instance(context, instance,
snapshot_id)
# Delete system_metadata for a shelved instance
compute_utils.remove_shelved_keys_from_system_metadata(instance)
#保存当前的状态
instance.save(expected_task_state=task_states.POWERING_ON)
#这个应该和上面的功能类似,现在还不知道是什么作用
self._notify_about_instance_usage(context, instance, "power_on.end")
#这个是调用链的结束,走到这里就代表开机已经成功了
compute_utils.notify_about_instance_action(context, instance,
self.host, action=fields.NotificationAction.POWER_ON,
phase=fields.Notific