示例#1
0
    def get_related(self, entity_id, related, filter_fields=None, fields=None):
        url_params = dict(entity=self.entity,
                          entity_id=entity_id,
                          related=related)

        r, response = self.send_get_request(self.base_relationship_url,
                                            **url_params)
        if r.status_code != requests.codes.ok:
            msg = ('Failed to query related {related} entities for PowerFlex '
                   '{entity} with id {_id}.'
                   ' Error: {response}'.format(related=related,
                                               entity=self.entity,
                                               _id=entity_id,
                                               response=response))
            LOG.error(msg)
            raise exceptions.PowerFlexClientException(msg)
        if filter_fields:
            response = utils.filter_response(response, filter_fields)
        if fields:
            response = utils.query_response_fields(response, fields)
        return response
示例#2
0
    def get(self, entity_id=None, filter_fields=None, fields=None):
        url = self.base_entity_list_or_create_url
        url_params = dict(entity=self.entity)

        if entity_id:
            url = self.base_entity_url
            url_params['entity_id'] = entity_id
            if filter_fields:
                msg = 'Can not apply filtering while querying entity by id.'
                raise exceptions.InvalidInput(msg)

        r, response = self.send_get_request(url, **url_params)
        if r.status_code != requests.codes.ok:
            exc = exceptions.PowerFlexFailQuerying(self.entity, entity_id)
            LOG.error(exc.message)
            raise exc
        if filter_fields:
            response = utils.filter_response(response, filter_fields)
        if fields:
            response = utils.query_response_fields(response, fields)
        return response
示例#3
0
 def test_utils_query_response_fields_invalid_field(self):
     fields = ('not_found_in_response', 'first', 'second')
     with self.assertRaises(exceptions.FieldsNotFound):
         utils.query_response_fields(self.fake_response, fields)
示例#4
0
 def test_utils_query_response_fields_dict(self):
     fields = ('first', )
     result = utils.query_response_fields(self.fake_response[0], fields)
     self.assertTrue(len(result) == 1)
     self.assertTrue(result['first'])
示例#5
0
 def test_utils_query_response_fields_list(self):
     fields = ('first', )
     result = utils.query_response_fields(self.fake_response, fields)
     self.assertTrue(all(map(lambda entity: len(entity) == 1, result)))
     self.assertTrue(all(map(lambda entity: entity['first'], result)))