'swift-ring-builder <builder_file> search <search-value>
or
swift-ring-builder <builder_file> search
--region <region> --zone <zone> --ip <ip or hostname> --port <port>
--replication-ip <r_ip or r_hostname> --replication-port <r_port>
--device <device_name> --meta <meta> --weight <weight>
Where <r_ip>, <r_hostname> and <r_port> are replication ip, hostname
and port.
Any of the options are optional in both cases.
Shows information about matching devices.'

@staticmethod
def search():

    if (len(argv) < 4):
        print(Commands.search.__doc__.strip())
        print()
        print(parse_search_value.__doc__.strip())
        exit(EXIT_ERROR)
    devs = builder.search_devs(_parse_search_values(argv[3:]))
    if (not devs):
        print('No    matching    devices    found')
        exit(EXIT_ERROR)
    print('Devices:                id        region        zone                        ip    address        port        replication    ip        replication    port                        name    weight    partitions    balance    meta')
    weighted_parts = ((builder.parts * builder.replicas) / sum((d['weight'] for d in builder.devs if (d is not None))))
    for dev in devs:
        if (not dev['weight']):
            if dev['parts']:
                balance = MAX_BALANCE
            else:
                balance = 0
        else:
            balance = (((100.0 * dev['parts']) / (dev['weight'] * weighted_parts)) - 100.0)
        print(('                                    %5d    %7d    %5d    %15s    %5d    %15s    %17d    %9s    %6.02f    %10s    %7.02f    %s' % (dev['id'], dev['region'], dev['zone'], dev['ip'], dev['port'], dev['replication_ip'], dev['replication_port'], dev['device'], dev['weight'], dev['parts'], balance, dev['meta'])))
    exit(EXIT_SUCCESS)
