← Back to team overview

openstack team mailing list archive

Re: "Shutoff" Status

 

Anne:

I don't have first hand-experience, but based on looking at the code, it appears that an instance is in "SHUTDOWN" state if the VM was powered down, but not through the OpenStack API (e.g., by a user doing "shutdown -h" from inside the instance). On Amazon EC2, if a user does a "shutdown -h", the instance will transition to the terminated state. But apparently OpenStack doesn't behave that way (?) by default (???). 

Here are my ramblings through the code that led me to this:

Looking at ./nova/api/openstack/common.py:

_STATE_MAP = {
    vm_states.SHUTOFF: {
        'default': 'SHUTOFF',
    },

It looks like SHUTOFF in the API corresponds to a VM state of SHUTOFF. The transition to shutoff state seems to be in ./nova/compute/manager.py:

    @manager.periodic_task(ticks_between_runs=10)
    def _sync_power_states(self, context):
   ...
            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):
                self._instance_update(context,
                                      db_instance["id"],
                                      power_state=vm_power_state,
                                      vm_state=vm_states.SHUTOFF)


So, if the compute manager detects to the VM is powered down (e.g., the user did a "shutdown" command), then it will transition to the SHUTOFF state. 


I don't quite understand what happens if you use the compute API to try to start an instance in the shutdown state. I think it tries to delete the instance first, but this depends on a "shutdown_terminate" database field on the Instance model.

Here's the start method from nova/compute/api.py:

    @wrap_check_policy
    @check_instance_state(vm_state=[vm_states.STOPPED, vm_states.SHUTOFF])
    def start(self, context, instance):
        """Start an instance."""
        vm_state = instance["vm_state"]
        instance_uuid = instance["uuid"]
        LOG.debug(_("Going to try to start instance"), instance=instance)

        if vm_state == vm_states.SHUTOFF:
            if instance['shutdown_terminate']:
                LOG.warning(_("Instance %(instance_uuid)s is not "
                              "stopped. (%(vm_state)s") % locals())
                return

            # NOTE(yamahata): nova compute doesn't reap instances
            # which initiated shutdown itself. So reap it here.
            self.stop(context, instance, do_cast=False)

        self.update(context,
                    instance,
                    vm_state=vm_states.STOPPED,
                    task_state=task_states.STARTING)

        # TODO(yamahata): injected_files isn't supported right now.
        #                 It is used only for osapi. not for ec2 api.
        #                 availability_zone isn't used by run_instance.
        self._cast_compute_message('start_instance', context, instance)


Here's the database field definition in db/sqlalchemy/models.py

class Instance(BASE, NovaBase):
...
    # EC2 instance_initiated_shutdown_teminate
    # True: -> 'terminate'
    # False: -> 'stop'
    shutdown_terminate = Column(Boolean(), default=True, nullable=False)


I can't tell if shutdown_terminate is a state variable (e.g., instance is currently in "shutdown_terminate=True" state), or if it's a per-instance behavior configuration variable (e.g., "terminate an instance in the shutdown state if shutdown_terminate=True")


Take care,

Lorin
--
Lorin Hochstein
Lead Architect - Cloud Services
Nimbis Services, Inc.
www.nimbisservices.com





On Apr 25, 2012, at 3:23 PM, Anne Gentle wrote:

