Example #1
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))
Example #2
0
def parse(previous_settings=None):

    version_str = "%s v%s" % ('anvil', version.version_string())
    help_formatter = IndentedHelpFormatter(width=120)
    parser = OptionParser(version=version_str, formatter=help_formatter,
                          prog='smithy')

    # Root options
    parser.add_option("-v", "--verbose",
        action="store_true",
        dest="verbose",
        default=False,
        help="make the output logging verbose")
    parser.add_option("--dryrun",
        action="store_true",
        dest="dryrun",
        default=False,
        help=("perform ACTION but do not actually run any of the commands"
              " that would normally complete ACTION"))

    # Install/start/stop/uninstall specific options
    base_group = OptionGroup(parser, "Action specific options")
    base_group.add_option("-p", "--persona",
        action="store",
        type="string",
        dest="persona_fn",
        default=sh.joinpths(settings.PERSONA_DIR, 'in-a-box', 'basic.yaml'),
        metavar="FILE",
        help="persona yaml file to apply (default: %default)")
    base_group.add_option("-a", "--action",
        action="store",
        type="string",
        dest="action",
        metavar="ACTION",
        help="required action to perform: %s" % (_format_list(actions.names())))
    base_group.add_option("-d", "--directory",
        action="store",
        type="string",
        dest="dir",
        metavar="DIR",
        help=("empty root DIR or "
              "DIR with existing components"))
    base_group.add_option("--no-prompt-passwords",
                          action="store_false",
                          dest="prompt_for_passwords",
                          default=True,
                          help="do not prompt the user for passwords")
    base_group.add_option("--no-store-passwords",
        action="store_false",
        dest="store_passwords",
        default=True,
        help="do not store the users passwords into yaml files")
    parser.add_option_group(base_group)

    suffixes = ("Known suffixes 'K' (kilobyte, 1024),"
                " 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)"
                " are supported, 'B' is the default and is ignored")
    status_group = OptionGroup(parser, "Status specific options")
    status_group.add_option('-s', "--show",
        action="callback",
        dest="show_amount",
        type='string',
        metavar="SIZE",
        callback=_size_cb,
        help="show SIZE 'details' when showing component status. " + suffixes)
    parser.add_option_group(status_group)

    pkg_group = OptionGroup(parser, "Packaging specific options")
    pkg_group.add_option('-m', "--match-installed",
        action="store_true",
        dest="match_installed",
        default=False,
        help="when packaging attempt to use the versions that are installed for the components dependencies")
    parser.add_option_group(pkg_group)

    uninstall_group = OptionGroup(parser, "Uninstall specific options")
    uninstall_group.add_option("--purge",
        action="store_true",
        dest="purge_packages",
        default=False,
        help=("assume when a package is not marked as removable that it can be removed (default: %default)"))
    parser.add_option_group(uninstall_group)

    # Extract only what we care about, these will be passed
    # to the constructor of actions as arguments 
    # so don't adjust the naming wily nilly...
    if previous_settings:
        parser.set_defaults(**previous_settings)

    (options, args) = parser.parse_args()
    values = {}
    values['dir'] = (options.dir or "")
    values['dryrun'] = (options.dryrun or False)
    values['action'] = (options.action or "")
    values['persona_fn'] = options.persona_fn
    values['verbose'] = options.verbose
    values['prompt_for_passwords'] = options.prompt_for_passwords
    values['show_amount'] = max(0, options.show_amount)
    values['store_passwords'] = options.store_passwords
    values['match_installed'] = options.match_installed
    values['purge_packages'] = options.purge_packages
    return values
