示例#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)
    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]