Ejemplo n.º 1
0
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
Ejemplo n.º 2
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__)
Ejemplo n.º 3
0
"""Interface to the ocaml configuration engine.
"""
import os.path
import json

# fix path if necessary (if running from source or running as test)
import fixup_python_path

import engage_utils.process as procutils
import preprocess_resources
from engage.utils.user_error import UserError, EngageErrInf, convert_exc_to_user_error, UserErrorParseExc, parse_user_error, AREA_CONFIG

from engage.utils.log_setup import setup_engine_logger
logger = setup_engine_logger(__name__)

def get_config_error_file(installer_file_layout):
    return os.path.join(os.path.dirname(
                          installer_file_layout.get_install_script_file()),
                            "config_error.json")
    

def run_config_engine(installer_file_layout, install_spec_file):
    ifl = installer_file_layout
    config_error_file = get_config_error_file(installer_file_layout)
    preprocess_resources.validate_install_spec(install_spec_file)
    install_script_file = ifl.get_install_script_file()
    if os.path.exists(install_script_file):
        logger.debug("moving old %s to %s before running config engine" %
                     (install_script_file, install_script_file + ".prev"))
        os.rename(install_script_file, install_script_file + ".prev")
    # we run the config engine from the same directory as where we want
Ejemplo n.º 4
0
def get_logger():
    global logger
    if logger == None:
        logger = setup_engine_logger(__name__)
    return logger