Example #3
0
def parse(previous_settings=None):

    version_str = "%s v%s" % ('anvil', version.version_string())
    help_formatter = IndentedHelpFormatter(width=120)
    parser = OptionParser(version=version_str,
                          formatter=help_formatter,
                          prog='smithy')

    # Root options
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="make the output logging verbose")
    parser.add_option(
        "--dryrun",
        action="store_true",
        dest="dryrun",
        default=False,
        help=("perform ACTION but do not actually run any of the commands"
              " that would normally complete ACTION"))
    parser.add_option(
        '-k',
        "--keyring",
        action="store",
        dest="keyring_path",
        default="/etc/anvil/passwords.cfg",
        help=
        ("read and create passwords using this keyring file (default: %default)"
         ))
    parser.add_option(
        '-e',
        "--encrypt",
        action="store_true",
        dest="keyring_encrypted",
        default=False,
        help=("use a encrypted keyring file (default: %default)"))
    parser.add_option("--no-prompt-passwords",
                      action="store_false",
                      dest="prompt_for_passwords",
                      default=True,
                      help="do not prompt the user for passwords")
    parser.add_option(
        "--no-store-passwords",
        action="store_false",
        dest="store_passwords",
        default=True,
        help="do not save the users passwords into the users keyring")

    # Install/start/stop/uninstall specific options
    base_group = OptionGroup(parser, "Action specific options")
    base_group.add_option(
        "-p",
        "--persona",
        action="store",
        type="string",
        dest="persona_fn",
        default=sh.joinpths(settings.PERSONA_DIR, 'in-a-box', 'basic.yaml'),
        metavar="FILE",
        help="persona yaml file to apply (default: %default)")
    base_group.add_option("-a",
                          "--action",
                          action="store",
                          type="string",
                          dest="action",
                          metavar="ACTION",
                          help="required action to perform: %s" %
                          (_format_list(actions.names())))
    base_group.add_option(
        "-d",
        "--directory",
        action="store",
        type="string",
        dest="dir",
        metavar="DIR",
        help=("empty root DIR or DIR with existing components"))
    parser.add_option_group(base_group)

    suffixes = ("Known suffixes 'K' (kilobyte, 1024),"
                " 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)"
                " are supported, 'B' is the default and is ignored")
    status_group = OptionGroup(parser, "Status specific options")
    status_group.add_option(
        '-s',
        "--show",
        action="callback",
        dest="show_amount",
        type='string',
        metavar="SIZE",
        callback=_size_cb,
        help="show SIZE 'details' when showing component status. " + suffixes)
    parser.add_option_group(status_group)

    pkg_group = OptionGroup(parser, "Packaging specific options")
    pkg_group.add_option(
        '-m',
        "--match-installed",
        action="store_true",
        dest="match_installed",
        default=False,
        help=("when packaging attempt to use the versions that are "
              "installed for the components dependencies"))
    parser.add_option_group(pkg_group)

    install_group = OptionGroup(parser, "Install specific options")
    install_group.add_option(
        '-c',
        "--only-configure",
        action="store_true",
        dest="only_configure",
        default=False,
        help=("when installing only perform the"
              " download and install phases (default: %default)"))
    parser.add_option_group(install_group)

    uninstall_group = OptionGroup(parser, "Uninstall specific options")
    uninstall_group.add_option(
        "--purge",
        action="store_true",
        dest="purge_packages",
        default=False,
        help=("assume when a package is not marked as"
              " removable that it can be removed (default: %default)"))
    parser.add_option_group(uninstall_group)

    # Extract only what we care about, these will be passed
    # to the constructor of actions as arguments
    # so don't adjust the naming wily nilly...
    if previous_settings:
        parser.set_defaults(**previous_settings)

    (options, _args) = parser.parse_args()
    values = {}
    values['dir'] = (options.dir or "")
    values['dryrun'] = (options.dryrun or False)
    values['action'] = (options.action or "")
    values['persona_fn'] = options.persona_fn
    values['verbose'] = options.verbose
    values['only_configure'] = options.only_configure
    values['prompt_for_passwords'] = options.prompt_for_passwords
    values['show_amount'] = max(0, options.show_amount)
    values['store_passwords'] = options.store_passwords
    values['match_installed'] = options.match_installed
    values['purge_packages'] = options.purge_packages
    values['keyring_path'] = options.keyring_path
    values['keyring_encrypted'] = options.keyring_encrypted
    return values
