예제 #1
0
    def test_build_param_with_none(self):
        dict_param = {'key1': 'val1', 'key2': None, 'key3': False, 'key4': ''}
        result_1 = utils.build_query_param(dict_param)
        result_2 = utils.build_query_param(None)

        expected = "?key1=val1"
        self.assertEqual(expected, result_1)
        self.assertFalse(result_2)
예제 #2
0
    def test_build_param_with_none(self):
        dict_param = {
            'key1': 'val1',
            'key2': None,
            'key3': False,
            'key4': ''
        }
        result_1 = utils.build_query_param(dict_param)
        result_2 = utils.build_query_param(None)

        expected = "?key1=val1"
        self.assertEqual(expected, result_1)
        self.assertFalse(result_2)
예제 #3
0
    def test_build_param_with_nones(self, dict_param):
        result = utils.build_query_param(dict_param)

        expected = ("key1=val1", "key3=False") if dict_param else ()
        for exp in expected:
            self.assertIn(exp, result)
        if not expected:
            self.assertEqual("", result)
예제 #4
0
    def test_build_param_with_nones(self, dict_param):
        result = utils.build_query_param(dict_param)

        expected = ("key1=val1", "key3=False") if dict_param else ()
        for exp in expected:
            self.assertIn(exp, result)
        if not expected:
            self.assertEqual("", result)
예제 #5
0
    def get(self, group_id, **kwargs):
        """Get a group.

        :param group_id: The ID of the group to get.
        :rtype: :class:`Group`
        """
        query_params = utils.unicode_key_value_to_string(kwargs)
        query_string = utils.build_query_param(query_params, sort=True)

        return self._get("/groups/%s" % group_id + query_string, "group")
예제 #6
0
    def test_build_param_with_sort_switch(self):
        dict_param = {
            'key1': 'val1',
            'key2': 'val2',
            'key3': 'val3',
        }
        result = utils.build_query_param(dict_param, True)

        expected = "?key1=val1&key2=val2&key3=val3"
        self.assertEqual(expected, result)
예제 #7
0
    def test_build_param_with_sort_switch(self):
        dict_param = {
            'key1': 'val1',
            'key2': 'val2',
            'key3': 'val3',
        }
        result = utils.build_query_param(dict_param, True)

        expected = "?key1=val1&key2=val2&key3=val3"
        self.assertEqual(expected, result)
예제 #8
0
    def _build_list_url(self,
                        resource_type,
                        detailed=True,
                        search_opts=None,
                        marker=None,
                        limit=None,
                        sort_key=None,
                        sort_dir=None,
                        sort=None,
                        offset=None):

        if search_opts is None:
            search_opts = {}

        query_params = {}
        for key, val in search_opts.items():
            if val:
                query_params[key] = val

        if marker:
            query_params['marker'] = marker

        if limit:
            query_params['limit'] = limit

        if sort:
            query_params['sort'] = self._format_sort_param(sort, resource_type)
        else:
            # sort_key and sort_dir deprecated in kilo, prefer sort
            if sort_key:
                query_params['sort_key'] = self._format_sort_key_param(
                    sort_key, resource_type)

            if sort_dir:
                query_params['sort_dir'] = self._format_sort_dir_param(
                    sort_dir)

        if offset:
            query_params['offset'] = offset
        query_params = utils.unicode_key_value_to_string(query_params)
        # Transform the dict to a sequence of two-element tuples in fixed
        # order, then the encoded string will be consistent in Python 2&3.

        query_string = utils.build_query_param(query_params, sort=True)

        detail = ""
        if detailed:
            detail = "/detail"

        return ("/%(resource_type)s%(detail)s%(query_string)s" % {
            "resource_type": resource_type,
            "detail": detail,
            "query_string": query_string
        })
예제 #9
0
    def test_build_param_without_sort_switch(self):
        dict_param = {
            'key1': 'val1',
            'key2': 'val2',
            'key3': 'val3',
        }
        result = utils.build_query_param(dict_param, True)

        self.assertIn('key1=val1', result)
        self.assertIn('key2=val2', result)
        self.assertIn('key3=val3', result)
예제 #10
0
    def get(self, group_id, **kwargs):
        """Get a group.

        :param group_id: The ID of the group to get.
        :rtype: :class:`Group`
        """
        query_params = utils.unicode_key_value_to_string(kwargs)
        query_string = utils.build_query_param(query_params, sort=True)

        return self._get("/groups/%s" % group_id + query_string,
                         "group")
