示例#1
0
def main():
    import argparse
    parser = argparse.ArgumentParser(description="dump beansdb data content",
                                     prefix_chars="-")

    parser.add_argument('cluster', choices=['db256', 'fs', 'test'])

    subparsers = parser.add_subparsers(dest="cmd", help='all commands')

    # route
    parser_route = subparsers.add_parser('route', help='get/set route')

    parser_route.add_argument('--set-version', type=int, help="set curr version")

    parser_route.add_argument('--set', help="set file $set to zk")

    parser_route.add_argument('--get', help="get config from zk to $get, use with --ver")
    parser_route.add_argument('--ver', type=int, default=-1, help="ver to fetch")

    parser_route.add_argument('--state', action='store_true', help="fetch config from zk to $fetch")
    parser_route.add_argument('--reload', help='reload route')

    # route diff
    parser_diff = subparsers.add_parser('diff', help='')

    parser_diff.add_argument('start', type=int, help="")
    parser_diff.add_argument('end', type=int, help="")
    # parser_diff.add_argument('--seq', action="store_true", help="")

    args = parser.parse_args()

    zk = ZK(args.cluster)

    cmd = args.cmd
    if cmd == "route":
        if args.get:
            data = zk.route_get(args.ver)
            dump_file(data, args.get)
            print "save ver %d to %s" % (args.ver, args.get)
        elif args.set:
            data = open(args.set).read()
            zk.route_set(data)
        elif args.state:
            pass
        elif args.set_version:
            zk.route_version_set(args.set_version)
        elif args.reload:
            force_reload_route(args.cluster)
    elif cmd == "diff":
        # zk.route_verison_get_all()
        vers = [args.start, args.end]
        routes = [((Route.from_yaml(zk.route_get(ver))), ver) for ver in vers]
        for i, (r, v) in enumerate(routes[:-1]):
            print routes[i+1][1], '-', v, ':', routes[i+1][0].diff(r)

    print print_route_state(zk)
示例#2
0
def update_zk_from_file(cluster, path):
    zk = ZK(cluster)
    with open(path, 'r') as f:
        table = yaml.load(f)
        return zk.route_set(yaml.dump(table))