Ejemplo n.º 1
0
def run(args):
    """Starts the execution after args have been parsed and logging has been setup.
    """

    LOG.debug("CLI arguments are:")
    utils.log_object(args, logger=LOG, level=logging.DEBUG, item_max_len=128)

    # Keep the old args around so we have the full set to write out
    saved_args = dict(args)
    action = args.pop("action", '').strip().lower()
    if re.match(r"^moo[o]*$", action):
        return

    try:
        runner_cls = actions.class_for(action)
    except Exception as ex:
        raise excp.OptionException(str(ex))

    if runner_cls.needs_sudo:
        ensure_perms()

    # Check persona file exists
    persona_fn = args.pop('persona_fn')
    if not persona_fn:
        raise excp.OptionException("No persona file name specified!")
    if not sh.isfile(persona_fn):
        raise excp.OptionException("Invalid persona file %r specified!" %
                                   (persona_fn))

    # Check origin file exists
    origins_fn = args.pop('origins_fn')
    if not origins_fn:
        raise excp.OptionException("No origin file name specified!")
    if not sh.isfile(origins_fn):
        raise excp.OptionException("Invalid origin file %r specified!" %
                                   (origins_fn))
    args['origins_fn'] = sh.abspth(origins_fn)

    # Determine the root directory...
    root_dir = sh.abspth(args.pop("dir"))

    (repeat_string, line_max_len) = utils.welcome()
    print(pprint.center_text("Action Runner", repeat_string, line_max_len))

    # !!
    # Here on out we should be using the logger (and not print)!!
    # !!

    # Ensure the anvil dirs are there if others are about to use it...
    if not sh.isdir(root_dir):
        LOG.info("Creating anvil root directory at path: %s", root_dir)
        sh.mkdir(root_dir)
    try:
        for d in ANVIL_DIRS:
            if sh.isdir(d):
                continue
            LOG.info("Creating anvil auxiliary directory at path: %s", d)
            sh.mkdir(d)
    except OSError as e:
        LOG.warn("Failed ensuring auxiliary directories due to %s", e)

    # Load the origins...
    origins = _origins.load(args['origins_fn'],
                            patch_file=args.get('origins_patch'))

    # Load the distro/s
    possible_distros = distro.load(settings.DISTRO_DIR,
                                   distros_patch=args.get('distros_patch'))

    # Load + match the persona to the possible distros...
    try:
        persona_obj = persona.load(persona_fn)
    except Exception as e:
        raise excp.OptionException("Error loading persona file: %s due to %s" %
                                   (persona_fn, e))
    else:
        dist = persona_obj.match(possible_distros, origins)
        LOG.info('Persona selected distro: %s from %s possible distros',
                 colorizer.quote(dist.name), len(possible_distros))

    # Update the dist with any other info...
    dist.inject_platform_overrides(persona_obj.distro_updates,
                                   source=persona_fn)
    dist.inject_platform_overrides(origins, source=origins_fn)

    # Print it out...
    LOG.debug("Distro settings are:")
    for line in dist.pformat(item_max_len=128).splitlines():
        LOG.debug(line)

    # Get the object we will be running with...
    runner = runner_cls(distro=dist,
                        root_dir=root_dir,
                        name=action,
                        cli_opts=args)

    # Now that the settings are known to work, store them for next run
    store_current_settings(saved_args)

    LOG.info("Starting action %s on %s for distro: %s",
             colorizer.quote(action), colorizer.quote(utils.iso8601()),
             colorizer.quote(dist.name))
    LOG.info("Using persona: %s", colorizer.quote(persona_fn))
    LOG.info("Using origins: %s", colorizer.quote(origins_fn))
    LOG.info("In root directory: %s", colorizer.quote(root_dir))

    start_time = time.time()
    runner.run(persona_obj)
    end_time = time.time()

    pretty_time = utils.format_time(end_time - start_time)
    LOG.info("It took %s seconds or %s minutes to complete action %s.",
             colorizer.quote(pretty_time['seconds']),
             colorizer.quote(pretty_time['minutes']), colorizer.quote(action))
