summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-11-13 05:33:36 +0000
committerGerrit Code Review <review@openstack.org>2012-11-13 05:33:36 +0000
commit7a8db63cef9400adecb5cb0630bb2aed027df3cb (patch)
tree87408a2bee68c265ce8da056176ce4dc2fe65a58
parentc8ecfc285ce890842be3460bf3eb1284e77b3c10 (diff)
parentfe12b264fdcb1084934b3ec69c7e3fa78522356f (diff)
downloadnova-7a8db63cef9400adecb5cb0630bb2aed027df3cb.tar.gz
nova-7a8db63cef9400adecb5cb0630bb2aed027df3cb.tar.xz
nova-7a8db63cef9400adecb5cb0630bb2aed027df3cb.zip
Merge "Make xenapi shutdown mode explicit"
-rw-r--r--nova/virt/xenapi/vm_utils.py40
-rw-r--r--nova/virt/xenapi/vmops.py14
2 files changed, 36 insertions, 18 deletions
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index f6d28ca54..61d59d83b 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -276,22 +276,42 @@ def destroy_vm(session, instance, vm_ref):
LOG.debug(_("VM destroyed"), instance=instance)
-def shutdown_vm(session, instance, vm_ref, hard=True):
- vm_rec = session.call_xenapi("VM.get_record", vm_ref)
- state = compile_info(vm_rec)['state']
- if state == power_state.SHUTDOWN:
+def clean_shutdown_vm(session, instance, vm_ref):
+ if _is_vm_shutdown(session, vm_ref):
LOG.warn(_("VM already halted, skipping shutdown..."),
instance=instance)
- return
+ return False
- LOG.debug(_("Shutting down VM"), instance=instance)
+ LOG.debug(_("Shutting down VM (cleanly)"), instance=instance)
try:
- if hard:
- session.call_xenapi('VM.hard_shutdown', vm_ref)
- else:
- session.call_xenapi('VM.clean_shutdown', vm_ref)
+ session.call_xenapi('VM.clean_shutdown', vm_ref)
except session.XenAPI.Failure, exc:
LOG.exception(exc)
+ return False
+ return True
+
+
+def hard_shutdown_vm(session, instance, vm_ref):
+ if _is_vm_shutdown(session, vm_ref):
+ LOG.warn(_("VM already halted, skipping shutdown..."),
+ instance=instance)
+ return False
+
+ LOG.debug(_("Shutting down VM (hard)"), instance=instance)
+ try:
+ session.call_xenapi('VM.hard_shutdown', vm_ref)
+ except session.XenAPI.Failure, exc:
+ LOG.exception(exc)
+ return False
+ return True
+
+
+def _is_vm_shutdown(session, vm_ref):
+ vm_rec = session.call_xenapi("VM.get_record", vm_ref)
+ state = compile_info(vm_rec)['state']
+ if state == power_state.SHUTDOWN:
+ return True
+ return False
def ensure_free_mem(session, instance):
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index df25b9992..5d250c712 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -693,8 +693,7 @@ class VMOps(object):
instance=instance)
# 2. Power down the instance before resizing
- vm_utils.shutdown_vm(
- self._session, instance, vm_ref, hard=False)
+ vm_utils.clean_shutdown_vm(self._session, instance, vm_ref)
self._update_instance_progress(context, instance,
step=2,
total_steps=RESIZE_TOTAL_STEPS)
@@ -741,8 +740,7 @@ class VMOps(object):
total_steps=RESIZE_TOTAL_STEPS)
# 3. Now power down the instance
- vm_utils.shutdown_vm(
- self._session, instance, vm_ref, hard=False)
+ vm_utils.clean_shutdown_vm(self._session, instance, vm_ref)
self._update_instance_progress(context, instance,
step=3,
total_steps=RESIZE_TOTAL_STEPS)
@@ -1075,7 +1073,7 @@ class VMOps(object):
instance=instance)
return
- vm_utils.shutdown_vm(self._session, instance, vm_ref)
+ vm_utils.hard_shutdown_vm(self._session, instance, vm_ref)
# Destroy VDIs
self._detach_vm_vols(instance, vm_ref, block_device_info)
@@ -1126,7 +1124,7 @@ class VMOps(object):
% instance['name'])
vm_ref = self._get_vm_opaque_ref(instance)
- vm_utils.shutdown_vm(self._session, instance, vm_ref)
+ vm_utils.hard_shutdown_vm(self._session, instance, vm_ref)
self._acquire_bootlock(vm_ref)
self.spawn(context, instance, image_meta, [], rescue_password,
network_info, name_label=rescue_name_label, rescue=True)
@@ -1159,7 +1157,7 @@ class VMOps(object):
LOG.warning(_("VM is not present, skipping soft delete..."),
instance=instance)
else:
- vm_utils.shutdown_vm(self._session, instance, vm_ref, hard=True)
+ vm_utils.hard_shutdown_vm(self._session, instance, vm_ref)
self._acquire_bootlock(vm_ref)
def restore(self, instance):
@@ -1171,7 +1169,7 @@ class VMOps(object):
def power_off(self, instance):
"""Power off the specified instance."""
vm_ref = self._get_vm_opaque_ref(instance)
- vm_utils.shutdown_vm(self._session, instance, vm_ref, hard=True)
+ vm_utils.hard_shutdown_vm(self._session, instance, vm_ref)
def power_on(self, instance):
"""Power on the specified instance."""