> Hey, sorry y'all. I grepped for SUSPENDED but needed to do it for SHUTOFF. What can you tell me about SHUTOFF based on the code here?
> 
> Yep, not too embarrassed to admit this to 3000+ of you. :)
> 
> ./nova/api/ec2/cloud.py:    vm_states.SHUTOFF: inst_state.SHUTOFF,
> ./nova/api/ec2/cloud.py:    if (vm_state == vm_states.SHUTOFF and
> ./nova/api/ec2/cloud.py:            if vm_state not in (vm_states.ACTIVE, vm_states.SHUTOFF,
> ./nova/api/ec2/cloud.py:            if vm_state in (vm_states.ACTIVE, vm_states.SHUTOFF):
> Binary file ./nova/api/ec2/cloud.pyc matches
> ./nova/api/ec2/inst_state.py:SHUTOFF = 'shutoff'
> ./nova/api/ec2/inst_state.py:    SHUTOFF: TERMINATED_CODE,
> Binary file ./nova/api/ec2/inst_state.pyc matches
> ./nova/api/openstack/common.py:    vm_states.SHUTOFF: {
> ./nova/api/openstack/common.py:        'default': 'SHUTOFF',
> Binary file ./nova/api/openstack/common.pyc matches
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF,
> ./nova/compute/api.py:                                    vm_states.SHUTOFF, vm_states.STOPPED])
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF,
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.STOPPED, vm_states.SHUTOFF])
> ./nova/compute/api.py:        if vm_state == vm_states.SHUTOFF:
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF])
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF])
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF,
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF],
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF],
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF],
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF],
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF,
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF,
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF,
> Binary file ./nova/compute/api.pyc matches
> ./nova/compute/manager.py:                                   power_state.SHUTOFF,
> ./nova/compute/manager.py:                                      vm_state=vm_states.SHUTOFF)
> Binary file ./nova/compute/manager.pyc matches
> ./nova/compute/power_state.py:SHUTOFF = 0x05
> ./nova/compute/power_state.py:    SHUTOFF: 'shutdown',
> Binary file ./nova/compute/power_state.pyc matches
> ./nova/compute/vm_states.py:SHUTOFF = 'shutoff'
> Binary file ./nova/compute/vm_states.pyc matches
> ./nova/tests/api/ec2/test_cloud.py:        test_instance_state(inst_state.TERMINATED_CODE, inst_state.SHUTOFF,
> ./nova/tests/api/ec2/test_cloud.py:                            power_state.NOSTATE, vm_states.SHUTOFF)
> ./nova/tests/api/ec2/test_cloud.py:                            power_state.NOSTATE, vm_states.SHUTOFF,
> ./nova/tests/baremetal/test_proxy_bare_metal.py:              dict(node_id=6, name='i-00000006', status=power_state.SHUTOFF),
> ./nova/tests/fakelibvirt.py:VIR_DOMAIN_SHUTOFF = 5
> ./nova/tests/fakelibvirt.py:        self._state = running and VIR_DOMAIN_RUNNING or VIR_DOMAIN_SHUTOFF
> ./nova/tests/fakelibvirt.py:        self._state = VIR_DOMAIN_SHUTOFF
> ./nova/tests/test_compute.py:                            'vm_state': vm_states.SHUTOFF})
> ./nova/tests/test_compute.py:        check_state(instance_uuid, power_state.NOSTATE, vm_states.SHUTOFF,
> ./nova/tests/test_compute.py:                          power_state.NOSTATE, vm_states.SHUTOFF, None)
> ./nova/tests/test_libvirt.py:                return {'state': power_state.SHUTOFF}
> ./nova/virt/libvirt/connection.py:                    if state == power_state.SHUTOFF:
> ./nova/virt/libvirt/connection.py:                         power_state.SHUTOFF,
> Binary file ./nova/virt/libvirt/connection.pyc matches
> 
> 
> On Mon, Apr 23, 2012 at 10:02 PM, Anne Gentle <anne@xxxxxxxxxxxxx> wrote:
> Hi all -
> We just added descriptions of each of the statuses to this page, but "SUSPENDED" is not one of them:
> 
> http://docs.openstack.org/api/openstack-compute/2/content/List_Servers-d1e2078.html
> 
> Who has more information about this server status? By grepping the code I get this additional info which may mean it only applies to bare metal deploy and/or xenapi?
> 
> ./nova/api/ec2/cloud.py:    vm_states.SUSPENDED: inst_state.SUSPEND,
> ./nova/api/openstack/common.py:    vm_states.SUSPENDED: {
> ./nova/api/openstack/common.py:        'default': 'SUSPENDED',
> ./nova/compute/api.py:    @check_instance_state(vm_state=[vm_states.SUSPENDED])
> ./nova/compute/api.py:                    vm_state=vm_states.SUSPENDED,
> ./nova/compute/manager.py:                              vm_state=vm_states.SUSPENDED,
> ./nova/compute/power_state.py:SUSPENDED = 0x07
> ./nova/compute/power_state.py:    SUSPENDED: 'suspended',
> ./nova/compute/vm_states.py:SUSPENDED = 'suspended'
> ./nova/tests/baremetal/test_proxy_bare_metal.py:              dict(node_id=8, name='i-00000008', status=power_state.SUSPENDED),
> ./nova/tests/test_compute.py:                           {'vm_state': vm_states.SUSPENDED})
> ./nova/tests/test_compute.py:                search_opts={'power_state': power_state.SUSPENDED})
> ./nova/virt/baremetal/proxy.py:                            'power_state': power_state.SUSPENDED})
> ./nova/virt/xenapi/vm_utils.py:    'Suspended': power_state.SUSPENDED,
> 
> Thanks,
> Anne
> 
> On Mon, Apr 23, 2012 at 9:24 AM, Razique Mahroua <razique.mahroua@xxxxxxxxx> wrote:
> Hello Alyssa, the status is the one reported when you suspend your instance
> 
> Nuage & Co - Razique Mahroua 
> razique.mahroua@xxxxxxxxx
> 
> 
> 
> Le 16 avr. 2012 à 18:15, Alyssa Hurtgen a écrit :
> 
>> Hi all,
>> 
>> I work at Rackspace and noticed a new Nova server status of "shutoff".  
>> What does this status mean?
>> How does the server get into this status?
>> Should the user be able to perform any actions against the server?
>> Thanks,
>> Alyssa Hurtgen
>> _______________________________________________
>> Mailing list: https://launchpad.net/~openstack
>> Post to     : openstack@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~openstack
>> More help   : https://help.launchpad.net/ListHelp
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~openstack
> Post to     : openstack@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~openstack
> More help   : https://help.launchpad.net/ListHelp
> 
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~openstack
> Post to     : openstack@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~openstack
> More help   : https://help.launchpad.net/ListHelp

Attachment: smime.p7s
Description: S/MIME cryptographic signature


References