From 5b85997e33aa749ece94edebaaefefe71b899561 Mon Sep 17 00:00:00 2001 From: Yun Mao Date: Thu, 24 May 2012 21:51:57 -0400 Subject: cleanup power state (partially implements bp task-management) Removed duplicate and invalid state in power_state: FAILED, SHUTOFF, BLOCKED This is the first step in cleaning up nova state machine and do better task management (bp/task-management) http://wiki.openstack.org/VMState Change-Id: I586b9058fada5efd468870fb187590fc0e37aa8f --- nova/compute/manager.py | 3 +-- nova/compute/power_state.py | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 6a0251a15..3159ffd52 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -306,7 +306,7 @@ class ComputeManager(manager.SchedulerDependentManager): try: return self.driver.get_info(instance)["state"] except exception.NotFound: - return power_state.FAILED + return power_state.NOSTATE def get_console_topic(self, context, **kwargs): """Retrieves the console host for a project on this host. @@ -2488,7 +2488,6 @@ class ComputeManager(manager.SchedulerDependentManager): continue if (vm_power_state in (power_state.NOSTATE, - power_state.SHUTOFF, power_state.SHUTDOWN, power_state.CRASHED) and db_instance['vm_state'] == vm_states.ACTIVE): diff --git a/nova/compute/power_state.py b/nova/compute/power_state.py index c468fe6b3..6d1c00b98 100644 --- a/nova/compute/power_state.py +++ b/nova/compute/power_state.py @@ -18,18 +18,26 @@ # License for the specific language governing permissions and limitations # under the License. -"""The various power states that a VM can be in.""" - -#NOTE(justinsb): These are the virDomainState values from libvirt +"""Power state is the state we get by calling virt driver on a particular +domain. The hypervisor is always considered the authority on the status +of a particular VM, and the power_state in the DB should be viewed as a +snapshot of the VMs's state in the (recent) past. It can be periodically +updated, and should also be updated at the end of a task if the task is +supposed to affect power_state. +""" + +# NOTE(maoy): These are *not* virDomainState values from libvirt. +# The hex value happens to match virDomainState for backward-compatibility +# reasons. NOSTATE = 0x00 RUNNING = 0x01 -BLOCKED = 0x02 PAUSED = 0x03 -SHUTDOWN = 0x04 -SHUTOFF = 0x05 +SHUTDOWN = 0x04 # the VM is powered off CRASHED = 0x06 SUSPENDED = 0x07 -FAILED = 0x08 + +# TODO(maoy): BUILDING state is only used in bare metal case and should +# eventually be removed/cleaned up. NOSTATE is probably enough. BUILDING = 0x09 # TODO(justinsb): Power state really needs to be a proper class, @@ -38,13 +46,10 @@ BUILDING = 0x09 _STATE_MAP = { NOSTATE: 'pending', RUNNING: 'running', - BLOCKED: 'blocked', PAUSED: 'paused', SHUTDOWN: 'shutdown', - SHUTOFF: 'shutdown', CRASHED: 'crashed', SUSPENDED: 'suspended', - FAILED: 'failed to spawn', BUILDING: 'building', } -- cgit