• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.validate_args函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中swift.common.ring.utils.validate_args函数的典型用法代码示例。如果您正苦于以下问题:Python validate_args函数的具体用法?Python validate_args怎么用?Python validate_args使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了validate_args函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _parse_remove_values

def _parse_remove_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    try:
        devs = []
        if len(args) > 0:
            if new_cmd_format:
                print(Commands.remove.__doc__.strip())
                exit(EXIT_ERROR)

            for arg in args:
                devs.extend(builder.search_devs(
                    parse_search_value(arg)) or [])
        else:
            devs.extend(builder.search_devs(
                parse_search_values_from_opts(opts)))

        return devs
    except ValueError as e:
        print(e)
        exit(EXIT_ERROR)
开发者ID:BjoernT,项目名称:swift,代码行数:25,代码来源:ringbuilder.py


示例2: _parse_set_weight_values

def _parse_set_weight_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    try:
        devs = []
        if not new_cmd_format:
            if len(args) % 2 != 0:
                print(Commands.set_weight.__doc__.strip())
                exit(EXIT_ERROR)

            devs_and_weights = izip(islice(argvish, 0, len(argvish), 2),
                                    islice(argvish, 1, len(argvish), 2))
            for devstr, weightstr in devs_and_weights:
                devs.extend(builder.search_devs(
                    parse_search_value(devstr)) or [])
                weight = float(weightstr)
                _set_weight_values(devs, weight)
        else:
            if len(args) != 1:
                print(Commands.set_weight.__doc__.strip())
                exit(EXIT_ERROR)

            devs.extend(builder.search_devs(
                parse_search_values_from_opts(opts)) or [])
            weight = float(args[0])
            _set_weight_values(devs, weight)
    except ValueError as e:
        print(e)
        exit(EXIT_ERROR)
开发者ID:BjoernT,项目名称:swift,代码行数:33,代码来源:ringbuilder.py


示例3: test_validate_args

 def test_validate_args(self):
     argv = \
         ["--id", "1", "--region", "2", "--zone", "3",
          "--ip", "test.test.com",
          "--port", "6200",
          "--replication-ip", "r.test.com",
          "--replication-port", "7000",
          "--device", "sda3",
          "--meta", "some meta data",
          "--weight", "3.14159265359",
          "--change-ip", "change.test.test.com",
          "--change-port", "6201",
          "--change-replication-ip", "change.r.test.com",
          "--change-replication-port", "7001",
          "--change-device", "sdb3",
          "--change-meta", "some meta data for change"]
     new_cmd_format, opts, args = validate_args(argv)
     self.assertTrue(new_cmd_format)
     self.assertEqual(opts.id, 1)
     self.assertEqual(opts.region, 2)
     self.assertEqual(opts.zone, 3)
     self.assertEqual(opts.ip, "test.test.com")
     self.assertEqual(opts.port, 6200)
     self.assertEqual(opts.replication_ip, "r.test.com")
     self.assertEqual(opts.replication_port, 7000)
     self.assertEqual(opts.device, "sda3")
     self.assertEqual(opts.meta, "some meta data")
     self.assertEqual(opts.weight, 3.14159265359)
     self.assertEqual(opts.change_ip, "change.test.test.com")
     self.assertEqual(opts.change_port, 6201)
     self.assertEqual(opts.change_replication_ip, "change.r.test.com")
     self.assertEqual(opts.change_replication_port, 7001)
     self.assertEqual(opts.change_device, "sdb3")
     self.assertEqual(opts.change_meta, "some meta data for change")
开发者ID:ISCAS-VDI,项目名称:swift-base,代码行数:34,代码来源:test_utils.py


示例4: _parse_add_values