Ejemplo n.º 2
0
def run(args):
    """
    Starts the execution after args have been parsed and logging has been setup.

    Arguments: N/A
    Returns: True for success to run, False for failure to start
    """
    LOG.debug("CLI arguments are:")
    utils.log_object(args, logger=LOG, level=logging.DEBUG, item_max_len=128)

    # Keep the old args around so we have the full set to write out
    saved_args = dict(args)
    action = args.pop("action", '').strip().lower()
    if action not in actions.names():
        raise excp.OptionException("Invalid action name %r specified!" %
                                   (action))

    # Determine + setup the root directory...
    # If not provided attempt to locate it via the environment control files
    args_root_dir = args.pop("dir")
    root_dir = env.get_key('INSTALL_ROOT')
    if not root_dir:
        root_dir = args_root_dir
    if not root_dir:
        root_dir = sh.joinpths(sh.gethomedir(), 'openstack')
    root_dir = sh.abspth(root_dir)
    sh.mkdir(root_dir)

    persona_fn = args.pop('persona_fn')
    if not persona_fn:
        raise excp.OptionException("No persona file name specified!")
    if not sh.isfile(persona_fn):
        raise excp.OptionException("Invalid persona file %r specified!" %
                                   (persona_fn))

    # !!
    # Here on out we should be using the logger (and not print)!!
    # !!

    # Stash the dryrun value (if any)
    if 'dryrun' in args:
        env.set("ANVIL_DRYRUN", str(args['dryrun']))

    # Ensure the anvil etc dir is there if others are about to use it
    ensure_anvil_dir()

    # Load the distro
    dist = distro.load(settings.DISTRO_DIR)

    # Load + verify the person
    try:
        persona_obj = persona.load(persona_fn)
        persona_obj.verify(dist)
    except Exception as e:
        raise excp.OptionException("Error loading persona file: %s due to %s" %
                                   (persona_fn, e))

    # Get the object we will be running with...
    runner_cls = actions.class_for(action)
    runner = runner_cls(distro=dist,
                        root_dir=root_dir,
                        name=action,
                        cli_opts=args)

    (repeat_string, line_max_len) = utils.welcome()
    print(center_text("Action Runner", repeat_string, line_max_len))

    # Now that the settings are known to work, store them for next run
    store_current_settings(saved_args)

    LOG.info("Starting action %s on %s for distro: %s",
             colorizer.quote(action), colorizer.quote(utils.iso8601()),
             colorizer.quote(dist.name))
    LOG.info("Using persona: %s", colorizer.quote(persona_fn))
    LOG.info("In root directory: %s", colorizer.quote(root_dir))

    start_time = time.time()
    runner.run(persona_obj)
    end_time = time.time()

    pretty_time = utils.format_time(end_time - start_time)
    LOG.info("It took %s seconds or %s minutes to complete action %s.",
             colorizer.quote(pretty_time['seconds']),
             colorizer.quote(pretty_time['minutes']), colorizer.quote(action))
Ejemplo n.º 3
0
def run(args):
    """Starts the execution after args have been parsed and logging has been setup.
    """

    LOG.debug("CLI arguments are:")
    utils.log_object(args, logger=LOG, level=logging.DEBUG, item_max_len=128)

    # Keep the old args around so we have the full set to write out
    saved_args = dict(args)
    action = args.pop("action", "").strip().lower()
    if re.match(r"^moo[o]*$", action):
        return

    try:
        runner_cls = actions.class_for(action)
    except Exception as ex:
        raise excp.OptionException(str(ex))

    if runner_cls.needs_sudo:
        ensure_perms()

    # Check persona file exists
    persona_fn = args.pop("persona_fn")
    if not persona_fn:
        raise excp.OptionException("No persona file name specified!")
    if not sh.isfile(persona_fn):
        raise excp.OptionException("Invalid persona file %r specified!" % (persona_fn))

    # Check origin file exists
    origins_fn = args.pop("origins_fn")
    if not origins_fn:
        raise excp.OptionException("No origin file name specified!")
    if not sh.isfile(origins_fn):
        raise excp.OptionException("Invalid origin file %r specified!" % (origins_fn))
    args["origins_fn"] = sh.abspth(origins_fn)

    # Determine the root directory...
    root_dir = sh.abspth(args.pop("dir"))

    (repeat_string, line_max_len) = utils.welcome()
    print(pprint.center_text("Action Runner", repeat_string, line_max_len))

    # !!
    # Here on out we should be using the logger (and not print)!!
    # !!

    # Stash the dryrun value (if any)
    if "dryrun" in args:
        sh.set_dry_run(args["dryrun"])

    # Ensure the anvil dirs are there if others are about to use it...
    ensure_anvil_dirs(root_dir)

    # Load the distro
    dist = distro.load(settings.DISTRO_DIR)

    # Load + verify the person
    try:
        persona_obj = persona.load(persona_fn)
        persona_obj.verify(dist)
    except Exception as e:
        raise excp.OptionException("Error loading persona file: %s due to %s" % (persona_fn, e))

    yum.YumDependencyHandler.jobs = args["jobs"]
    # Get the object we will be running with...
    runner = runner_cls(distro=dist, root_dir=root_dir, name=action, cli_opts=args)

    # Now that the settings are known to work, store them for next run
    store_current_settings(saved_args)

    LOG.info(
        "Starting action %s on %s for distro: %s",
        colorizer.quote(action),
        colorizer.quote(utils.iso8601()),
        colorizer.quote(dist.name),
    )
    LOG.info("Using persona: %s", colorizer.quote(persona_fn))
    LOG.info("Using origins: %s", colorizer.quote(origins_fn))
    LOG.info("In root directory: %s", colorizer.quote(root_dir))

    start_time = time.time()
    runner.run(persona_obj)
    end_time = time.time()

    pretty_time = utils.format_time(end_time - start_time)
    LOG.info(
        "It took %s seconds or %s minutes to complete action %s.",
        colorizer.quote(pretty_time["seconds"]),
        colorizer.quote(pretty_time["minutes"]),
        colorizer.quote(action),
    )
Ejemplo n.º 4
0
def run(args):
    """Starts the execution after args have been parsed and logging has been setup.
    """

    LOG.debug("CLI arguments are:")
    utils.log_object(args, logger=LOG, level=logging.DEBUG, item_max_len=128)

    # Keep the old args around so we have the full set to write out
    saved_args = dict(args)
    action = args.pop("action", '').strip().lower()
    if re.match(r"^moo[o]*$", action):
        return

    try:
        runner_cls = actions.class_for(action)
    except Exception as ex:
        raise excp.OptionException(str(ex))

    if runner_cls.needs_sudo:
        ensure_perms()

    persona_fn = args.pop('persona_fn')
    if not persona_fn:
        raise excp.OptionException("No persona file name specified!")
    if not sh.isfile(persona_fn):
        raise excp.OptionException("Invalid persona file %r specified!" %
                                   (persona_fn))

    # Determine the root directory...
    root_dir = sh.abspth(args.pop("dir"))

    (repeat_string, line_max_len) = utils.welcome()
    print(pprint.center_text("Action Runner", repeat_string, line_max_len))

    # !!
    # Here on out we should be using the logger (and not print)!!
    # !!

    # Stash the dryrun value (if any)
    if 'dryrun' in args:
        sh.set_dry_run(args['dryrun'])

    # Ensure the anvil dirs are there if others are about to use it...
    ensure_anvil_dirs(root_dir)

    # Load the distro
    dist = distro.load(settings.DISTRO_DIR)

    # Load + verify the person
    try:
        persona_obj = persona.load(persona_fn)
        persona_obj.verify(dist)
    except Exception as e:
        raise excp.OptionException("Error loading persona file: %s due to %s" %
                                   (persona_fn, e))

    yum.YumDependencyHandler.jobs = args["jobs"]
    # Get the object we will be running with...
    runner = runner_cls(distro=dist,
                        root_dir=root_dir,
                        name=action,
                        cli_opts=args)

    # Now that the settings are known to work, store them for next run
    store_current_settings(saved_args)

    LOG.info("Starting action %s on %s for distro: %s",
             colorizer.quote(action), colorizer.quote(utils.iso8601()),
             colorizer.quote(dist.name))
    LOG.info("Using persona: %s", colorizer.quote(persona_fn))
    LOG.info("In root directory: %s", colorizer.quote(root_dir))

    start_time = time.time()
    runner.run(persona_obj)
    end_time = time.time()

    pretty_time = utils.format_time(end_time - start_time)
    LOG.info("It took %s seconds or %s minutes to complete action %s.",
             colorizer.quote(pretty_time['seconds']),
             colorizer.quote(pretty_time['minutes']), colorizer.quote(action))
Ejemplo n.º 5
0
def run(args):
    """
    Starts the execution after args have been parsed and logging has been setup.
    """

    LOG.debug("CLI arguments are:")
    utils.log_object(args, logger=LOG, level=logging.DEBUG, item_max_len=128)

    # Keep the old args around so we have the full set to write out
    saved_args = dict(args)
    action = args.pop("action", '').strip().lower()
    try:
        runner_cls = actions.class_for(action)
    except Exception as ex:
        raise excp.OptionException(str(ex))

    if runner_cls.needs_sudo:
        ensure_perms()

    persona_fn = args.pop('persona_fn')
    if not persona_fn:
        raise excp.OptionException("No persona file name specified!")
    if not sh.isfile(persona_fn):
        raise excp.OptionException("Invalid persona file %r specified!" % (persona_fn))

    # Determine + setup the root directory...
    # If not provided attempt to locate it via the environment control files
    args_root_dir = args.pop("dir")
    root_dir = env.get_key('INSTALL_ROOT')
    if not root_dir:
        root_dir = args_root_dir
    if not root_dir:
        root_dir = sh.joinpths(sh.gethomedir(), 'openstack')
    root_dir = sh.abspth(root_dir)

    (repeat_string, line_max_len) = utils.welcome()
    print(center_text("Action Runner", repeat_string, line_max_len))

    # !!
    # Here on out we should be using the logger (and not print)!!
    # !!

    # Stash the dryrun value (if any)
    if 'dryrun' in args:
        sh.set_dry_run(args['dryrun'])

    # Ensure the anvil dirs are there if others are about to use it...
    ensure_anvil_dirs(root_dir)

    # Load the distro
    dist = distro.load(settings.DISTRO_DIR)

    # Load + verify the person
    try:
        persona_obj = persona.load(persona_fn)
        persona_obj.verify(dist)
    except Exception as e:
        raise excp.OptionException("Error loading persona file: %s due to %s" % (persona_fn, e))

    # Get the object we will be running with...
    runner = runner_cls(distro=dist,
                        root_dir=root_dir,
                        name=action,
                        cli_opts=args)

    # Now that the settings are known to work, store them for next run
    store_current_settings(saved_args)

    LOG.info("Starting action %s on %s for distro: %s",
             colorizer.quote(action), colorizer.quote(utils.iso8601()),
             colorizer.quote(dist.name))
    LOG.info("Using persona: %s", colorizer.quote(persona_fn))
    LOG.info("In root directory: %s", colorizer.quote(root_dir))

    start_time = time.time()
    runner.run(persona_obj)
    end_time = time.time()

    pretty_time = utils.format_time(end_time - start_time)
    LOG.info("It took %s seconds or %s minutes to complete action %s.",
             colorizer.quote(pretty_time['seconds']), colorizer.quote(pretty_time['minutes']), colorizer.quote(action))
