コード例 #1
0
ファイル: shell.py プロジェクト: jmikedupont/satori
def main(argv=None):
    """Discover an existing configuration for a network location."""
    config = parse_args(argv)
    common_logging.init_logging(config)

    if not (config['format'] == 'json'
            or check_format(config['format'] or "text")):
        sys.exit("Output format file (%s) not found or accessible. Try "
                 "specifying raw JSON format using `--format json`" %
                 get_template_path(config['format']))

    try:
        results, errors = discovery.run(config['netloc'],
                                        config,
                                        interactive=True)
        print(
            format_output(config['netloc'],
                          results,
                          template_name=config['format']))
        if errors:
            sys.stderr.write(format_errors(errors, config))
    except Exception as exc:  # pylint: disable=W0703
        if config['debug']:
            LOG.exception(exc)
        return str(exc)

    sys.exit(0)
コード例 #2
0
ファイル: shell.py プロジェクト: gondoi/satori
def main(argv=None):
    """Discover an existing configuration for a network location."""
    config = parse_args(argv)
    common_logging.init_logging(config)

    if not (config.format == 'json' or check_format(config.format or "text")):
        sys.exit("Output format file (%s) not found or accessible. Try "
                 "specifying raw JSON format using `--format json`" %
                 get_template_path(config.format))

    try:
        results = discovery.run(config.netloc, config, interactive=True)
        print(format_output(config.netloc, results,
                            template_name=config.format))
    except Exception as exc:  # pylint: disable=W0703
        if config.debug:
            LOG.exception(exc)
        return str(exc)

    sys.exit(0)
コード例 #3
0
def main():
    """Discover an existing configuration for a network location."""
    parser = argparse.ArgumentParser(description='Configuration discovery.')
    parser.add_argument(
        'netloc',
        help='Network location. E.g. https://domain.com, sub.domain.com, or '
        '4.3.2.1')
    openstack_group = parser.add_argument_group(
        'OpenStack Settings',
        'Cloud credentials, settings and endpoints. If a network location is '
        'found to be hosted on the tenant additional information is provided.')

    openstack_group.add_argument(
        '--os-username',
        dest='username',
        default=os.environ.get('OS_USERNAME'),
        help='OpenStack Auth username. Defaults to env[OS_USERNAME].')
    openstack_group.add_argument(
        '--os-password',
        dest='password',
        default=os.environ.get('OS_PASSWORD'),
        help='OpenStack Auth password. Defaults to env[OS_PASSWORD].')
    openstack_group.add_argument(
        '--os-region-name',
        dest='region',
        default=os.environ.get('OS_REGION_NAME'),
        help='OpenStack region. Defaults to env[OS_REGION_NAME].')
    openstack_group.add_argument(
        '--os-auth-url',
        dest='authurl',
        default=os.environ.get('OS_AUTH_URL'),
        help='OpenStack Auth endpoint. Defaults to env[OS_AUTH_URL].')
    openstack_group.add_argument(
        '--os-compute-api-version',
        dest='compute_api_version',
        default=os.environ.get('OS_COMPUTE_API_VERSION', '1.1'),
        help='OpenStack Compute API version. Defaults to '
        'env[OS_COMPUTE_API_VERSION] or 1.1.')

    # Tenant name or ID can be supplied
    tenant_group = openstack_group.add_mutually_exclusive_group()
    tenant_group.add_argument(
        '--os-tenant-name',
        dest='tenant_name',
        default=os.environ.get('OS_TENANT_NAME'),
        help='OpenStack Auth tenant name. Defaults to env[OS_TENANT_NAME].')
    tenant_group.add_argument(
        '--os-tenant-id',
        dest='tenant_id',
        default=os.environ.get('OS_TENANT_ID'),
        help='OpenStack Auth tenant ID. Defaults to env[OS_TENANT_ID].')

    parser.add_argument('--host-key-path',
                        type=argparse.FileType('r'),
                        help='SSH key to access Nova resources.')

    parser.add_argument(
        '--system-info',
        help='Mechanism to use on a Nova resource to obtain system '
        'information. E.g. ohai, facts, factor.')

    args = parser.parse_args()

    if args.host_key_path:
        args.host_key = args.host_key_path.read()

    # argparse lacks a method to say "if this option is set, require these too"
    required_to_access_cloud = [
        args.username,
        args.password,
        args.authurl,
        args.region,
        args.tenant_name or args.tenant_id,
    ]
    if args.username and not all(required_to_access_cloud):
        parser.error("To connect to an OpenStack cloud you must supply a "
                     "username, password, authentication enpoind, region and "
                     "tenant. Either provide all of these settings or none of "
                     "them.")

    results = discovery.run(args.netloc, args)
    output_results(args.netloc, results)
    return 0
コード例 #4
0
ファイル: shell.py プロジェクト: calebgroom/satori
def main():
    """Discover an existing configuration for a network location."""
    parser = argparse.ArgumentParser(description='Configuration discovery.')
    parser.add_argument(
        'netloc',
        help='Network location. E.g. https://domain.com, sub.domain.com, or '
             '4.3.2.1'
    )
    openstack_group = parser.add_argument_group(
        'OpenStack Settings',
        'Cloud credentials, settings and endpoints. If a network location is '
        'found to be hosted on the tenant additional information is provided.'
    )

    openstack_group.add_argument(
        '--os-username',
        dest='username',
        default=os.environ.get('OS_USERNAME'),
        help='OpenStack Auth username. Defaults to env[OS_USERNAME].'
    )
    openstack_group.add_argument(
        '--os-password',
        dest='password',
        default=os.environ.get('OS_PASSWORD'),
        help='OpenStack Auth password. Defaults to env[OS_PASSWORD].'
    )
    openstack_group.add_argument(
        '--os-region-name',
        dest='region',
        default=os.environ.get('OS_REGION_NAME'),
        help='OpenStack region. Defaults to env[OS_REGION_NAME].'
    )
    openstack_group.add_argument(
        '--os-auth-url',
        dest='authurl',
        default=os.environ.get('OS_AUTH_URL'),
        help='OpenStack Auth endpoint. Defaults to env[OS_AUTH_URL].'
    )
    openstack_group.add_argument(
        '--os-compute-api-version',
        dest='compute_api_version',
        default=os.environ.get('OS_COMPUTE_API_VERSION', '1.1'),
        help='OpenStack Compute API version. Defaults to '
             'env[OS_COMPUTE_API_VERSION] or 1.1.'
    )

    # Tenant name or ID can be supplied
    tenant_group = openstack_group.add_mutually_exclusive_group()
    tenant_group.add_argument(
        '--os-tenant-name',
        dest='tenant_name',
        default=os.environ.get('OS_TENANT_NAME'),
        help='OpenStack Auth tenant name. Defaults to env[OS_TENANT_NAME].'
    )
    tenant_group.add_argument(
        '--os-tenant-id',
        dest='tenant_id',
        default=os.environ.get('OS_TENANT_ID'),
        help='OpenStack Auth tenant ID. Defaults to env[OS_TENANT_ID].'
    )

    args = parser.parse_args()

    # argparse lacks a method to say "if this option is set, require these too"
    required_to_access_cloud = [
        args.username,
        args.password,
        args.authurl,
        args.region,
        args.tenant_name or args.tenant_id,
    ]
    if args.username and not all(required_to_access_cloud):
        parser.error("To connect to an OpenStack cloud you must supply a "
                     "username, password, authentication enpoind, region and "
                     "tenant. Either provide all of these settings or none of "
                     "them.")

    results = discovery.run(args.netloc, args)
    output_results(args.netloc, results)
    return 0