Пример #1
0
 def test_unicode_key_value_to_string(self):
     src = {u'key': u'\u70fd\u7231\u5a77'}
     expected = {'key': '\xe7\x83\xbd\xe7\x88\xb1\xe5\xa9\xb7'}
     if six.PY2:
         self.assertEqual(expected, utils.unicode_key_value_to_string(src))
     else:
         # u'xxxx' in PY3 is str, we will not get extra 'u' from cli
         # output in PY3
         self.assertEqual(src, utils.unicode_key_value_to_string(src))
Пример #2
0
 def test_unicode_key_value_to_string(self):
     src = {u'key': u'\u70fd\u7231\u5a77'}
     expected = {'key': '\xe7\x83\xbd\xe7\x88\xb1\xe5\xa9\xb7'}
     if six.PY2:
         self.assertEqual(expected, utils.unicode_key_value_to_string(src))
     else:
         # u'xxxx' in PY3 is str, we will not get extra 'u' from cli
         # output in PY3
         self.assertEqual(src, utils.unicode_key_value_to_string(src))
Пример #3
0
 def _build_query_string(self, search_opts):
     search_opts = search_opts or {}
     search_opts = utils.unicode_key_value_to_string(search_opts)
     params = sorted(
         [(k, v) for (k, v) in search_opts.items() if v])
     query_string = "?%s" % utils.safe_urlencode(params) if params else ''
     return query_string
    def list(self, detailed=True, search_opts=None, sort_key=None,
             sort_dir=None):
        """Get a list of snapshots of shares.

        :param search_opts: Search options to filter out shares.
        :param sort_key: Key to be sorted.
        :param sort_dir: Sort direction, should be 'desc' or 'asc'.
        :rtype: list of :class:`ShareSnapshot`
        """
        if search_opts is None:
            search_opts = {}

        if sort_key is not None:
            if sort_key in constants.SNAPSHOT_SORT_KEY_VALUES:
                search_opts['sort_key'] = sort_key
            else:
                raise ValueError(
                    'sort_key must be one of the following: %s.'
                    % ', '.join(constants.SNAPSHOT_SORT_KEY_VALUES))

        if sort_dir is not None:
            if sort_dir in constants.SORT_DIR_VALUES:
                search_opts['sort_dir'] = sort_dir
            else:
                raise ValueError(
                    'sort_dir must be one of the following: %s.'
                    % ', '.join(constants.SORT_DIR_VALUES))

        query_string = ""
        if search_opts:
            search_opts = utils.unicode_key_value_to_string(search_opts)
            params = sorted(
                [(k, v) for (k, v) in list(search_opts.items()) if v])
            if params:
                query_string = "?%s" % parse.urlencode(params)

        if detailed:
            path = "/snapshots/detail%s" % (query_string,)
        else:
            path = "/snapshots%s" % (query_string,)

        return self._list(path, 'snapshots')
    def list(self, detailed=True, search_opts=None):
        """Get a list of all share network.

        :rtype: list of :class:`NetworkInfo`
        """
        if not search_opts:
            search_opts = {}

        query_string = ""
        if search_opts:
            search_opts = utils.unicode_key_value_to_string(search_opts)
            params = sorted(
                [(k, v) for (k, v) in list(search_opts.items()) if v])
            if params:
                query_string = "?%s" % parse.urlencode(params)

        if detailed:
            path = RESOURCES_PATH + "/detail" + query_string
        else:
            path = RESOURCES_PATH + query_string

        return self._list(path, RESOURCES_NAME)
Пример #6
0
    def do_list(self,
                detailed=True,
                search_opts=None,
                sort_key=None,
                sort_dir=None):
        """Get a list of all shares.

        :param detailed: Whether to return detailed share info or not.
        :param search_opts: dict with search options to filter out shares.
            available keys are below (('name1', 'name2', ...), 'type'):
            - ('all_tenants', int)
            - ('is_public', bool)
            - ('metadata', dict)
            - ('extra_specs', dict)
            - ('limit', int)
            - ('offset', int)
            - ('name', text)
            - ('status', text)
            - ('host', text)
            - ('share_server_id', text)
            - (('share_network_id', 'share_network'), text)
            - (('share_type_id', 'share_type'), text)
            - (('snapshot_id', 'snapshot'), text)
            Note, that member context will have restricted set of
            available search opts. For admin context filtering also available
            by each share attr from its Model. So, this list is not full for
            admin context.
        :param sort_key: Key to be sorted (i.e. 'created_at' or 'status').
        :param sort_dir: Sort direction, should be 'desc' or 'asc'.
        :rtype: list of :class:`Share`
        """
        if search_opts is None:
            search_opts = {}

        if sort_key is not None:
            if sort_key in constants.SHARE_SORT_KEY_VALUES:
                search_opts['sort_key'] = sort_key
                # NOTE(vponomaryov): Replace aliases with appropriate keys
                if sort_key == 'share_type':
                    search_opts['sort_key'] = 'share_type_id'
                elif sort_key == 'snapshot':
                    search_opts['sort_key'] = 'snapshot_id'
                elif sort_key == 'share_network':
                    search_opts['sort_key'] = 'share_network_id'
            else:
                raise ValueError('sort_key must be one of the following: %s.' %
                                 ', '.join(constants.SHARE_SORT_KEY_VALUES))

        if sort_dir is not None:
            if sort_dir in constants.SORT_DIR_VALUES:
                search_opts['sort_dir'] = sort_dir
            else:
                raise ValueError('sort_dir must be one of the following: %s.' %
                                 ', '.join(constants.SORT_DIR_VALUES))

        if 'is_public' not in search_opts:
            search_opts['is_public'] = True

        export_location = search_opts.pop('export_location', None)
        if export_location:
            if uuidutils.is_uuid_like(export_location):
                search_opts['export_location_id'] = export_location
            else:
                search_opts['export_location_path'] = export_location

        query_string = ""
        if search_opts:
            search_opts = utils.unicode_key_value_to_string(search_opts)
            params = sorted([(k, v) for (k, v) in list(search_opts.items())
                             if v])
            if params:
                query_string = "?%s" % parse.urlencode(params)

        if detailed:
            path = "/shares/detail%s" % (query_string, )
        else:
            path = "/shares%s" % (query_string, )

        return self._list(path, 'shares')
Пример #7
0
 def _build_query_string(self, search_opts):
     search_opts = search_opts or {}
     search_opts = utils.unicode_key_value_to_string(search_opts)
     params = sorted([(k, v) for (k, v) in search_opts.items() if v])
     query_string = "?%s" % utils.safe_urlencode(params) if params else ''
     return query_string