def _parse_add_values(argvish):
    """
    Parse devices to add as specified on the command line.

    Will exit on error and spew warnings.

    :returns: array of device dicts
    """
    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    parsed_devs = []
    if len(args) > 0:
        if new_cmd_format or len(args) % 2 != 0:
            print(Commands.add.__doc__.strip())
            exit(EXIT_ERROR)

        devs_and_weights = izip(islice(args, 0, len(args), 2),
                                islice(args, 1, len(args), 2))

        for devstr, weightstr in devs_and_weights:
            dev_dict = parse_add_value(devstr)

            if dev_dict['region'] is None:
                stderr.write('WARNING: No region specified for %s. '
                             'Defaulting to region 1.\n' % devstr)
                dev_dict['region'] = 1

            if dev_dict['replication_ip'] is None:
                dev_dict['replication_ip'] = dev_dict['ip']

            if dev_dict['replication_port'] is None:
                dev_dict['replication_port'] = dev_dict['port']

            weight = float(weightstr)
            if weight < 0:
                raise ValueError('Invalid weight value: %s' % devstr)
            dev_dict['weight'] = weight

            parsed_devs.append(dev_dict)
    else:
        parsed_devs.append(build_dev_from_opts(opts))

    return parsed_devs
开发者ID:BjoernT,项目名称:swift,代码行数:46,代码来源:ringbuilder.py


示例5: test_validate_args_new_cmd_format

    def test_validate_args_new_cmd_format(self):
        argv = \
            ["--id", "0", "--region", "0", "--zone", "0",
             "--ip", "",
             "--port", "0",
             "--replication-ip", "",
             "--replication-port", "0",
             "--device", "",
             "--meta", "",
             "--weight", "0",
             "--change-ip", "",
             "--change-port", "0",
             "--change-replication-ip", "",
             "--change-replication-port", "0",
             "--change-device", "",
             "--change-meta", ""]
        new_cmd_format, opts, args = validate_args(argv)
        self.assertTrue(new_cmd_format)

        argv = \
            ["--id", None, "--region", None, "--zone", None,
             "--ip", "",
             "--port", "0",
             "--replication-ip", "",
             "--replication-port", "0",
             "--device", "",
             "--meta", "",
             "--weight", None,
             "--change-ip", "change.test.test.com",
             "--change-port", "6201",
             "--change-replication-ip", "change.r.test.com",
             "--change-replication-port", "7001",
             "--change-device", "sdb3",
             "--change-meta", "some meta data for change"]
        new_cmd_format, opts, args = validate_args(argv)
        self.assertFalse(new_cmd_format)

        argv = \
            ["--id", "0"]
        new_cmd_format, opts, args = validate_args(argv)
        self.assertTrue(new_cmd_format)
        argv = \
            ["--region", "0"]
        new_cmd_format, opts, args = validate_args(argv)
        self.assertTrue(new_cmd_format)
        argv = \
            ["--zone", "0"]
        new_cmd_format, opts, args = validate_args(argv)
        self.assertTrue(new_cmd_format)
        argv = \
            ["--weight", "0"]
        new_cmd_format, opts, args = validate_args(argv)
        self.assertTrue(new_cmd_format)
开发者ID:ISCAS-VDI,项目名称:swift-base,代码行数:53,代码来源:test_utils.py


示例6: _parse_set_info_values

def _parse_set_info_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    if not new_cmd_format:
        if len(args) % 2 != 0:
            print(Commands.search.__doc__.strip())
            exit(EXIT_ERROR)

        searches_and_changes = izip(islice(argvish, 0, len(argvish), 2),
                                    islice(argvish, 1, len(argvish), 2))

        for search_value, change_value in searches_and_changes:
            devs = builder.search_devs(parse_search_value(search_value))
            change = {}

            change_value = calculate_change_value(change_value, change,
                                                  'ip', 'port')

            if change_value.startswith('R'):
                change_value = change_value[1:]
                change_value = calculate_change_value(change_value, change,
                                                      'replication_ip',
                                                      'replication_port')
            if change_value.startswith('/'):
                i = 1
                while i < len(change_value) and change_value[i] != '_':
                    i += 1
                change['device'] = change_value[1:i]
                change_value = change_value[i:]
            if change_value.startswith('_'):
                change['meta'] = change_value[1:]
                change_value = ''
            if change_value or not change:
                raise ValueError('Invalid set info change value: %s' %
                                 repr(argvish[1]))
            _set_info_values(devs, change, opts)
    else:
        devs = builder.search_devs(parse_search_values_from_opts(opts))
        change = parse_change_values_from_opts(opts)
        _set_info_values(devs, change, opts)