예제 #11
0
    def test_build_param_without_sort_switch(self):
        dict_param = {
            'key1': 'val1',
            'key2': 'val2',
            'key3': 'val3',
        }
        result = utils.build_query_param(dict_param, True)

        self.assertIn('key1=val1', result)
        self.assertIn('key2=val2', result)
        self.assertIn('key3=val3', result)
예제 #12
0
    def list(self, base_url=None, **kwargs):
        """List the collection.

        :param base_url: if provided, the generated URL will be appended to it
        """
        kwargs = self._filter_kwargs(kwargs)

        return self._list(
            '%(base_url)s%(query)s' % {
                'base_url': self.build_url(base_url=base_url, **kwargs),
                'query': utils.build_query_param(kwargs),
            }, self.collection_key)
예제 #13
0
    def get(self, tenant_id=None):
        """Get a specific extension.

        :rtype: :class:`Limits`
        """
        opts = {}
        if tenant_id:
            opts['tenant_id'] = tenant_id

        query_string = utils.build_query_param(opts)

        return self._get("/limits%s" % query_string, "limits")
예제 #14
0
    def list(self, detailed=True, search_opts=None):
        """Get a list of all volume transfer.

        :rtype: list of :class:`VolumeTransfer`
        """
        query_string = utils.build_query_param(search_opts)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/os-volume-transfer%s%s" % (detail, query_string),
                          "transfers")
예제 #15
0
    def list(self, detailed=True, search_opts=None):
        """Lists all cgsnapshots.

        :rtype: list of :class:`Cgsnapshot`
        """
        query_string = utils.build_query_param(search_opts)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/cgsnapshots%s%s" % (detail, query_string),
                          "cgsnapshots")
예제 #16
0
    def list(self, base_url=None, **kwargs):
        """List the collection.

        :param base_url: if provided, the generated URL will be appended to it
        """
        kwargs = self._filter_kwargs(kwargs)

        return self._list(
            '%(base_url)s%(query)s' % {
                'base_url': self.build_url(base_url=base_url, **kwargs),
                'query': utils.build_query_param(kwargs),
            },
            self.collection_key)
예제 #17
0
    def list(self, detailed=True, search_opts=None):
        """Lists all cgsnapshots.

        :rtype: list of :class:`Cgsnapshot`
        """
        query_string = utils.build_query_param(search_opts)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/cgsnapshots%s%s" % (detail, query_string),
                          "cgsnapshots")
예제 #18
0
    def list(self, detailed=True, search_opts=None):
        """Lists all groups.

        :rtype: list of :class:`Group`
        """
        query_string = utils.build_query_param(search_opts)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/groups%s%s" % (detail, query_string),
                          "groups")
    def list(self, detailed=True, search_opts=None):
        """
        Get a list of all snapshots.

        :rtype: list of :class:`Snapshot`
        """
        query_string = utils.build_query_param(search_opts, sort=True)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/snapshots%s%s" % (detail, query_string),
                          "snapshots")
    def list(self, detailed=True, search_opts=None):
        """
        Get a list of all snapshots.

        :rtype: list of :class:`Snapshot`
        """
        query_string = utils.build_query_param(search_opts, True)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/snapshots%s%s" % (detail, query_string),
                          "snapshots")
예제 #21
0
    def list(self, detailed=True, search_opts=None):
        """Lists all group snapshots.

        :param detailed: list detailed info or not
        :param search_opts: search options
        :rtype: list of :class:`GroupSnapshot`
        """
        query_string = utils.build_query_param(search_opts)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/group_snapshots%s%s" % (detail, query_string),
                          "group_snapshots")
예제 #22
0
    def list(self, detailed=True, search_opts=None, list_volume=False):
        """Lists all groups.

        :rtype: list of :class:`Group`
        """
        if list_volume:
            if not search_opts:
                search_opts = {}
            search_opts['list_volume'] = True
        query_string = utils.build_query_param(search_opts)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/groups%s%s" % (detail, query_string), "groups")
