Exemplo n.º 1
0
def add_action(url, args):
    action_creator = ActionCreator(url)
    action_creator.add(args)
    url = action_creator.get_url()
    encoded_query = action_creator.get_encoded_query()
    return {"url": url, "postproc": open_url_and_show_response,
            "encoded_query": encoded_query}
Exemplo n.º 2
0
def add_action(url, args):
    action_creator = ActionCreator(url)
    action_creator.add(args)
    url = action_creator.get_url()
    encoded_query = action_creator.get_encoded_query()
    return {"url": url, "postproc": open_url_and_show_response,
            "encoded_query": encoded_query}
Exemplo n.º 3
0
def main(arg_list=None, exec_postproc=True):
    parser = argparse.ArgumentParser(description="Hatohol Voyager")
    parser.add_argument("--server", type=parse_server_arg, dest="server_url",
                        metavar="SERVER[:PORT]",
                        default="%s:%d" % (DEFAULT_SERVER, DEFAULT_PORT))
    subparsers = parser.add_subparsers(help="Sub commands", dest="sub_command")

    # test
    sub_server = subparsers.add_parser("test")

    # login
    sub_server = subparsers.add_parser("login")
    sub_server.add_argument("user", type=str)
    sub_server.add_argument("password", type=str)

    # logout
    sub_server = subparsers.add_parser("logout")

    # server
    sub_server = subparsers.add_parser("show-server")
    sub_server.add_argument("server_id", type=int, nargs="?",
                            help="get a server only with server ID")
    # trigger
    sub_trigger = subparsers.add_parser("show-trigger")
    sub_trigger.add_argument("server_id", type=int, nargs="?")
    sub_trigger.add_argument("host_id", type=int, nargs="?")
    sub_trigger.add_argument("trigger_id", type=int, nargs="?")

    # event
    sub_event = subparsers.add_parser("show-event")
    sub_event.add_argument("--sort", choices=["asc", "desc"])
    sub_event.add_argument("-n", "--max-number", type=int)
    sub_event.add_argument("--start-id", type=int)

    # item
    sub_item = subparsers.add_parser("show-item")

    # host
    sub_host = subparsers.add_parser("show-host")
    sub_host.add_argument("server_id", type=int, nargs="?")
    sub_host.add_argument("host_id", type=int, nargs="?")

    # action
    sub_action = subparsers.add_parser("show-action")

    # action (add)
    sub_action = subparsers.add_parser("add-action")
    ActionCreator.setup_arguments(sub_action)

    # action (delete)
    sub_action = subparsers.add_parser("del-action")
    sub_action.add_argument("action_id")

    # user (show)
    sub_action = subparsers.add_parser("show-user")

    # user (add)
    sub_user = subparsers.add_parser("add-user")
    UserCreator.setup_arguments(sub_user)

    # user (delete)
    sub_user = subparsers.add_parser("del-user")
    sub_user.add_argument("user_id")

    # server-conn-stat
    sub_svconnstat = subparsers.add_parser("server-conn-stat")

    args = parser.parse_args(arg_list)
    cmd_ctx = command_map[args.sub_command](args.server_url, args)
    if not exec_postproc:
        return cmd_ctx
    cmd_ctx["postproc"](cmd_ctx)
Exemplo n.º 4
0
def main(arg_list=None, exec_postproc=True):
    parser = argparse.ArgumentParser(description="Hatohol Voyager")
    parser.add_argument("--server", type=parse_server_arg, dest="server_url",
                        metavar="SERVER[:PORT]",
                        default="%s:%d" % (DEFAULT_SERVER, DEFAULT_PORT))
    subparsers = parser.add_subparsers(help="Sub commands", dest="sub_command")

    # test
    sub_server = subparsers.add_parser("test")

    # login
    sub_server = subparsers.add_parser("login")
    sub_server.add_argument("user", type=str)
    sub_server.add_argument("password", type=str)

    # logout
    sub_server = subparsers.add_parser("logout")

    # server
    sub_server = subparsers.add_parser("show-server")
    sub_server.add_argument("server_id", type=int, nargs="?",
                            help="get a server only with server ID")
    # trigger
    sub_trigger = subparsers.add_parser("show-trigger")
    sub_trigger.add_argument("server_id", type=int, nargs="?")
    sub_trigger.add_argument("host_id", type=int, nargs="?")
    sub_trigger.add_argument("trigger_id", type=int, nargs="?")

    # event
    sub_event = subparsers.add_parser("show-event")
    sub_event.add_argument("--sort", choices=["asc", "desc"])
    sub_event.add_argument("-n", "--max-number", type=int)
    sub_event.add_argument("--start-id", type=int)

    # item
    sub_item = subparsers.add_parser("show-item")

    # host
    sub_host = subparsers.add_parser("show-host")
    sub_host.add_argument("server_id", type=int, nargs="?")
    sub_host.add_argument("host_id", type=int, nargs="?")

    # action
    sub_action = subparsers.add_parser("show-action")

    # action (add)
    sub_action = subparsers.add_parser("add-action")
    ActionCreator.setup_arguments(sub_action)

    # action (delete)
    sub_action = subparsers.add_parser("del-action")
    sub_action.add_argument("action_id")

    # user (show)
    sub_action = subparsers.add_parser("show-user")

    # user (add)
    sub_user = subparsers.add_parser("add-user")
    UserCreator.setup_arguments(sub_user)

    # user (delete)
    sub_user = subparsers.add_parser("del-user")
    sub_user.add_argument("user_id")

    # server-conn-stat
    sub_svconnstat = subparsers.add_parser("server-conn-stat")

    args = parser.parse_args(arg_list)
    cmd_ctx = command_map[args.sub_command](args.server_url, args)
    if not exec_postproc:
        return cmd_ctx
    cmd_ctx["postproc"](cmd_ctx)