开发者ID:bebule,项目名称:swift,代码行数:44,代码来源:ringbuilder.py


示例7: _parse_search_values

def _parse_search_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    try:
        search_values = {}
        if len(args) > 0:
            if new_cmd_format or len(args) != 1:
                print(Commands.search.__doc__.strip())
                exit(EXIT_ERROR)
            search_values = parse_search_value(args[0])
        else:
            search_values = parse_search_values_from_opts(opts)
        return search_values
    except ValueError as e:
        print(e)
        exit(EXIT_ERROR)
开发者ID:BjoernT,项目名称:swift,代码行数:20,代码来源:ringbuilder.py


示例8: _parse_set_info_values

def _parse_set_info_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    if not new_cmd_format:
        if len(args) % 2 != 0:
            print(Commands.search.__doc__.strip())
            exit(EXIT_ERROR)

        searches_and_changes = izip(islice(argvish, 0, len(argvish), 2),
                                    islice(argvish, 1, len(argvish), 2))

        for search_value, change_value in searches_and_changes:
            devs = builder.search_devs(parse_search_value(search_value))
            change = {}
            ip = ''
            if change_value and change_value[0].isdigit():
                i = 1
                while (i < len(change_value) and
                       change_value[i] in '0123456789.'):
                    i += 1
                ip = change_value[:i]
                change_value = change_value[i:]
            elif change_value and change_value.startswith('['):
                i = 1
                while i < len(change_value) and change_value[i] != ']':
                    i += 1
                i += 1
                ip = change_value[:i].lstrip('[').rstrip(']')
                change_value = change_value[i:]
            if ip:
                change['ip'] = validate_and_normalize_ip(ip)
            if change_value.startswith(':'):
                i = 1
                while i < len(change_value) and change_value[i].isdigit():
                    i += 1
                change['port'] = int(change_value[1:i])
                change_value = change_value[i:]
            if change_value.startswith('R'):
                change_value = change_value[1:]
                replication_ip = ''
                if change_value and change_value[0].isdigit():
                    i = 1
                    while (i < len(change_value) and
                           change_value[i] in '0123456789.'):
                        i += 1
                    replication_ip = change_value[:i]
                    change_value = change_value[i:]
                elif change_value and change_value.startswith('['):
                    i = 1
                    while i < len(change_value) and change_value[i] != ']':
                        i += 1
                    i += 1
                    replication_ip = \
                        change_value[:i].lstrip('[').rstrip(']')
                    change_value = change_value[i:]
                if replication_ip:
                    change['replication_ip'] = \
                        validate_and_normalize_ip(replication_ip)
                if change_value.startswith(':'):
                    i = 1
                    while i < len(change_value) and change_value[i].isdigit():
                        i += 1
                    change['replication_port'] = int(change_value[1:i])
                    change_value = change_value[i:]
            if change_value.startswith('/'):
                i = 1
                while i < len(change_value) and change_value[i] != '_':
                    i += 1
                change['device'] = change_value[1:i]
                change_value = change_value[i:]
            if change_value.startswith('_'):
                change['meta'] = change_value[1:]
                change_value = ''
            if change_value or not change:
                raise ValueError('Invalid set info change value: %s' %
                                 repr(argvish[1]))
            _set_info_values(devs, change)
    else:
        devs = builder.search_devs(parse_search_values_from_opts(opts))
        change = parse_change_values_from_opts(opts)
        _set_info_values(devs, change)
开发者ID:BjoernT,项目名称:swift,代码行数:85,代码来源:ringbuilder.py


