Ejemplo n.º 1
0
    def _list(self,
              url,
              response_key,
              obj_class=None,
              body=None,
              filters=None):
        if filters:
            url = utils.get_url_with_filter(url, filters)
        if body:
            resp, body = self.api.client.post(url, body=body)
        else:
            resp, body = self.api.client.get(url)

        if obj_class is None:
            obj_class = self.resource_class

        data = body[response_key]
        # NOTE(ja): keystone returns values as list as {'values': [ ... ]}
        #           unlike other services which just return the list...
        if isinstance(data, dict):
            try:
                data = data['values']
            except KeyError:
                pass

        with self.completion_cache('human_id', obj_class, mode="w"):
            with self.completion_cache('uuid', obj_class, mode="w"):
                items = [
                    obj_class(self, res, loaded=True) for res in data if res
                ]
                return ListWithMeta(items, resp)
Ejemplo n.º 2
0
    def _list(self, url, response_key, obj_class=None, body=None,
              filters=None):
        if filters:
            url = utils.get_url_with_filter(url, filters)
        if body:
            resp, body = self.api.client.post(url, body=body)
        else:
            resp, body = self.api.client.get(url)

        if obj_class is None:
            obj_class = self.resource_class

        data = body[response_key]
        # NOTE(ja): keystone returns values as list as {'values': [ ... ]}
        #           unlike other services which just return the list...
        if isinstance(data, dict):
            try:
                data = data['values']
            except KeyError:
                pass

        with self.completion_cache('human_id', obj_class, mode="w"):
            with self.completion_cache('uuid', obj_class, mode="w"):
                items = [obj_class(self, res, loaded=True)
                         for res in data if res]
                return ListWithMeta(items, resp)
Ejemplo n.º 3
0
 def _get(self, url, response_key, filters=None):
     if filters:
         url = utils.get_url_with_filter(url, filters)
     resp, body = self.api.client.get(url)
     if response_key is not None:
         content = body[response_key]
     else:
         content = body
     return self.resource_class(self, content, loaded=True, resp=resp)
Ejemplo n.º 4
0
 def _get(self, url, response_key, filters=None):
     if filters:
         url = utils.get_url_with_filter(url, filters)
     resp, body = self.api.client.get(url)
     if response_key is not None:
         content = body[response_key]
     else:
         content = body
     return self.resource_class(self, content, loaded=True,
                                resp=resp)
Ejemplo n.º 5
0
 def test_get_url_with_filter(self):
     url = '/fake'
     for case in self.cases:
         self.assertEqual(
             '%s%s' % (url, case[1]),
             parse.unquote_plus(utils.get_url_with_filter(url, case[0])))