Example #4
0
def parse(previous_settings=None):

    version_str = "%s v%s" % ('anvil', version.version_string())
    help_formatter = SmithyHelpFormatter(width=120)
    parser = OptionParser(version=version_str,
                          formatter=help_formatter,
                          prog='smithy')

    # Root options
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="make the output logging verbose")

    # Install/start/stop/uninstall specific options
    base_group = OptionGroup(parser, "Action specific options")
    base_group.add_option(
        "-p",
        "--persona",
        action="store",
        type="string",
        dest="persona_fn",
        default=sh.joinpths(settings.PERSONA_DIR, 'in-a-box', 'basic.yaml'),
        metavar="FILE",
        help="persona yaml file to apply (default: %default)")
    base_group.add_option("-a",
                          "--action",
                          action="store",
                          type="string",
                          dest="action",
                          metavar="ACTION",
                          help="required action to perform: %s" %
                          (_format_list(actions.names())))
    base_group.add_option(
        "-o",
        "--origins",
        action="store",
        type="string",
        dest="origins_fn",
        default=sh.joinpths(settings.ORIGINS_DIR, 'master.yaml'),
        metavar="FILE",
        help="yaml file describing where to get openstack sources "
        "from (default: %default)")
    base_group.add_option("--origins-patch",
                          action="store",
                          type="string",
                          dest="origins_patch_fn",
                          default=None,
                          metavar="FILE",
                          help="origins file patch, jsonpath format (rfc6902)")
    base_group.add_option("--distros-patch",
                          action="store",
                          type="string",
                          dest="distros_patch_fn",
                          default=None,
                          metavar="FILE",
                          help="distros file patch, jsonpath format (rfc6902)")
    base_group.add_option(
        "-j",
        "--jobs",
        action="store",
        type="int",
        dest="jobs",
        default=multiprocessing.cpu_count() + 1,
        metavar="JOBS",
        help="number of building jobs to run simultaneously (default: %default)"
    )
    base_group.add_option(
        "-d",
        "--directory",
        action="store",
        type="string",
        dest="dir",
        metavar="DIR",
        default=_get_default_dir(),
        help=(
            "empty root DIR or DIR with existing components (default: %default)"
        ))
    base_group.add_option(
        "--tee-file",
        action="store",
        type="string",
        dest="tee_file",
        metavar="FILE",
        default='/var/log/anvil.log',
        help=("location to store tee of output (default: %default)"))
    parser.add_option_group(base_group)

    build_group = OptionGroup(parser, "Build specific options")
    build_group.add_option('-u',
                           "--usr-only",
                           action="store_true",
                           dest="usr_only",
                           default=False,
                           help=("when packaging only store /usr directory"
                                 " (default: %default)"))
    build_group.add_option("--venv-deploy-dir",
                           action="store",
                           type="string",
                           dest="venv_deploy_dir",
                           default=None,
                           help=("for virtualenv builds, make the virtualenv "
                                 "relocatable to a directory different from "
                                 "build directory"))
    build_group.add_option(
        '-c',
        "--overwrite-configs",
        action="store_true",
        dest="overwrite_configs",
        default=False,
        help=("When packaging do you want rpm to mark config "
              "files with %config or treat them as files and "
              "overwrite them each time on rpm install"))
    parser.add_option_group(build_group)

    # Extract only what we care about, these will be passed
    # to the constructor of actions as arguments
    # so don't adjust the naming wily nilly...
    if previous_settings:
        parser.set_defaults(**previous_settings)

    (options, _args) = parser.parse_args()
    values = {}
    values['dir'] = (options.dir or "")
    values['action'] = (options.action or "")
    values['jobs'] = options.jobs
    values['persona_fn'] = options.persona_fn
    values['origins_fn'] = options.origins_fn
    values['verbose'] = options.verbose
    values['usr_only'] = options.usr_only
    values['tee_file'] = options.tee_file
    values['overwrite_configs'] = options.overwrite_configs
    if options.origins_patch_fn:
        with open(options.origins_patch_fn) as fp:
            values['origins_patch'] = json.load(fp)
    if options.distros_patch_fn:
        with open(options.distros_patch_fn) as fp:
            values['distros_patch'] = json.load(fp)
    values['venv_deploy_dir'] = options.venv_deploy_dir
    return values
