def main(argv): from optparse import OptionParser parser = OptionParser(usage="%prog [options] backup|uninstall|restore|restore-engage [backup_directory]") parser.add_option("--compress", "-c", action="store_true", dest="compress", default=False, help="If specified, compress backup files") cmdline_script_utils.add_standard_cmdline_options(parser, running_deployment=False) (options, args) = parser.parse_args() if not (len(args)==2 or (len(args)==1 and args[0]=="uninstall")): parser.error("Wrong number of args, expecting 1 or 2") cmd = args[0] valid_commands = ["backup", "uninstall", "restore", "restore-engage"] if not (cmd in valid_commands): parser.error("Command must be one of %s" % valid_commands) (file_layout, dh) = cmdline_script_utils.process_standard_options(options, parser) if cmd != "uninstall": backup_directory = os.path.abspath(os.path.expanduser(args[1])) if cmd=="backup": if not os.path.isdir(backup_directory): os.makedirs(backup_directory) elif (cmd=="restore") or (cmd=="restore-engage"): if not os.path.isdir(backup_directory): parser.error("Backup directory %s does not exist" % backup_directory) if cmd == "restore-engage": # for restore engage, we don't try to get resources, as they aren't there yet restore_engage_files(backup_directory) return 0 # skip the rest mgr_pkg_list = cmdline_script_utils.get_mgrs_and_pkgs(file_layout, dh, options) logger = log_setup.setup_engine_logger(__name__) if cmd=="backup": for (m, p) in reversed(mgr_pkg_list): if m.is_service() and m.is_running(): logger.info("stopping resource %s" % m.id) m.stop() backup_resources(backup_directory, mgr_pkg_list, logger, options.compress) save_engage_files(backup_directory, dh, logger, options.compress) elif cmd=="uninstall": for (m, p) in reversed(mgr_pkg_list): if m.is_service() and m.is_running(): logger.info("stopping resource %s" % m.id) m.stop() uninstall_resources(mgr_pkg_list, logger) else: # command == restore restore_resources(backup_directory, mgr_pkg_list, logger) return 0
def parse_command_args(self, argv): usage = "usage: %prog [options]" parser = OptionParser(usage=usage) cmdline_script_utils.add_standard_cmdline_options(parser) parser.add_option("-m", "--multinode", action="store_true", dest="multinode", default=False, help="Installation requires multiple nodes") (self.options, self.args) = parser.parse_args(args=argv) if len(self.args) > 0: parser.error("Extra arguments for install engine") (dummy, self.deployment_home) = \ cmdline_script_utils.process_standard_options(self.options, parser, self.engage_file_layout) self.logger = setup_engine_logger(__name__)
def process_args(self, argv, engage_file_layout=None): usage = "usage: %prog [options] install_specification_file" parser = OptionParser(usage=usage) parser.add_option("-a", "--additive-install", default=False, action="store_true", help="If specified, an install already exists and we are adding resources to the deployment") cmdline_script_utils.add_standard_cmdline_options(parser, uses_pw_file=True) (self.options, args) = parser.parse_args(args=argv) if len(args)!=1: parser.error("Incorrect number of arguments - expecting install spec name") self.input_spec_file = args[0] if not os.path.exists(self.input_spec_file): parser.error("Install specification file %s does not exist" % self.input_spec_file) (self.efl, self.deployment_home) = \ cmdline_script_utils.process_standard_options(self.options, parser, engage_file_layout, installer_name=None) ir_file = self.efl.get_installed_resources_file(self.deployment_home) if self.options.additive_install: if not os.path.exists(ir_file): parser.error("--additive-install specified, but existing install file %s does not exist" % ir_file) else: if os.path.exists(ir_file): parser.error("Installed resources file %s already exists. Specify --additive-install if you want to add resources to this deployment home" % ir_file) self.error_file = os.path.join(self.efl.get_log_directory(), "user_error.json") self.config_error_file = config_engine.get_config_error_file(self.efl) self.tr = get_target_machine_resource(self.deployment_home, self.efl.get_log_directory()) if self.options.mgt_backends: import mgt_registration mgt_registration.validate_backend_names(self.options.mgt_backends, parser)
def process_args(self, argv, installer_file_layout=None): usage = "usage: %prog [options] installer_name" parser = OptionParser(usage=usage) cmdline_script_utils.add_standard_cmdline_options(parser) parser.add_option("--config-choices-file", dest="config_choices_file", default=None, help="If specified, get configuration choices from this json file, rather than interactively from the user") parser.add_option("--config-choices-history-file", dest="history_file", default=None, help="If specified, save config choices to this file") parser.add_option("--upgrade", "-u", dest="upgrade_from", action="store", default=None, help="If specified, we are doing an upgrade from the app backed up to the specified source directory") parser.add_option("--application-archive", "-a", dest="application_archive", action="store", default=None, help="If specified, override the application_archive property in config choices file with this value") parser.add_option("--no-rollback-on-failed-upgrades", dest="no_rollback_on_failed_upgrades", default=False, action="store_true", help="If specified, do not roll back a failed upgrade (helpful for debugging).") parser.add_option("-y", "--use-defaults", dest="use_defaults", default=False, action="store_true", help="If specified, always pick default for input options") (self.options, args) = parser.parse_args(args=argv) if len(args)>1: parser.error("Extra arguments - expecting only installer name") if self.options.config_choices_file: config_choices_file = os.path.abspath(os.path.expanduser(self.options.config_choices_file)) if not os.path.exists(config_choices_file): parser.error("Configuration choices file %s does not exist" % config_choices_file) self.config_choices = ConfigChoices(config_choices_file) else: self.config_choices = ConfigChoices(use_defaults=self.options.use_defaults) # processing of --application-archive option if self.options.application_archive: app_archive = os.path.abspath(os.path.expanduser(self.options.application_archive)) if not os.path.exists(app_archive): parser.error("Application archive %s does not exist" % app_archive) if self.options.config_choices_file: self.config_choices.choices_from_file[APPLICATION_ARCHIVE_PROP] = app_archive else: self.config_choices.app_archive_value = app_archive # figure out which installer we are running if installer_file_layout: self.installer_name = installer_file_layout.installer_name if len(args)==1 and installer_file_layout.installer_name!=args[0]: parser.error("installer name '%s' provided on commmand line does not match installer name provided by installer_file_layout '%s'" % (args[0], installer_file_layout.installer_name)) elif self.options.config_choices_file: if len(args)>0: parser.error("Do not specify installer on command line if running from a config choices file") self.installer_name = self.config_choices.get_installer_name() else: if len(args)==0: parser.error("Must provide name of installer") self.installer_name = args[0] self.config_choices.set_installer_name(self.installer_name) (self.installer_file_layout, self.deployment_home) = \ cmdline_script_utils.process_standard_options(self.options, parser, installer_file_layout, installer_name=self.installer_name) if self.options.upgrade_from: self.upgrade_from = os.path.abspath(os.path.expanduser(self.options.upgrade_from)) if not os.path.isdir(self.upgrade_from): parser.error("Application backup directory %s does not exist" % self.upgrade_from) self.error_file = os.path.join(self.installer_file_layout.get_log_directory(), "user_error.json") self.config_error_file = get_config_error_file(self.installer_file_layout) if self.options.mgt_backends: import mgt_registration mgt_registration.validate_backend_names(self.options.mgt_backends, parser) # save backends in history for use in upgrades self.config_choices.choice_history[MGT_BACKENDS_PROP] = self.options.mgt_backends elif self.config_choices.choices_from_file and \ self.config_choices.choices_from_file.has_key(MGT_BACKENDS_PROP): # If a previous run had management backends specified, use those self.options.mgt_backends = self.config_choices.choices_from_file[MGT_BACKENDS_PROP] import mgt_registration mgt_registration.validate_backend_names(self.options.mgt_backends, parser)
def main(): parser = OptionParser(usage=usage_msg) add_standard_cmdline_options(parser, running_deployment=False, default_log_level="WARNING") parser.add_option("-r", "--resource-file", dest="resource_file", default=None, help="Name of resource file (defaults to <deployment_home>/config/installed_resources.json)") parser.add_option("--force", dest='force', default=False, action="store_true", help="If stop or restart, try to force everything to stop") parser.add_option("--dry-run", dest="dry_run", default=False, action="store_true", help="If specified, just print what would be done") (options, args) = parser.parse_args() if len(args)==0: parser.print_help() sys.exit(0) if len(args)<1: parser.error("Missing command name. Must be one of %s" % valid_commands) (file_layout, deployment_home) = process_standard_options(options, parser, allow_overrides_of_dh=True, rotate_logfiles=False) if options.resource_file: installed_resources_file = os.path.abspath(os.path.expanduser(options.resource_file)) else: installed_resources_file = file_layout.get_installed_resources_file(deployment_home) if not os.path.exists(installed_resources_file): sys.stderr.write("Error: Installed resources file '%s does not exist\n" % installed_resources_file) sys.exit(1) logger = setup_engage_logger(__name__) mgr_pkg_list = get_mgrs_and_pkgs(file_layout, deployment_home, options, installed_resources_file) resource_map = {} for (mgr, pkg) in mgr_pkg_list: resource_map[mgr.id] = mgr command = args[0] if command not in commands.keys(): sys.stderr.write("Error: invalid command %s\n" % command) parser.print_help() sys.exit(1) if options.force and command not in ['stop', 'restart']: sys.stderr.write("Error: --force option not valid for command %s\n" % command) parser.print_help() sys.exit(1) command_args = args[1:] cmd_fn = commands[command] try: if command in ['stop', 'restart']: rc = cmd_fn(command, command_args, mgr_pkg_list, resource_map, logger, options.dry_run, force=options.force) else: rc = cmd_fn(command, command_args, mgr_pkg_list, resource_map, logger, options.dry_run) except CommandError, msg: sys.stderr.write("Error: %s\n" % msg) sys.exit(1)