示例9: test_parse_change_values_from_opts

    def test_parse_change_values_from_opts(self):
        argv = \
            ["--id", "1", "--region", "2", "--zone", "3",
             "--ip", "test.test.com",
             "--port", "6000",
             "--replication-ip", "r.test.com",
             "--replication-port", "7000",
             "--device", "sda3",
             "--meta", "some meta data",
             "--weight", "3.14159265359",
             "--change-ip", "change.test.test.com",
             "--change-port", "6001",
             "--change-replication-ip", "change.r.test.com",
             "--change-replication-port", "7001",
             "--change-device", "sdb3",
             "--change-meta", "some meta data for change"]
        expected = {
            'ip': "change.test.test.com",
            'port': 6001,
            'replication_ip': "change.r.test.com",
            'replication_port': 7001,
            'device': "sdb3",
            'meta': "some meta data for change",
        }
        new_cmd_format, opts, args = validate_args(argv)
        search_values = parse_change_values_from_opts(opts)
        self.assertEquals(search_values, expected)

        argv = \
            ["--id", "1", "--region", "2", "--zone", "3",
             "--ip", "127.0.0.1",
             "--port", "6000",
             "--replication-ip", "127.0.0.10",
             "--replication-port", "7000",
             "--device", "sda3",
             "--meta", "some meta data",
             "--weight", "3.14159265359",
             "--change-ip", "127.0.0.2",
             "--change-port", "6001",
             "--change-replication-ip", "127.0.0.20",
             "--change-replication-port", "7001",
             "--change-device", "sdb3",
             "--change-meta", "some meta data for change"]
        expected = {
            'ip': "127.0.0.2",
            'port': 6001,
            'replication_ip': "127.0.0.20",
            'replication_port': 7001,
            'device': "sdb3",
            'meta': "some meta data for change",
        }
        new_cmd_format, opts, args = validate_args(argv)
        search_values = parse_change_values_from_opts(opts)
        self.assertEquals(search_values, expected)

        argv = \
            ["--id", "1", "--region", "2", "--zone", "3",
             "--ip", "[127.0.0.1]",
             "--port", "6000",
             "--replication-ip", "[127.0.0.10]",
             "--replication-port", "7000",
             "--device", "sda3",
             "--meta", "some meta data",
             "--weight", "3.14159265359",
             "--change-ip", "[127.0.0.2]",
             "--change-port", "6001",
             "--change-replication-ip", "[127.0.0.20]",
             "--change-replication-port", "7001",
             "--change-device", "sdb3",
             "--change-meta", "some meta data for change"]
        new_cmd_format, opts, args = validate_args(argv)
        search_values = parse_change_values_from_opts(opts)
        self.assertEquals(search_values, expected)
开发者ID:bigdig,项目名称:swift,代码行数:73,代码来源:test_utils.py


示例10: _parse_add_values

def _parse_add_values(argvish):
    """
    Parse devices to add as specified on the command line.

    Will exit on error and spew warnings.

    :returns: array of device dicts
    """
    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    parsed_devs = []
    if len(args) > 0:
        if new_cmd_format or len(args) % 2 != 0:
            print Commands.add.__doc__.strip()
            exit(EXIT_ERROR)

        devs_and_weights = izip(islice(args, 0, len(args), 2),
                                islice(args, 1, len(args), 2))

        for devstr, weightstr in devs_and_weights:
            region = 1
            rest = devstr
            if devstr.startswith('r'):
                i = 1
                while i < len(devstr) and devstr[i].isdigit():
                    i += 1
                region = int(devstr[1:i])
                rest = devstr[i:]
            else:
                stderr.write('WARNING: No region specified for %s. '
                             'Defaulting to region 1.\n' % devstr)

            if not rest.startswith('z'):
                raise ValueError('Invalid add value: %s' % devstr)
            i = 1
            while i < len(rest) and rest[i].isdigit():
                i += 1
            zone = int(rest[1:i])
            rest = rest[i:]

            if not rest.startswith('-'):
                raise ValueError('Invalid add value: %s' % devstr)

            ip, port, rest = _parse_address(rest[1:])

            replication_ip = ip
            replication_port = port
            if rest.startswith('R'):
                replication_ip, replication_port, rest =  \
                    _parse_address(rest[1:])
            if not rest.startswith('/'):
                raise ValueError(
                    'Invalid add value: %s' % devstr)
            i = 1
            while i < len(rest) and rest[i] != '_':
                i += 1
            device_name = rest[1:i]
            rest = rest[i:]

            meta = ''
            if rest.startswith('_'):
                meta = rest[1:]

            weight = float(weightstr)

            if weight < 0:
                raise ValueError('Invalid weight value: %s' % devstr)

            parsed_devs.append({'region': region, 'zone': zone, 'ip': ip,
                                'port': port, 'device': device_name,
                                'replication_ip': replication_ip,
                                'replication_port': replication_port,
                                'weight': weight, 'meta': meta})
    else:
        parsed_devs.append(build_dev_from_opts(opts))

    return parsed_devs
