1、nova 命令
#软重启
nova reboot SERVER
#硬重启
nova reboot --hard SERVER
2、软硬重启区别
1) 软重启只是重启操作系统 ,整个过程中,虚拟机还处于运行状态,相当于在linux中执行reboot命令;
2)硬重启是重启虚拟机,相当于关机之后再开机。
3、代码分析
#nova.nova.api.openstack.compute.servers.ServersController._action_reboot
@wsgi.response(202)
@extensions.expected_errors((404, 409))
@wsgi.action('reboot')
@validation.schema(schema_servers.reboot)
def _action_reboot(self, req, id, body):
#获取重启类型
reboot_type = body['reboot']['type'].upper()
context = req.environ['nova.context']
context.can(server_policies.SERVERS % 'reboot')
instance = self._get_server(context, req, id)
try:
#跳转到nova.compute.api
self.compute_api.reboot(context, instance, reboot_type)
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'reboot', id)
@check_instance_lock
def reboot(self, context, instance, reboot_type):
"""Reboot the given instance."""
if reboot_type == 'SOFT':
self._soft_reboot(context, instance)
else:
self._hard_reboot(context, instance)
@check_instance_state(vm_state=set(vm_states.ALLOW_SOFT_REBOOT),
task_state=[None])
def _soft_reboot(self, context, instance):
expected_task_state = [None]
instance.task_state =