Esempio n. 1
0
    def start_bind_job(self, context, valid_fields):
        """Check and start bind jobs for ARQ."""
        expected = ARQ_STATES_TRANSFORM_MATRIX[constants.ARQ_BIND_STARTED]
        # Check whether ARQ can be bound.
        if self.arq.state not in expected:
            raise exception.ARQBadState(state=self.arq.state,
                                        uuid=self.arq.uuid,
                                        expected=expected)

        hostname = valid_fields[self.arq.uuid]['hostname']
        devrp_uuid = valid_fields[self.arq.uuid]['device_rp_uuid']
        instance_uuid = valid_fields[self.arq.uuid]['instance_uuid']
        project_id = valid_fields[self.arq.uuid].get('project_id')
        LOG.info(
            '[arqs:objs] bind. hostname: %(hostname)s, '
            'devrp_uuid: %(devrp_uuid)s, '
            'instance_uuid: %(instance_uuid)s, '
            'project_id: %(project_id)s', {
                'hostname': hostname,
                'devrp_uuid': devrp_uuid,
                'instance_uuid': instance_uuid,
                'project_id': project_id
            })

        self.arq.hostname = hostname
        self.arq.device_rp_uuid = devrp_uuid
        self.arq.instance_uuid = instance_uuid
        self.arq.project_id = project_id

        # If prog fails, we'll change this ARQ state changes get committed here
        self.update_check_state(context, constants.ARQ_BIND_STARTED)

        dep = objects.Deployable.get_by_device_rp_uuid(context, devrp_uuid)
        return self._bind_job(context, dep)
Esempio n. 2
0
    def get_arq_bind_statuses(cls, arq_list):
        """Return the list of UUID/state pairs for each ARQ.

        :param arq_list: List of ARQ objects.
        :returns: List of (arq_uuid, arq_bind_status) tuples.
        :raises: ARQBadState exception if any ARQ state is invalid.
        """
        # NOTE(Sundar): This should be called when all ARQs have
        # completed binding, successfully or not. One or more may be in
        # deleting state. So, arq_state must be 'Bound', 'BindFailed'
        # or 'Deleting'
        state_map = constants.ARQ_BIND_STATES_STATUS_MAP
        good_states = list(state_map.keys())
        arq_bind_statuses = []
        for arq in arq_list:
            if arq.state not in good_states:
                raise exception.ARQBadState(
                    state=arq.state, uuid=arq.uuid, expected=good_states)
            arq_bind_status = (arq.uuid, state_map[arq.state])
            arq_bind_statuses.append(arq_bind_status)
        return arq_bind_statuses
Esempio n. 3
0
 def update_check_state(self, context, state, scope=None):
     if self.arq.state == state:
         LOG.info("ExtARQ(%s) state is %s, no need to update",
                  self.arq.uuid, state)
         return False
     old = self.arq.state
     scope = scope or ARQ_STATES_TRANSFORM_MATRIX[state]
     self.update_state(context, state, scope)
     ea = ExtARQ.get(context, self.arq.uuid, lock=True)
     if not ea:
         raise exception.ResourceNotFound("Can not find ExtARQ(%s)" %
                                          self.arq.uuid)
     current = ea.arq.state
     if state != current:
         msg = ("Failed to change ARQ state from %s to %s, the current "
                "state is %s" % (old, state, current))
         LOG.error(msg)
         raise exception.ARQBadState(state=current,
                                     uuid=self.arq.uuid,
                                     expected=list(state))
     return True
Esempio n. 4
0
    def get_all(self, bind_state=None, instance=None):
        """Retrieve a list of arqs."""
        # TODO(Sundar) Need to implement 'arq=uuid1,...' query parameter
        LOG.info('[arqs] get_all. bind_state:(%s), instance:(%s)', bind_state
                 or '', instance or '')
        context = pecan.request.context
        extarqs = objects.ExtARQ.list(context)
        state_map = constants.ARQ_BIND_STATES_STATUS_MAP
        valid_bind_states = list(state_map.keys())
        arqs = [extarq.arq for extarq in extarqs]
        # TODO(Sundar): Optimize by doing the filtering in the db layer
        # Apply instance filter before state filter.
        if bind_state and bind_state != 'resolved':
            raise exception.ARQBadState(state=bind_state,
                                        uuid=None,
                                        expected=['resolved'])
        if instance:
            new_arqs = [
                arq for arq in arqs if arq['instance_uuid'] == instance
            ]
            arqs = new_arqs
            if bind_state:
                for arq in new_arqs:
                    if arq['state'] not in valid_bind_states:
                        # NOTE(Sundar) This should return HTTP code 423
                        # if any ARQ for this instance is not resolved.
                        LOG.warning(
                            'Some of ARQs for instance %s is not '
                            'resolved', instance)
                        return wsme.api.Response(None,
                                                 status_code=HTTPStatus.LOCKED)
        elif bind_state:
            arqs = [arq for arq in arqs if arq['state'] in valid_bind_states]

        ret = ARQCollection.convert_with_links(arqs)
        LOG.info('[arqs:get_all] Returned: %s', ret)
        return ret