def do_main(args): init_mongoctl_signal_handler() header = """ ------------------------------------------------------------------------------------------- __ _ ___ ___ ___ ____ ____/ /_/ / / ' \/ _ \/ _ \/ _ `/ _ \/ __/ __/ / /_/_/_/\___/_//_/\_, /\___/\__/\__/_/ /___/ ------------------------------------------------------------------------------------------- """ # Parse options parser = get_mongoctl_cmd_parser() if len(args) < 1: print(header) parser.print_help() return # Parse the arguments and call the function of the selected cmd parsed_args = parser.parse_args(args) # turn on verbose if specified if namespace_get_property(parsed_args,"mongoctlVerbose"): turn_logging_verbose_on() # set interactive mode non_interactive = namespace_get_property(parsed_args,'noninteractive') non_interactive = False if non_interactive is None else non_interactive set_interactive_mode(not non_interactive) if not is_interactive_mode(): log_verbose("Running with noninteractive mode") # set global prompt value yes_all = parsed_args.yesToEverything no_all = parsed_args.noToEverything if yes_all and no_all: raise MongoctlException("Cannot have --yes and --no at the same time. " "Please choose either --yes or --no") elif yes_all: say_yes_to_everything() elif no_all: say_no_to_everything() # set the global SSL_OFF flag if parsed_args.clientSslMode: objects.server.set_client_ssl_mode(parsed_args.clientSslMode) # set the global USE_ALT_ADDRESS field if parsed_args.useAltAddress: use_alt_address = parsed_args.useAltAddress log_info("Using alternative address '%s'..." % use_alt_address) objects.server.USE_ALT_ADDRESS = use_alt_address # set conf root if specified if parsed_args.configRoot is not None: config.set_config_root(parsed_args.configRoot) elif os.getenv(CONF_ROOT_ENV_VAR) is not None: config.set_config_root(os.getenv(CONF_ROOT_ENV_VAR)) # set cmd arg servers/clusters if parsed_args.servers or parsed_args.clusters: repository.set_commandline_servers_and_clusters(parsed_args.servers, parsed_args.clusters) # get the function to call from the parser framework command_function = parsed_args.func # parse global login if present username = namespace_get_property(parsed_args, "username") password = namespace_get_property(parsed_args, "password") server_id = namespace_get_property(parsed_args, SERVER_ID_PARAM) parse_global_login_user_arg(username, password, server_id) if server_id is not None: # check if assumeLocal was specified assume_local = namespace_get_property(parsed_args,"assumeLocal") if assume_local: objects.server.assume_local_server(server_id) # execute command log_info("") return command_function(parsed_args)
def do_main(args): init_mongoctl_signal_handler() header = """ ------------------------------------------------------------------------------------------- __ _ ___ ___ ___ ____ ____/ /_/ / / ' \/ _ \/ _ \/ _ `/ _ \/ __/ __/ / /_/_/_/\___/_//_/\_, /\___/\__/\__/_/ /___/ ------------------------------------------------------------------------------------------- """ # Parse options parser = get_mongoctl_cmd_parser() if len(args) < 1: print(header) parser.print_help() return # Parse the arguments and call the function of the selected cmd parsed_args = parser.parse_args(args) # turn on verbose if specified if namespace_get_property(parsed_args, "mongoctlVerbose"): turn_logging_verbose_on() # set interactive mode non_interactive = namespace_get_property(parsed_args, "noninteractive") non_interactive = False if non_interactive is None else non_interactive set_interactive_mode(not non_interactive) if not is_interactive_mode(): log_verbose("Running with noninteractive mode") # set global prompt value yes_all = parsed_args.yesToEverything no_all = parsed_args.noToEverything if yes_all and no_all: raise MongoctlException("Cannot have --yes and --no at the same time. " "Please choose either --yes or --no") elif yes_all: say_yes_to_everything() elif no_all: say_no_to_everything() # set the global SSL_OFF flag if parsed_args.clientSslMode: objects.server.set_client_ssl_mode(parsed_args.clientSslMode) # set the global USE_ALT_ADDRESS field if parsed_args.useAltAddress: use_alt_address = parsed_args.useAltAddress log_info("Using alternative address '%s'..." % use_alt_address) objects.server.USE_ALT_ADDRESS = use_alt_address # set conf root if specified if parsed_args.configRoot is not None: config.set_config_root(parsed_args.configRoot) elif os.getenv(CONF_ROOT_ENV_VAR) is not None: config.set_config_root(os.getenv(CONF_ROOT_ENV_VAR)) # set cmd arg servers/clusters if parsed_args.servers or parsed_args.clusters: repository.set_commandline_servers_and_clusters(parsed_args.servers, parsed_args.clusters) # get the function to call from the parser framework command_function = parsed_args.func # parse global login if present username = namespace_get_property(parsed_args, "username") password = namespace_get_property(parsed_args, "password") server_id = namespace_get_property(parsed_args, SERVER_ID_PARAM) parse_global_login_user_arg(username, password, server_id) if server_id is not None: # check if assumeLocal was specified assume_local = namespace_get_property(parsed_args, "assumeLocal") if assume_local: objects.server.assume_local_server(server_id) # execute command log_info("") return command_function(parsed_args)
def __do_execute(args): header = """ ------------------------------------------------------------------------------------------- __ _ ___ ___ ___ ____ ____/ /_/ / / ' \/ _ \/ _ \/ _ `/ _ \/ __/ __/ / /_/_/_/\___/_//_/\_, /\___/\__/\__/_/ /___/ ------------------------------------------------------------------------------------------- """ global parser if len(args) < 1: print(header) parser.print_help() return # Parse the arguments and call the function of the selected cmd parsed_args = parser.parse_args(args) # turn on verbose if specified if namespace_get_property(parsed_args, "mongoctlVerbose"): turn_logging_verbose_on() # set interactive mode non_interactive = namespace_get_property(parsed_args, 'noninteractive') non_interactive = False if non_interactive is None else non_interactive set_interactive_mode(not non_interactive) if not is_interactive_mode(): log_verbose("Running with noninteractive mode") # set global prompt value yes_all = parsed_args.yesToEverything no_all = parsed_args.noToEverything if yes_all and no_all: raise MongoctlException("Cannot have --yes and --no at the same time. " "Please choose either --yes or --no") elif yes_all: say_yes_to_everything() elif no_all: say_no_to_everything() # set conf root if specified if parsed_args.configRoot is not None: config._set_config_root(parsed_args.configRoot) elif os.getenv(CONF_ROOT_ENV_VAR) is not None: config._set_config_root(os.getenv(CONF_ROOT_ENV_VAR)) # get the function to call from the parser framework command_function = parsed_args.func # parse global login if present username = namespace_get_property(parsed_args, "username") password = namespace_get_property(parsed_args, "password") server_id = namespace_get_property(parsed_args, SERVER_ID_PARAM) parse_global_login_user_arg(username, password, server_id) if server_id is not None: # check if assumeLocal was specified assume_local = namespace_get_property(parsed_args, "assumeLocal") if assume_local: objects.server.assume_local_server(server_id) # execute command log_info("") return command_function(parsed_args)