Esempio n. 1
0
    def status(self):
        ### Check for taskmanager errors.
        if self.db_info.task_status.is_error:
            return InstanceStatus.ERROR

        ### Check for taskmanager status.
        ACTION = self.db_info.task_status.action
        if 'BUILDING' == ACTION:
            if 'ERROR' == self.db_info.server_status:
                return InstanceStatus.ERROR
            return InstanceStatus.BUILD
        if 'REBOOTING' == ACTION:
            return InstanceStatus.REBOOT
        if 'RESIZING' == ACTION:
            return InstanceStatus.RESIZE

        ### Check for server status.
        if self.db_info.server_status in [
                "BUILD", "ERROR", "REBOOT", "RESIZE"
        ]:
            return self.db_info.server_status

        ### Check if there is a backup running for this instance
        if Backup.running(self.id):
            return InstanceStatus.BACKUP

        ### Report as Shutdown while deleting, unless there's an error.
        if 'DELETING' == ACTION:
            if self.db_info.server_status in ["ACTIVE", "SHUTDOWN", "DELETED"]:
                return InstanceStatus.SHUTDOWN
            else:
                msg = _("While shutting down instance (%s): server had "
                        "status (%s).")
                LOG.error(msg % (self.id, self.db_info.server_status))
                return InstanceStatus.ERROR

        ### Check against the service status.
        # The service is only paused during a reboot.
        if ServiceStatuses.PAUSED == self.service_status.status:
            return InstanceStatus.REBOOT
        # If the service status is NEW, then we are building.
        if ServiceStatuses.NEW == self.service_status.status:
            return InstanceStatus.BUILD

        # For everything else we can look at the service status mapping.
        return self.service_status.status.api_status
Esempio n. 2
0
    def status(self):
        ### Check for taskmanager errors.
        if self.db_info.task_status.is_error:
            return InstanceStatus.ERROR

        ### Check for taskmanager status.
        ACTION = self.db_info.task_status.action
        if 'BUILDING' == ACTION:
            if 'ERROR' == self.db_info.server_status:
                return InstanceStatus.ERROR
            return InstanceStatus.BUILD
        if 'REBOOTING' == ACTION:
            return InstanceStatus.REBOOT
        if 'RESIZING' == ACTION:
            return InstanceStatus.RESIZE

        ### Check for server status.
        if self.db_info.server_status in ["BUILD", "ERROR", "REBOOT",
                                          "RESIZE"]:
            return self.db_info.server_status

        ### Check if there is a backup running for this instance
        if Backup.running(self.id):
            return InstanceStatus.BACKUP

        ### Report as Shutdown while deleting, unless there's an error.
        if 'DELETING' == ACTION:
            if self.db_info.server_status in ["ACTIVE", "SHUTDOWN", "DELETED"]:
                return InstanceStatus.SHUTDOWN
            else:
                msg = _("While shutting down instance (%s): server had "
                        "status (%s).")
                LOG.error(msg % (self.id, self.db_info.server_status))
                return InstanceStatus.ERROR

        ### Check against the service status.
        # The service is only paused during a reboot.
        if ServiceStatuses.PAUSED == self.service_status.status:
            return InstanceStatus.REBOOT
        # If the service status is NEW, then we are building.
        if ServiceStatuses.NEW == self.service_status.status:
            return InstanceStatus.BUILD

        # For everything else we can look at the service status mapping.
        return self.service_status.status.api_status
Esempio n. 3
0
 def validate_can_perform_action(self):
     """
     Raises exception if an instance action cannot currently be performed.
     """
     if self.db_info.server_status != 'ACTIVE':
         status = self.db_info.server_status
     elif self.db_info.task_status != InstanceTasks.NONE:
         status = self.db_info.task_status
     elif not self.service_status.status.action_is_allowed:
         status = self.status
     elif Backup.running(self.id):
         status = InstanceStatus.BACKUP
     else:
         return
     msg = ("Instance is not currently available for an action to be "
            "performed (status was %s)." % status)
     LOG.error(msg)
     raise exception.UnprocessableEntity(msg)
Esempio n. 4
0
 def validate_can_perform_action(self):
     """
     Raises exception if an instance action cannot currently be performed.
     """
     status = None
     if self.db_info.server_status != 'ACTIVE':
         status = self.db_info.server_status
     elif self.db_info.task_status != InstanceTasks.NONE:
         status = self.db_info.task_status
     elif not self.service_status.status.action_is_allowed:
         status = self.status
     elif Backup.running(self.id):
         status = InstanceStatus.BACKUP
     else:
         return
     msg = ("Instance is not currently available for an action to be "
            "performed (status was %s)." % status)
     LOG.error(msg)
     raise exception.UnprocessableEntity(msg)