当前位置: 首页>>代码示例>>Python>>正文


Python RingBuilder.save方法代码示例

本文整理汇总了Python中swift.common.ring.RingBuilder.save方法的典型用法代码示例。如果您正苦于以下问题:Python RingBuilder.save方法的具体用法?Python RingBuilder.save怎么用?Python RingBuilder.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swift.common.ring.RingBuilder的用法示例。


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

示例1: create_sample_ring

# 需要导入模块: from swift.common.ring import RingBuilder [as 别名]
# 或者: from swift.common.ring.RingBuilder import save [as 别名]
    def create_sample_ring(self):
        """ Create a sample ring with two devices

        At least two devices are needed to test removing
        a device, since removing the last device of a ring
        is not allowed """

        # Ensure there is no existing test builder file because
        # create_sample_ring() might be used more than once in a single test
        try:
            os.remove(self.tmpfile)
        except OSError:
            pass

        ring = RingBuilder(6, 3, 1)
        ring.add_dev({'weight': 100.0,
                      'region': 0,
                      'zone': 0,
                      'ip': '127.0.0.1',
                      'port': 6000,
                      'device': 'sda1',
                      'meta': 'some meta data',
                      })
        ring.add_dev({'weight': 100.0,
                      'region': 1,
                      'zone': 1,
                      'ip': '127.0.0.2',
                      'port': 6001,
                      'device': 'sda2'
                      })
        ring.save(self.tmpfile)
开发者ID:steveruckdashel,项目名称:swift,代码行数:33,代码来源:test_ringbuilder.py

示例2: create

# 需要导入模块: from swift.common.ring import RingBuilder [as 别名]
# 或者: from swift.common.ring.RingBuilder import save [as 别名]
    def create():
        """
swift-ring-builder <builder_file> create <part_power> <replicas>
                                         <min_part_hours>
    Creates <builder_file> with 2^<part_power> partitions and <replicas>.
    <min_part_hours> is number of hours to restrict moving a partition more
    than once.
        """
        if len(argv) < 6:
            print(Commands.create.__doc__.strip())
            exit(EXIT_ERROR)
        # 1、生成RingBuilder对象实例
        builder = RingBuilder(int(argv[3]), float(argv[4]), int(argv[5]))

        # 2、创建备份目录
        backup_dir = pathjoin(dirname(builder_file), 'backups')
        try:
            mkdir(backup_dir)
        except OSError as err:
            if err.errno != EEXIST:
                raise

        # 3、保存原始数据到备份目录,以及/etc/swift目录中
        builder.save(pathjoin(backup_dir,
                              '%d.' % time() + basename(builder_file)))
        builder.save(builder_file)
        exit(EXIT_SUCCESS)
开发者ID:revoer,项目名称:keystone-8.0.0,代码行数:29,代码来源:ringbuilder.py

示例3: create

# 需要导入模块: from swift.common.ring import RingBuilder [as 别名]
# 或者: from swift.common.ring.RingBuilder import save [as 别名]
    def create():
        """
swift-ring-builder <builder_file> create <part_power> <replicas>
                                         <min_part_hours>
    Creates <builder_file> with 2^<part_power> partitions and <replicas>.
    <min_part_hours> is number of hours to restrict moving a partition more
    than once.
OR
swift-ring-builder <builder_file> create <part_power> <replicas>
                                         <min_part_hours> <policy_info_file>
    policy_info_file contains the information about the policy
        """
        if len(argv) < 6:
            print Commands.create.__doc__.strip()
            exit(EXIT_ERROR)
        if len (argv) > 6:
            builder = RingBuilder(int(argv[3]), float(argv[4]), int(argv[5]), argv[6])
        else:
            builder = RingBuilder(int(argv[3]), float(argv[4]), int(argv[5]))
        backup_dir = pathjoin(dirname(argv[1]), 'backups')
        try:
            mkdir(backup_dir)
        except OSError as err:
            if err.errno != EEXIST:
                raise
        builder.save(pathjoin(backup_dir, '%d.' % time() + basename(argv[1])))
        builder.save(argv[1])
        exit(EXIT_SUCCESS)
开发者ID:sagarjha,项目名称:swift,代码行数:30,代码来源:ringbuilder.py

示例4: create_sample_ring

# 需要导入模块: from swift.common.ring import RingBuilder [as 别名]
# 或者: from swift.common.ring.RingBuilder import save [as 别名]
    def create_sample_ring(self):
        """ Create a sample ring with two devices

        At least two devices are needed to test removing
        a device, since removing the last device of a ring
        is not allowed """

        # Ensure there is no existing test builder file because
        # create_sample_ring() might be used more than once in a single test
        try:
            os.remove(self.tmpfile)
        except OSError:
            pass

        ring = RingBuilder(6, 3, 1)
        ring.add_dev(
            {
                "weight": 100.0,
                "region": 0,
                "zone": 0,
                "ip": "127.0.0.1",
                "port": 6000,
                "device": "sda1",
                "meta": "some meta data",
            }
        )
        ring.add_dev({"weight": 100.0, "region": 1, "zone": 1, "ip": "127.0.0.2", "port": 6001, "device": "sda2"})
        ring.save(self.tmpfile)
开发者ID:heemanshu,项目名称:swift_juno,代码行数:30,代码来源:test_ringbuilder.py

示例5: storage_policies

# 需要导入模块: from swift.common.ring import RingBuilder [as 别名]
# 或者: from swift.common.ring.RingBuilder import save [as 别名]
def storage_policies(request):
    """
    Creates a storage policy to swift with an specific ring.
    Allows create replication storage policies and erasure code storage policies
    """

    if request.method == "GET":
        try:
            r = get_redis_connection()
        except RedisError:
            return JSONResponse('Error connecting with DB', status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        keys = r.keys("storage-policy:*")
        storage_policy_list = []
        for key in keys:
            storage_policy = r.hgetall(key)
            to_json_bools(storage_policy, 'deprecated', 'default', 'deployed')
            storage_policy['id'] = str(key).split(':')[-1]
            storage_policy['devices'] = json.loads(storage_policy['devices'])
            storage_policy_list.append(storage_policy)
        return JSONResponse(storage_policy_list, status=status.HTTP_200_OK)

    if request.method == "POST":
        try:
            r = get_redis_connection()
        except RedisError:
            return JSONResponse('Error connecting with DB', status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        data = JSONParser().parse(request)

        if data['policy_type'] == 'EC':
            data['replicas'] = int(data['ec_num_data_fragments']) + int(data['ec_num_parity_fragments'])

        try:
            sp_id = str(r.incr('storage-policies:id'))
            key = 'storage-policy:' + sp_id

            ring = RingBuilder(int(data['partition_power']), int(data['replicas']), int(data['time']))
            ring.save(get_policy_file_path(settings.SWIFT_CFG_TMP_DIR, sp_id))

            r.hmset(key, data)
        except:
            return JSONResponse('Error creating the Storage Policy', status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        return JSONResponse('Account created successfully', status=status.HTTP_201_CREATED)

    return JSONResponse('Only HTTP POST requests allowed.', status=status.HTTP_405_METHOD_NOT_ALLOWED)
开发者ID:Crystal-SDS,项目名称:Crystal-Controller,代码行数:49,代码来源:views.py

示例6: write_ring

# 需要导入模块: from swift.common.ring import RingBuilder [as 别名]
# 或者: from swift.common.ring.RingBuilder import save [as 别名]
def write_ring(args, devices, builderfile):
    # Make an educated guess about the used port. These are the defaults for
    # TripleO-based deployments in Mitaka
    builder_fname = os.path.basename(builderfile)
    if 'account' in builder_fname:
        port = 6002
    elif 'container' in builder_fname:
        port = 6001
    elif 'object' in builder_fname:
        port = 6000
    else:
        port = 6000

    logging.debug('Set port for new devices to %d' % port)

    if not os.path.isfile(builderfile):
        logging.info(
            '%s not found, creating new builder file', builderfile)
        rb = RingBuilder(args.part_power, args.replicas, args.min_part_hours)
    else:
        logging.info('Using existing builder file %s', builderfile)
        rb = RingBuilder.load(builderfile)

    # Add all missing devices
    for dev in devices:
        _dev = rb.search_devs({'meta': dev['meta']})
        if not _dev:
            dev['weight'] = float(dev.get('size')) / 10**9
            dev['region'] = 1
            dev['zone'] = 1
            dev['port'] = port
            dev['replication_ip'] = dev['ip']
            dev['replication_port'] = dev['port']
            rb.add_dev(dev)
            logging.info('Added device %s / %s', dev['ip'], dev['device'])
        else:
            logging.info(
                'Ignoring existing device %s / %s', dev['ip'], dev['device'])
    try:
        rb.rebalance()
    except RingValidationError as exc:
        logging.error(exc)
    rb.save(builderfile)
    ring_file = os.path.splitext(builderfile)[0] + '.ring.gz'
    ring_data = rb.get_ring()
    ring_data.save(ring_file)
    return [builderfile, ring_file]
开发者ID:cschwede,项目名称:tripleo-swift-ring-tool,代码行数:49,代码来源:tripleo_swift_ring_tool.py

示例7: write_builder

# 需要导入模块: from swift.common.ring import RingBuilder [as 别名]
# 或者: from swift.common.ring.RingBuilder import save [as 别名]
    def write_builder():
        """
swift-ring-builder <ring_file> write_builder [min_part_hours]
    Recreate a builder from a ring file (lossy) if you lost your builder
    backups.  (Protip: don't lose your builder backups).
    [min_part_hours] is one of those numbers lost to the builder,
    you can change it with set_min_part_hours.
        """
        if exists(builder_file):
            print 'Cowardly refusing to overwrite existing ' \
                'Ring Builder file: %s' % builder_file
            exit(EXIT_ERROR)
        if len(argv) > 3:
            min_part_hours = int(argv[3])
        else:
            stderr.write("WARNING: default min_part_hours may not match "
                         "the value in the lost builder.\n")
            min_part_hours = 24
        ring = Ring(ring_file)
        for dev in ring.devs:
            dev.update({
                'parts': 0,
                'parts_wanted': 0,
            })
        builder_dict = {
            'part_power': 32 - ring._part_shift,
            'replicas': float(ring.replica_count),
            'min_part_hours': min_part_hours,
            'parts': ring.partition_count,
            'devs': ring.devs,
            'devs_changed': False,
            'version': 0,
            '_replica2part2dev': ring._replica2part2dev_id,
            '_last_part_moves_epoch': None,
            '_last_part_moves': None,
            '_last_part_gather_start': 0,
            '_remove_devs': [],
        }
        builder = RingBuilder(1, 1, 1)
        builder.copy_from(builder_dict)
        for parts in builder._replica2part2dev:
            for dev_id in parts:
                builder.devs[dev_id]['parts'] += 1
        builder._set_parts_wanted()
        builder.save(builder_file)
开发者ID:701,项目名称:swift,代码行数:47,代码来源:ringbuilder.py

示例8: remake_rings

# 需要导入模块: from swift.common.ring import RingBuilder [as 别名]
# 或者: from swift.common.ring.RingBuilder import save [as 别名]
def remake_rings(partpower=16, weight=100, replicas=3, min_part_hours=1, drives=False):
    for service in ['object', 'container', 'account']:
        builder_file = '/etc/swift/%s.builder' % service
        ring_file = '/etc/swift/%s.ring.gz' % service
        try:
            os.remove(builder_file)
            os.remove(ring_file)
        except OSError:
            pass
        builder = RingBuilder(partpower, replicas, min_part_hours)
        builder.save(builder_file)
        devstrs = _get_builder_strings(service, drives)
        for devstr in devstrs:
            new_dev = _parse_add_values(devstr, str(weight))
            builder.add_dev(new_dev[0])
        builder.save(builder_file)
        builder.rebalance(builder_file)
        builder.get_ring().save(ring_file)
开发者ID:ahale,项目名称:salt-playground,代码行数:20,代码来源:swiftutils.py

示例9: write_stub_builder

# 需要导入模块: from swift.common.ring import RingBuilder [as 别名]
# 或者: from swift.common.ring.RingBuilder import save [as 别名]
def write_stub_builder(tmpdir, region=1, name=''):
    """
    Pretty much just a three node, three replica, 8 part power builder...

    :param tmpdir: a place to write the builder, be sure to clean it up!
    :param region: an integer, fills in region and ip
    :param name: the name of the builder (i.e. <name>.builder)
    """
    name = name or str(region)
    replicas = 3
    builder = RingBuilder(8, replicas, 1)
    for i in range(replicas):
        dev = {'weight': 100,
               'region': '%d' % region,
               'zone': '1',
               'ip': '10.0.0.%d' % region,
               'port': '3600',
               'device': 'sdb%d' % i}
        builder.add_dev(dev)
    builder.rebalance()
    builder_file = os.path.join(tmpdir, '%s.builder' % name)
    builder.save(builder_file)
    return builder, builder_file
开发者ID:mahak,项目名称:swift,代码行数:25,代码来源:__init__.py


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