예제 #23
0
    def _build_list_url(self, resource_type, detailed=True, search_opts=None,
                        marker=None, limit=None, sort_key=None, sort_dir=None,
                        sort=None, offset=None):

        if search_opts is None:
            search_opts = {}

        query_params = {}
        for key, val in search_opts.items():
            if val:
                query_params[key] = val

        if marker:
            query_params['marker'] = marker

        if limit:
            query_params['limit'] = limit

        if sort:
            query_params['sort'] = self._format_sort_param(sort,
                                                           resource_type)
        else:
            # sort_key and sort_dir deprecated in kilo, prefer sort
            if sort_key:
                query_params['sort_key'] = self._format_sort_key_param(
                    sort_key,
                    resource_type)

            if sort_dir:
                query_params['sort_dir'] = self._format_sort_dir_param(
                    sort_dir)

        if offset:
            query_params['offset'] = offset
        query_params = utils.unicode_key_value_to_string(query_params)
        # Transform the dict to a sequence of two-element tuples in fixed
        # order, then the encoded string will be consistent in Python 2&3.

        query_string = utils.build_query_param(query_params, sort=True)

        detail = ""
        if detailed:
            detail = "/detail"

        return ("/%(resource_type)s%(detail)s%(query_string)s" %
                {"resource_type": resource_type, "detail": detail,
                 "query_string": query_string})
예제 #24
0
    def list(self, detailed=True, search_opts=None, list_volume=False):
        """Lists all groups.

        :rtype: list of :class:`Group`
        """
        if list_volume:
            if not search_opts:
                search_opts = {}
            search_opts['list_volume'] = True
        query_string = utils.build_query_param(search_opts, sort=True)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/groups%s%s" % (detail, query_string),
                          "groups")
    def list(self, detailed=True, search_opts=None):
        """Get a list of all volume transfer.

        :param detailed: Get detailed object information.
        :param search_opts: Filtering options.
        :rtype: list of :class:`VolumeTransfer`
        """
        query_string = utils.build_query_param(search_opts)

        detail = ""
        if detailed:
            detail = "/detail"

        if self.api_version.matches('3.55'):
            return self._list("/volume-transfers%s%s" % (detail, query_string),
                              "transfers")

        return self._list("/os-volume-transfer%s%s" % (detail, query_string),
                          "transfers")
예제 #26
0
    def list(self, detailed=True, search_opts=None):
        """Get a list of all volume transfer.

        :param detailed: Get detailed object information.
        :param search_opts: Filtering options.
        :rtype: list of :class:`VolumeTransfer`
        """
        query_string = utils.build_query_param(search_opts)

        detail = ""
        if detailed:
            detail = "/detail"

        if self.api_version.matches('3.55'):
            return self._list("/volume-transfers%s%s" % (detail, query_string),
                              "transfers")

        return self._list("/os-volume-transfer%s%s" % (detail, query_string),
                          "transfers")
예제 #27
0
    def list(self, detailed=True, search_opts=None, limit=None):
        """
        Get a list of all volumes.

        :rtype: list of :class:`Volume`
        """
        if search_opts is None:
            search_opts = {}

        if limit:
            search_opts['limit'] = limit

        query_string = utils.build_query_param(search_opts, True)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/volumes%s%s" % (detail, query_string), "volumes")
예제 #28
0
    def list(self, detailed=True, search_opts=None, limit=None):
        """
        Get a list of all volumes.

        :rtype: list of :class:`Volume`
        """
        if search_opts is None:
            search_opts = {}

        if limit:
            search_opts['limit'] = limit

        query_string = utils.build_query_param(search_opts, True)

        detail = ""
        if detailed:
            detail = "/detail"

        return self._list("/volumes%s%s" % (detail, query_string),
                          "volumes")
예제 #29
0
    def find(self, base_url=None, **kwargs):
        """Find a single item with attributes matching ``**kwargs``.

        :param base_url: if provided, the generated URL will be appended to it
        """
        kwargs = self._filter_kwargs(kwargs)

        rl = self._list(
            '%(base_url)s%(query)s' % {
                'base_url': self.build_url(base_url=base_url, **kwargs),
                'query': '?%s' % utils.build_query_param(kwargs),
            }, self.collection_key)
        num = len(rl)

        if num == 0:
            msg = "No %s matching %s." % (self.resource_class.__name__, kwargs)
            raise exceptions.NotFound(404, msg)
        elif num > 1:
            raise exceptions.NoUniqueMatch
        else:
            return rl[0]
예제 #30
0
    def find(self, base_url=None, **kwargs):
        """Find a single item with attributes matching ``**kwargs``.

        :param base_url: if provided, the generated URL will be appended to it
        """
        kwargs = self._filter_kwargs(kwargs)

        rl = self._list(
            '%(base_url)s%(query)s' % {
                'base_url': self.build_url(base_url=base_url, **kwargs),
                'query': '?%s' % utils.build_query_param(kwargs),
            },
            self.collection_key)
        num = len(rl)

        if num == 0:
            msg = "No %s matching %s." % (self.resource_class.__name__, kwargs)
            raise exceptions.NotFound(404, msg)
        elif num > 1:
            raise exceptions.NoUniqueMatch
        else:
            return rl[0]