Example #5
0
def parse(previous_settings=None):

    version_str = "%s v%s" % ('anvil', version.version_string())
    help_formatter = IndentedHelpFormatter(width=120)
    parser = OptionParser(version=version_str, formatter=help_formatter,
                          prog='smithy')

    # Root options
    parser.add_option("-v", "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="make the output logging verbose")
    parser.add_option("--dryrun",
                      action="store_true",
                      dest="dryrun",
                      default=False,
                      help=("perform ACTION but do not actually run any of the commands"
                            " that would normally complete ACTION"))
    parser.add_option('-k', "--keyring",
                      action="store",
                      dest="keyring_path",
                      default="/etc/anvil/passwords.cfg",
                      help=("read and create passwords using this keyring file (default: %default)"))
    parser.add_option('-e', "--encrypt",
                      action="store_true",
                      dest="keyring_encrypted",
                      default=False,
                      help=("use a encrypted keyring file (default: %default)"))
    parser.add_option("--no-prompt-passwords",
                      action="store_false",
                      dest="prompt_for_passwords",
                      default=True,
                      help="do not prompt the user for passwords")
    parser.add_option("--no-store-passwords",
                      action="store_false",
                      dest="store_passwords",
                      default=True,
                      help="do not save the users passwords into the users keyring")

    # Install/start/stop/uninstall specific options
    base_group = OptionGroup(parser, "Action specific options")
    base_group.add_option("-p", "--persona",
                          action="store",
                          type="string",
                          dest="persona_fn",
                          default=sh.joinpths(settings.PERSONA_DIR, 'in-a-box', 'basic.yaml'),
                          metavar="FILE",
                          help="persona yaml file to apply (default: %default)")
    base_group.add_option("-t", "--openstack-version",
                          action="store",
                          type="string",
                          dest="version_fn",
                          default=sh.joinpths(settings.VERSION_DIR, 'default.yaml'),
                          metavar="FILE",
                          help="version yaml file to apply (default: %default)")
    base_group.add_option("-a", "--action",
                          action="store",
                          type="string",
                          dest="action",
                          metavar="ACTION",
                          help="required action to perform: %s" % (_format_list(actions.names())))
    base_group.add_option("-j", "--jobs",
                          action="store",
                          type="int",
                          dest="jobs",
                          default=multiprocessing.cpu_count() + 1,
                          metavar="JOBS",
                          help="number of building jobs to run simultaneously (default: %default)")
    base_group.add_option("-d", "--directory",
                          action="store",
                          type="string",
                          dest="dir",
                          metavar="DIR",
                          help=("empty root DIR or DIR with existing components"))
    parser.add_option_group(base_group)

    suffixes = ("Known suffixes 'K' (kilobyte, 1024),"
                " 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)"
                " are supported, 'B' is the default and is ignored")
    status_group = OptionGroup(parser, "Status specific options")
    status_group.add_option('-s', "--show",
                            action="callback",
                            dest="show_amount",
                            type='string',
                            metavar="SIZE",
                            callback=_size_cb,
                            help="show SIZE 'details' when showing component status. " + suffixes)
    parser.add_option_group(status_group)

    build_group = OptionGroup(parser, "Build specific options")
    build_group.add_option('-u', "--usr-only",
                           action="store_true",
                           dest="usr_only",
                           default=False,
                           help=("when packaging only store /usr directory"
                                 " (default: %default)"))
    parser.add_option_group(build_group)

    # Extract only what we care about, these will be passed
    # to the constructor of actions as arguments
    # so don't adjust the naming wily nilly...
    if previous_settings:
        parser.set_defaults(**previous_settings)

    (options, _args) = parser.parse_args()
    values = {}
    values['dir'] = (options.dir or "")
    values['dryrun'] = (options.dryrun or False)
    values['action'] = (options.action or "")
    values['jobs'] = options.jobs
    values['persona_fn'] = options.persona_fn
    values['version_fn'] = options.version_fn
    values['verbose'] = options.verbose
    values['usr_only'] = options.usr_only
    values['prompt_for_passwords'] = options.prompt_for_passwords
    values['show_amount'] = max(0, options.show_amount)
    values['store_passwords'] = options.store_passwords
    values['keyring_path'] = options.keyring_path
    values['keyring_encrypted'] = options.keyring_encrypted
    return values
Example #6
0
def parse(previous_settings=None):

    version_str = "%s v%s" % ('anvil', version.version_string())
    help_formatter = SmithyHelpFormatter(width=120)
    parser = OptionParser(version=version_str,
                          formatter=help_formatter,
                          prog='smithy')

    # Root options
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="make the output logging verbose")
    parser.add_option(
        "--dryrun",
        action="store_true",
        dest="dryrun",
        default=False,
        help=("perform ACTION but do not actually run any of the commands"
              " that would normally complete ACTION"))
    parser.add_option(
        '-k',
        "--keyring",
        action="store",
        dest="keyring_path",
        default="/etc/anvil/passwords.cfg",
        help=
        ("read and create passwords using this keyring file (default: %default)"
         ))
    parser.add_option(
        '-e',
        "--encrypt",
        action="store_true",
        dest="keyring_encrypted",
        default=False,
        help=("use a encrypted keyring file (default: %default)"))
    parser.add_option("--no-prompt-passwords",
                      action="store_false",
                      dest="prompt_for_passwords",
                      default=True,
                      help="do not prompt the user for passwords")
    parser.add_option(
        "--no-store-passwords",
        action="store_false",
        dest="store_passwords",
        default=True,
        help="do not save the users passwords into the users keyring")

    # Install/start/stop/uninstall specific options
    base_group = OptionGroup(parser, "Action specific options")
    base_group.add_option(
        "-p",
        "--persona",
        action="store",
        type="string",
        dest="persona_fn",
        default=sh.joinpths(settings.PERSONA_DIR, 'in-a-box', 'basic.yaml'),
        metavar="FILE",
        help="persona yaml file to apply (default: %default)")
    base_group.add_option("-a",
                          "--action",
                          action="store",
                          type="string",
                          dest="action",
                          metavar="ACTION",
                          help="required action to perform: %s" %
                          (_format_list(actions.names())))
    base_group.add_option(
        "-j",
        "--jobs",
        action="store",
        type="int",
        dest="jobs",
        default=multiprocessing.cpu_count() + 1,
        metavar="JOBS",
        help="number of building jobs to run simultaneously (default: %default)"
    )
    base_group.add_option(
        "-d",
        "--directory",
        action="store",
        type="string",
        dest="dir",
        metavar="DIR",
        default=_get_default_dir(),
        help=(
            "empty root DIR or DIR with existing components (default: %default)"
        ))
    parser.add_option_group(base_group)

    suffixes = ("Known suffixes 'K' (kilobyte, 1024),"
                " 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)"
                " are supported, 'B' is the default and is ignored")
    status_group = OptionGroup(parser, "Status specific options")
    status_group.add_option(
        '-s',
        "--show",
        action="callback",
        dest="show_amount",
        type='string',
        metavar="SIZE",
        callback=_size_cb,
        help="show SIZE 'details' when showing component status. " + suffixes)
    parser.add_option_group(status_group)

    build_group = OptionGroup(parser, "Build specific options")
    build_group.add_option('-u',
                           "--usr-only",
                           action="store_true",
                           dest="usr_only",
                           default=False,
                           help=("when packaging only store /usr directory"
                                 " (default: %default)"))
    parser.add_option_group(build_group)

    test_group = OptionGroup(parser, "Test specific options")
    test_group.add_option(
        '-i',
        "--ignore-failures",
        action="store_true",
        dest="ignore_test_failures",
        default=False,
        help=("when running tests ignore component test failures"
              " (default: %default)"))
    parser.add_option_group(test_group)

    # Extract only what we care about, these will be passed
    # to the constructor of actions as arguments
    # so don't adjust the naming wily nilly...
    if previous_settings:
        parser.set_defaults(**previous_settings)

    (options, _args) = parser.parse_args()
    values = {}
    values['dir'] = (options.dir or "")
    values['dryrun'] = (options.dryrun or False)
    values['action'] = (options.action or "")
    values['jobs'] = options.jobs
    values['persona_fn'] = options.persona_fn
    values['verbose'] = options.verbose
    values['usr_only'] = options.usr_only
    values['prompt_for_passwords'] = options.prompt_for_passwords
    values['show_amount'] = max(0, options.show_amount)
    values['store_passwords'] = options.store_passwords
    values['keyring_path'] = options.keyring_path
    values['keyring_encrypted'] = options.keyring_encrypted
    values['ignore_test_failures'] = options.ignore_test_failures
    return values
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 dirs are there if others are about to use it...
    ensure_anvil_dirs()

    # 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))