开发者ID:gayana06,项目名称:Thesis,代码行数:80,代码来源:ringbuilder.py


示例11: _parse_set_info_values

def _parse_set_info_values(argvish):

    new_cmd_format, opts, args = validate_args(argvish)

    # We'll either parse the all-in-one-string format or the
    # --options format,
    # but not both. If both are specified, raise an error.
    if not new_cmd_format:
        if len(args) % 2 != 0:
            print(Commands.search.__doc__.strip())
            exit(EXIT_ERROR)

        searches_and_changes = izip(islice(argvish, 0, len(argvish), 2), islice(argvish, 1, len(argvish), 2))

        for search_value, change_value in searches_and_changes:
            devs = builder.search_devs(parse_search_value(search_value))
            change = {}
            ip = ""
            if len(change_value) and change_value[0].isdigit():
                i = 1
                while i < len(change_value) and change_value[i] in "0123456789.":
                    i += 1
                ip = change_value[:i]
                change_value = change_value[i:]
            elif len(change_value) and change_value[0] == "[":
                i = 1
                while i < len(change_value) and change_value[i] != "]":
                    i += 1
                i += 1
                ip = change_value[:i].lstrip("[").rstrip("]")
                change_value = change_value[i:]
            if ip:
                change["ip"] = validate_and_normalize_ip(ip)
            if change_value.startswith(":"):
                i = 1
                while i < len(change_value) and change_value[i].isdigit():
                    i += 1
                change["port"] = int(change_value[1:i])
                change_value = change_value[i:]
            if change_value.startswith("R"):
                change_value = change_value[1:]
                replication_ip = ""
                if len(change_value) and change_value[0].isdigit():
                    i = 1
                    while i < len(change_value) and change_value[i] in "0123456789.":
                        i += 1
                    replication_ip = change_value[:i]
                    change_value = change_value[i:]
                elif len(change_value) and change_value[0] == "[":
                    i = 1
                    while i < len(change_value) and change_value[i] != "]":
                        i += 1
                    i += 1
                    replication_ip = change_value[:i].lstrip("[").rstrip("]")
                    change_value = change_value[i:]
                if replication_ip:
                    change["replication_ip"] = validate_and_normalize_ip(replication_ip)
                if change_value.startswith(":"):
                    i = 1
                    while i < len(change_value) and change_value[i].isdigit():
                        i += 1
                    change["replication_port"] = int(change_value[1:i])
                    change_value = change_value[i:]
            if change_value.startswith("/"):
                i = 1
                while i < len(change_value) and change_value[i] != "_":
                    i += 1
                change["device"] = change_value[1:i]
                change_value = change_value[i:]
            if change_value.startswith("_"):
                change["meta"] = change_value[1:]
                change_value = ""
            if change_value or not change:
                raise ValueError("Invalid set info change value: %s" % repr(argvish[1]))
            _set_info_values(devs, change)
    else:
        devs = builder.search_devs(parse_search_values_from_opts(opts))
        change = parse_change_values_from_opts(opts)
        _set_info_values(devs, change)
开发者ID:iloveyou416068,项目名称:swift-1,代码行数:79,代码来源:ringbuilder.py



注:本文中的swift.common.ring.utils.validate_args函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python storage_policy.BindPortsCache类代码示例发布时间:2022-05-27
下一篇:
Python utils.tiers_for_dev函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap