예제 #1
0
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)
예제 #2
0
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)
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]
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]