~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/api/openstack/servers.py

  • Committer: Tarmac
  • Author(s): Brian Lamar, Dan Prince
  • Date: 2011-08-31 22:55:34 UTC
  • mfrom: (1443.3.61 instance_states)
  • Revision ID: tarmac-20110831225534-upfhtsvcsafyql6x
Fixed and improved the way instance "states" are set. Instead of relying on solely the power_state of a VM, there are now explicitly defined VM states and VM task states which respectively define the current state of the VM and the task which is currently being performed by the VM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
        search_opts['recurse_zones'] = utils.bool_from_str(
96
96
                search_opts.get('recurse_zones', False))
97
97
 
98
 
        # If search by 'status', we need to convert it to 'state'
99
 
        # If the status is unknown, bail.
100
 
        # Leave 'state' in search_opts so compute can pass it on to
101
 
        # child zones..
 
98
        # If search by 'status', we need to convert it to 'vm_state'
 
99
        # to pass on to child zones.
102
100
        if 'status' in search_opts:
103
101
            status = search_opts['status']
104
 
            search_opts['state'] = common.power_states_from_status(status)
105
 
            if len(search_opts['state']) == 0:
 
102
            state = common.vm_state_from_status(status)
 
103
            if state is None:
106
104
                reason = _('Invalid server status: %(status)s') % locals()
107
 
                LOG.error(reason)
108
105
                raise exception.InvalidInput(reason=reason)
 
106
            search_opts['vm_state'] = state
109
107
 
110
108
        # By default, compute's get_all() will return deleted instances.
111
109
        # If an admin hasn't specified a 'deleted' search option, we need
608
606
 
609
607
        try:
610
608
            self.compute_api.rebuild(context, instance_id, image_id, password)
611
 
        except exception.BuildInProgress:
612
 
            msg = _("Instance %s is currently being rebuilt.") % instance_id
613
 
            LOG.debug(msg)
 
609
        except exception.RebuildRequiresActiveInstance:
 
610
            msg = _("Instance %s must be active to rebuild.") % instance_id
614
611
            raise exc.HTTPConflict(explanation=msg)
615
612
 
616
613
        return webob.Response(status_int=202)
750
747
            self.compute_api.rebuild(context, instance_id, image_href,
751
748
                                     password, name=name, metadata=metadata,
752
749
                                     files_to_inject=personalities)
753
 
        except exception.BuildInProgress:
754
 
            msg = _("Instance %s is currently being rebuilt.") % instance_id
755
 
            LOG.debug(msg)
 
750
        except exception.RebuildRequiresActiveInstance:
 
751
            msg = _("Instance %s must be active to rebuild.") % instance_id
756
752
            raise exc.HTTPConflict(explanation=msg)
757
753
        except exception.InstanceNotFound:
758
754
            msg = _("Instance %s could not be found") % instance_id