Example #1
0
def run_tests(args):
    driver = call_get_network_driver(args.vendor)
    optional_args = helpers.parse_optional_args(args.optional_args)

    device = call_instantiating_object(driver,
                                       args.hostname,
                                       args.user,
                                       password=args.password,
                                       timeout=60,
                                       optional_args=optional_args)

    if args.debug:
        call_pre_connection(device)

    call_open_device(device)

    if args.debug:
        call_connection(device)
        call_facts(device)

    if args.which == 'call':
        method_kwargs = helpers.parse_optional_args(args.method_kwargs)
        call_getter(device, args.method, **method_kwargs)
    elif args.which == 'config':
        configuration_change(device, args.config_file, args.strategy,
                             args.dry_run)
    elif args.which == 'validate':
        call_compliance_report(device, args.validation_file)

    call_close(device)

    if args.debug:
        call_post_connection(device)
Example #2
0
def run(vendor, hostname, user, password, strategy, optional_args, config_file,
        dry_run):

    logger.debug('Getting driver for OS "{driver}"'.format(driver=vendor))
    driver = get_network_driver(vendor)

    optional_args = parse_optional_args(optional_args)
    logger.debug(
        'Connecting to device "{}" with user "{}" and optional_args={}'.format(
            hostname, user, optional_args))
    with driver(hostname, user, password,
                optional_args=optional_args) as device:
        logger.debug(
            'Strategy for loading configuration is "{strategy}"'.format(
                strategy=strategy))
        if strategy == "replace":
            strategy_method = device.load_replace_candidate
        elif strategy == "merge":
            strategy_method = device.load_merge_candidate

        logger.debug(
            'Loading configuration file "{config}"'.format(config=config_file))
        strategy_method(filename=config_file)

        logger.debug("Comparing configuration")
        diff = device.compare_config()

        if dry_run:
            logger.debug("Dry-run. Discarding configuration.")
        else:
            logger.debug("Committing configuration")
            device.commit_config()
        logger.debug("Closing session")
        return diff
Example #3
0
def run(vendor, hostname, user, password, strategy, optional_args, config_file, dry_run):

    logger.debug('Getting driver for OS "{driver}"'.format(driver=vendor))
    driver = get_network_driver(vendor)

    optional_args = parse_optional_args(optional_args)
    logger.debug('Connecting to device "{}" with user "{}" and optional_args={}'.format(
                 hostname, user, optional_args))
    with driver(hostname, user, password, optional_args=optional_args) as device:
        logger.debug('Strategy for loading configuration is "{strategy}"'.format(strategy=strategy))
        if strategy == 'replace':
            strategy_method = device.load_replace_candidate
        elif strategy == 'merge':
            strategy_method = device.load_merge_candidate

        logger.debug('Loading configuration file "{config}"'.format(config=config_file))
        strategy_method(filename=config_file)

        logger.debug('Comparing configuration')
        diff = device.compare_config()

        if dry_run:
            logger.debug('Dry-run. Discarding configuration.')
        else:
            logger.debug('Committing configuration')
            device.commit_config()
        logger.debug('Closing session')
        return diff
Example #4
0
def main():
    args = build_help(validate=True)
    configure_logging(logger, args.debug)

    logger.debug('Getting driver for OS "{driver}"'.format(driver=args.vendor))
    driver = get_network_driver(args.vendor)

    optional_args = parse_optional_args(args.optional_args)
    logger.debug('Connecting to device "{}" with user "{}" and optional_args={}'.format(
                 args.hostname, args.user, optional_args))

    with driver(args.hostname, args.user, args.password, optional_args=optional_args) as device:
        logger.debug('Generating compliance report')
        print(json.dumps(device.compliance_report(args.validation_file), indent=4))
        logger.debug('Closing session')
    sys.exit(0)
Example #5
0
def main():
    warning()
    args = build_help(validate=True)
    configure_logging(logger, args.debug)

    logger.debug('Getting driver for OS "{driver}"'.format(driver=args.vendor))
    driver = get_network_driver(args.vendor)

    optional_args = parse_optional_args(args.optional_args)
    logger.debug('Connecting to device "{}" with user "{}" and optional_args={}'.format(
                 args.hostname, args.user, optional_args))

    with driver(args.hostname, args.user, args.password, optional_args=optional_args) as device:
        logger.debug('Generating compliance report')
        print(json.dumps(device.compliance_report(args.validation_file), indent=4))
        logger.debug('Closing session')
    sys.exit(0)
Example #6
0
def main():
    warning()
    args = build_help(connect_test=True)
    configure_logging(logger, args.debug)

    logger.debug('Getting driver for OS "{driver}"'.format(driver=args.vendor))
    driver = get_network_driver(args.vendor)

    optional_args = parse_optional_args(args.optional_args)
    logger.debug('Connecting to device "{}" with user "{}" and optional_args={}'.format(
                 args.hostname, args.user, optional_args))

    with driver(args.hostname,
                args.user,
                args.password,
                optional_args=optional_args) as device:
        logger.debug('Successfully connected to the device: {}'.format(device.hostname))
        print('Successfully connected to the device')
    sys.exit(0)
Example #7
0
def main():
    args = build_help(connect_test=True)
    configure_logging(logger, args.debug)

    logger.debug('Getting driver for OS "{driver}"'.format(driver=args.vendor))
    driver = get_network_driver(args.vendor)

    optional_args = parse_optional_args(args.optional_args)
    logger.debug(
        'Connecting to device "{}" with user "{}" and optional_args={}'.format(
            args.hostname, args.user, optional_args))

    with driver(args.hostname,
                args.user,
                args.password,
                optional_args=optional_args) as device:
        logger.debug('Successfully connected to the device: {}'.format(
            device.hostname))
        print('Successfully connected to the device')
    sys.exit(0)