Example #8
0
File: opts.py Project: y2kbot/anvil
def parse(previous_settings=None):

    version_str = "%s v%s" % ('anvil', version.version_string())
    help_formatter = SmithyHelpFormatter(width=120)
    parser = OptionParser(version=version_str, formatter=help_formatter,
                          prog='smithy')

    # Root options
    parser.add_option("-v", "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="make the output logging verbose")

    # Install/start/stop/uninstall specific options
    base_group = OptionGroup(parser, "Action specific options")
    base_group.add_option("-p", "--persona",
                          action="store",
                          type="string",
                          dest="persona_fn",
                          default=sh.joinpths(settings.PERSONA_DIR, 'in-a-box', 'basic.yaml'),
                          metavar="FILE",
                          help="persona yaml file to apply (default: %default)")
    base_group.add_option("-a", "--action",
                          action="store",
                          type="string",
                          dest="action",
                          metavar="ACTION",
                          help="required action to perform: %s" % (_format_list(actions.names())))
    base_group.add_option("-o", "--origins",
                          action="store",
                          type="string",
                          dest="origins_fn",
                          default=sh.joinpths(settings.ORIGINS_DIR, 'master.yaml'),
                          metavar="FILE",
                          help="yaml file describing where to get openstack sources "
                               "from (default: %default)")
    base_group.add_option("--origins-patch",
                          action="store",
                          type="string",
                          dest="origins_patch_fn",
                          default=None,
                          metavar="FILE",
                          help="origins file patch, jsonpath format (rfc6902)")
    base_group.add_option("--distros-patch",
                          action="store",
                          type="string",
                          dest="distros_patch_fn",
                          default=None,
                          metavar="FILE",
                          help="distros file patch, jsonpath format (rfc6902)")
    base_group.add_option("-j", "--jobs",
                          action="store",
                          type="int",
                          dest="jobs",
                          default=multiprocessing.cpu_count() + 1,
                          metavar="JOBS",
                          help="number of building jobs to run simultaneously (default: %default)")
    base_group.add_option("-d", "--directory",
                          action="store",
                          type="string",
                          dest="dir",
                          metavar="DIR",
                          default=_get_default_dir(),
                          help=("empty root DIR or DIR with existing components (default: %default)"))
    parser.add_option_group(base_group)

    build_group = OptionGroup(parser, "Build specific options")
    build_group.add_option('-u', "--usr-only",
                           action="store_true",
                           dest="usr_only",
                           default=False,
                           help=("when packaging only store /usr directory"
                                 " (default: %default)"))
    build_group.add_option("--venv-deploy-dir",
                           action="store",
                           type="string",
                           dest="venv_deploy_dir",
                           default=None,
                           help=("for virtualenv builds, make the virtualenv "
                                 "relocatable to a directory different from "
                                 "build directory"))
    parser.add_option_group(build_group)

    # Extract only what we care about, these will be passed
    # to the constructor of actions as arguments
    # so don't adjust the naming wily nilly...
    if previous_settings:
        parser.set_defaults(**previous_settings)

    (options, _args) = parser.parse_args()
    values = {}
    values['dir'] = (options.dir or "")
    values['action'] = (options.action or "")
    values['jobs'] = options.jobs
    values['persona_fn'] = options.persona_fn
    values['origins_fn'] = options.origins_fn
    values['verbose'] = options.verbose
    values['usr_only'] = options.usr_only
    if options.origins_patch_fn:
        with open(options.origins_patch_fn) as fp:
            values['origins_patch'] = json.load(fp)
    if options.distros_patch_fn:
        with open(options.distros_patch_fn) as fp:
            values['distros_patch'] = json.load(fp)
    values['venv_deploy_dir'] = options.venv_deploy_dir
    return values
Example #9
0
def parse(previous_settings=None):

    version_str = "%s v%s" % ("anvil", version.version_string())
    help_formatter = SmithyHelpFormatter(width=120)
    parser = OptionParser(version=version_str, formatter=help_formatter, prog="smithy")

    # Root options
    parser.add_option(
        "-v", "--verbose", action="store_true", dest="verbose", default=False, help="make the output logging verbose"
    )
    parser.add_option(
        "--dryrun",
        action="store_true",
        dest="dryrun",
        default=False,
        help=("perform ACTION but do not actually run any of the commands" " that would normally complete ACTION"),
    )
    parser.add_option(
        "-k",
        "--keyring",
        action="store",
        dest="keyring_path",
        default="/etc/anvil/passwords.cfg",
        help=("read and create passwords using this keyring file (default: %default)"),
    )
    parser.add_option(
        "-e",
        "--encrypt",
        action="store_true",
        dest="keyring_encrypted",
        default=False,
        help=("use a encrypted keyring file (default: %default)"),
    )
    parser.add_option(
        "--no-prompt-passwords",
        action="store_false",
        dest="prompt_for_passwords",
        default=True,
        help="do not prompt the user for passwords",
    )
    parser.add_option(
        "--no-store-passwords",
        action="store_false",
        dest="store_passwords",
        default=True,
        help="do not save the users passwords into the users keyring",
    )

    # Install/start/stop/uninstall specific options
    base_group = OptionGroup(parser, "Action specific options")
    base_group.add_option(
        "-p",
        "--persona",
        action="store",
        type="string",
        dest="persona_fn",
        default=sh.joinpths(settings.PERSONA_DIR, "in-a-box", "basic.yaml"),
        metavar="FILE",
        help="persona yaml file to apply (default: %default)",
    )
    base_group.add_option(
        "-a",
        "--action",
        action="store",
        type="string",
        dest="action",
        metavar="ACTION",
        help="required action to perform: %s" % (_format_list(actions.names())),
    )
    base_group.add_option(
        "-o",
        "--origins",
        action="store",
        type="string",
        dest="origins_fn",
        default=sh.joinpths(settings.ORIGINS_DIR, "master.yaml"),
        metavar="FILE",
        help="yaml file describing where to get openstack sources " "from (default: %default)",
    )
    base_group.add_option(
        "-j",
        "--jobs",
        action="store",
        type="int",
        dest="jobs",
        default=multiprocessing.cpu_count() + 1,
        metavar="JOBS",
        help="number of building jobs to run simultaneously (default: %default)",
    )
    base_group.add_option(
        "-d",
        "--directory",
        action="store",
        type="string",
        dest="dir",
        metavar="DIR",
        default=_get_default_dir(),
        help=("empty root DIR or DIR with existing components (default: %default)"),
    )
    parser.add_option_group(base_group)

    suffixes = (
        "Known suffixes 'K' (kilobyte, 1024),"
        " 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)"
        " are supported, 'B' is the default and is ignored"
    )
    status_group = OptionGroup(parser, "Status specific options")
    status_group.add_option(
        "-s",
        "--show",
        action="callback",
        dest="show_amount",
        type="string",
        metavar="SIZE",
        callback=_size_cb,
        help="show SIZE 'details' when showing component status. " + suffixes,
    )
    parser.add_option_group(status_group)

    build_group = OptionGroup(parser, "Build specific options")
    build_group.add_option(
        "-u",
        "--usr-only",
        action="store_true",
        dest="usr_only",
        default=False,
        help=("when packaging only store /usr directory" " (default: %default)"),
    )
    parser.add_option_group(build_group)

    test_group = OptionGroup(parser, "Test specific options")
    test_group.add_option(
        "-i",
        "--ignore-failures",
        action="store_true",
        dest="ignore_test_failures",
        default=False,
        help=("when running tests ignore component test failures" " (default: %default)"),
    )
    parser.add_option_group(test_group)

    # Extract only what we care about, these will be passed
    # to the constructor of actions as arguments
    # so don't adjust the naming wily nilly...
    if previous_settings:
        parser.set_defaults(**previous_settings)

    (options, _args) = parser.parse_args()
    values = {}
    values["dir"] = options.dir or ""
    values["dryrun"] = options.dryrun or False
    values["action"] = options.action or ""
    values["jobs"] = options.jobs
    values["persona_fn"] = options.persona_fn
    values["origins_fn"] = options.origins_fn
    values["verbose"] = options.verbose
    values["usr_only"] = options.usr_only
    values["prompt_for_passwords"] = options.prompt_for_passwords
    values["show_amount"] = max(0, options.show_amount)
    values["store_passwords"] = options.store_passwords
    values["keyring_path"] = options.keyring_path
    values["keyring_encrypted"] = options.keyring_encrypted
    values["ignore_test_failures"] = options.ignore_test_failures
    return values