Ejemplo n.º 6
0
def run(args):
    """Starts the execution after args have been parsed and logging has been setup.
    """

    LOG.debug("CLI arguments are:")
    utils.log_object(args, logger=LOG, level=logging.DEBUG, item_max_len=128)

    # Keep the old args around so we have the full set to write out
    saved_args = dict(args)
    action = args.pop("action", '').strip().lower()
    if re.match(r"^moo[o]*$", action):
        return

    try:
        runner_cls = actions.class_for(action)
    except Exception as ex:
        raise excp.OptionException(str(ex))

    if runner_cls.needs_sudo:
        ensure_perms()

    # Check persona file exists
    persona_fn = args.pop('persona_fn')
    if not persona_fn:
        raise excp.OptionException("No persona file name specified!")
    if not sh.isfile(persona_fn):
        raise excp.OptionException("Invalid persona file %r specified!" % (persona_fn))

    # Check origin file exists
    origins_fn = args.pop('origins_fn')
    if not origins_fn:
        raise excp.OptionException("No origin file name specified!")
    if not sh.isfile(origins_fn):
        raise excp.OptionException("Invalid origin file %r specified!" % (origins_fn))
    args['origins_fn'] = sh.abspth(origins_fn)

    # Determine the root directory...
    root_dir = sh.abspth(args.pop("dir"))

    (repeat_string, line_max_len) = utils.welcome()
    print(pprint.center_text("Action Runner", repeat_string, line_max_len))

    # !!
    # Here on out we should be using the logger (and not print)!!
    # !!

    # Ensure the anvil dirs are there if others are about to use it...
    if not sh.isdir(root_dir):
        LOG.info("Creating anvil root directory at path: %s", root_dir)
        sh.mkdir(root_dir)
    try:
        for d in ANVIL_DIRS:
            if sh.isdir(d):
                continue
            LOG.info("Creating anvil auxiliary directory at path: %s", d)
            sh.mkdir(d)
    except OSError as e:
        LOG.warn("Failed ensuring auxiliary directories due to %s", e)

    # Load the origins...
    origins = _origins.load(args['origins_fn'],
                            patch_file=args.get('origins_patch'))

    # Load the distro/s
    possible_distros = distro.load(settings.DISTRO_DIR,
                                   distros_patch=args.get('distros_patch'))

    # Load + match the persona to the possible distros...
    try:
        persona_obj = persona.load(persona_fn)
    except Exception as e:
        raise excp.OptionException("Error loading persona file: %s due to %s" % (persona_fn, e))
    else:
        dist = persona_obj.match(possible_distros, origins)
        LOG.info('Persona selected distro: %s from %s possible distros',
                 colorizer.quote(dist.name), len(possible_distros))

    # Update the dist with any other info...
    dist.inject_platform_overrides(persona_obj.distro_updates, source=persona_fn)
    dist.inject_platform_overrides(origins, source=origins_fn)

    # Print it out...
    LOG.debug("Distro settings are:")
    for line in dist.pformat(item_max_len=128).splitlines():
        LOG.debug(line)

    # Get the object we will be running with...
    runner = runner_cls(distro=dist,
                        root_dir=root_dir,
                        name=action,
                        cli_opts=args)

    # Now that the settings are known to work, store them for next run
    store_current_settings(saved_args)

    LOG.info("Starting action %s on %s for distro: %s",
             colorizer.quote(action), colorizer.quote(utils.iso8601()),
             colorizer.quote(dist.name))
    LOG.info("Using persona: %s", colorizer.quote(persona_fn))
    LOG.info("Using origins: %s", colorizer.quote(origins_fn))
    LOG.info("In root directory: %s", colorizer.quote(root_dir))

    start_time = time.time()
    runner.run(persona_obj)
    end_time = time.time()

    pretty_time = utils.format_time(end_time - start_time)
    LOG.info("It took %s seconds or %s minutes to complete action %s.",
             colorizer.quote(pretty_time['seconds']), colorizer.quote(pretty_time['minutes']), colorizer.quote(action))