Esempio n. 1
0
    def get_one(self, uuid):
        """Retrieve a single device profile by uuid."""
        LOG.info('[device_profiles] get_one. uuid=%s', uuid)
        api_obj_devprofs = self._get_device_profile_list(uuid=uuid)
        if len(api_obj_devprofs) == 0:
            raise exception.ResourceNotFound(resource='Device profile',
                                             msg='with uuid %s' % uuid)

        count = len(api_obj_devprofs)
        if count != 1:  # Should never happen because names are unique
            raise exception.ExpectedOneObject(obj='device profile',
                                              count=count)
        ret = {"device_profile": api_obj_devprofs[0]}
        LOG.info('[device_profiles] get_one returned: %s', ret)
        # TODO(Sundar) Replace this with convert_with_links()
        return wsme.api.Response(ret,
                                 status_code=http_client.OK,
                                 return_type=wsme.types.DictType)
Esempio n. 2
0
 def _get_bitstream_md_from_function_id(self, function_id):
     """Get bitstream metadata given a function id."""
     # TODO(Shaohe) parametrize this role in config file.
     conn = connection.Connection(cloud='devstack-admin')
     properties = {constants.ACCEL_FUNCTION_ID: function_id}
     resp = conn.image.get('/images', params=properties)
     if resp:
         image_list = resp.json()['images']
         if type(image_list) != list:
             raise exception.InvalidType(obj='image',
                                         type=type(image_list),
                                         expected='list')
         if len(image_list) != 1:
             raise exception.ExpectedOneObject(obj='image',
                                               count=len(image_list))
         LOG.info(
             '[arqs:objs] For function id (%s), got '
             'bitstream id (%s)', function_id, image_list[0]['id'])
         return image_list[0]
     else:
         LOG.warning('Failed to get image for function (%s)', function_id)
         return None
Esempio n. 3
0
    def _do_programming(self, context, deployable, bitstream_id):
        """FPGA program."""
        hostname = self.arq.hostname
        driver_name = deployable.driver_name

        # query_filter = {"device_id": deployable.device_id}
        # TODO(Shaohe) We should probably get cpid from objects layer,
        # not db layer
        cpid_list = deployable.get_cpid_list(context)
        count = len(cpid_list)
        if count != 1:
            self.update_check_state(
                context, constants.ARQ_BIND_FAILED)
            raise exception.ExpectedOneObject(type='controlpath_id',
                                              count=count)
        controlpath_id = cpid_list[0]
        controlpath_id['cpid_info'] = jsonutils.loads(
            controlpath_id['cpid_info'])
        LOG.info('Found control path id: %s', controlpath_id)

        LOG.info('Starting programming for host: (%s) deployable (%s) '
                 'bitstream_id (%s)', hostname,
                 deployable.uuid, bitstream_id)
        # TODO(Shaohe) do this asynchronously, do this in conductor or agent?
        try:
            agent = AgentAPI()
            agent.fpga_program_v2(context, hostname,
                                  controlpath_id, bitstream_id,
                                  driver_name)
        except Exception as e:
            self.update_check_state(
                context, constants.ARQ_BIND_FAILED)
            LOG.error('Failed programming for host: (%s) deployable (%s). '
                      'Error: %s', hostname, deployable.uuid, e.message)
            raise
        LOG.info('Finished programming for host: (%s) deployable (%s)',
                 hostname, deployable.uuid)
        # TODO(Shaohe) propagate agent errors to caller
        return True