當前位置: 首頁>>代碼示例>>Python>>正文


Python napalm_base.get_network_driver方法代碼示例

本文整理匯總了Python中napalm_base.get_network_driver方法的典型用法代碼示例。如果您正苦於以下問題:Python napalm_base.get_network_driver方法的具體用法?Python napalm_base.get_network_driver怎麽用?Python napalm_base.get_network_driver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在napalm_base的用法示例。


在下文中一共展示了napalm_base.get_network_driver方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import napalm_base [as 別名]
# 或者: from napalm_base import get_network_driver [as 別名]
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) 
開發者ID:napalm-automation,項目名稱:napalm-base,代碼行數:18,代碼來源:cl_napalm_validate.py

示例2: main

# 需要導入模塊: import napalm_base [as 別名]
# 或者: from napalm_base import get_network_driver [as 別名]
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) 
開發者ID:napalm-automation,項目名稱:napalm-base,代碼行數:20,代碼來源:cl_napalm_test.py

示例3: test_get_network_driver

# 需要導入模塊: import napalm_base [as 別名]
# 或者: from napalm_base import get_network_driver [as 別名]
def test_get_network_driver(self, driver):
        """Check that we can get the desired driver and is instance of NetworkDriver."""
        self.assertTrue(issubclass(get_network_driver(driver), NetworkDriver)) 
開發者ID:napalm-automation,項目名稱:napalm-base,代碼行數:5,代碼來源:test_get_network_driver.py

示例4: test_get_wrong_network_driver

# 需要導入模塊: import napalm_base [as 別名]
# 或者: from napalm_base import get_network_driver [as 別名]
def test_get_wrong_network_driver(self, driver):
        """Check that inexisting driver throws ModuleImportError."""
        self.assertRaises(ModuleImportError, get_network_driver, driver, prepend=False) 
開發者ID:napalm-automation,項目名稱:napalm-base,代碼行數:5,代碼來源:test_get_network_driver.py

示例5: run

# 需要導入模塊: import napalm_base [as 別名]
# 或者: from napalm_base import get_network_driver [as 別名]
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 
開發者ID:napalm-automation,項目名稱:napalm-base,代碼行數:30,代碼來源:cl_napalm_configure.py

示例6: _do_init

# 需要導入模塊: import napalm_base [as 別名]
# 或者: from napalm_base import get_network_driver [as 別名]
def _do_init(self):
        config = self.config

        self.host = config.get('host')
        self.user = config.get('user')
        self.password = config.get('password')
        self.optional_args = config.get('driver_args', {})

        if ':' not in config['type']:
            raise ValueError('napalm requires a subtype')

        driver = config['type'].split(':', 2)[1]
        cls = napalm_base.get_network_driver(driver)
        self.dev = cls(self.host, self.user, self.password, optional_args=self.optional_args) 
開發者ID:20c,項目名稱:ngage,代碼行數:16,代碼來源:napalm.py

示例7: init

# 需要導入模塊: import napalm_base [as 別名]
# 或者: from napalm_base import get_network_driver [as 別名]
def init(opts):
    '''
    Opens the connection with the network device.
    '''
    proxy_dict = opts.get('proxy', {})
    NETWORK_DEVICE['HOSTNAME'] = proxy_dict.get('host') or proxy_dict.get('hostname')
    NETWORK_DEVICE['USERNAME'] = proxy_dict.get('username') or proxy_dict.get('user')
    NETWORK_DEVICE['DRIVER_NAME'] = proxy_dict.get('driver') or proxy_dict.get('os')
    NETWORK_DEVICE['PASSWORD'] = proxy_dict.get('passwd') or proxy_dict.get('password') or proxy_dict.get('pass')
    NETWORK_DEVICE['TIMEOUT'] = proxy_dict.get('timeout', 60)
    NETWORK_DEVICE['OPTIONAL_ARGS'] = proxy_dict.get('optional_args', {})

    NETWORK_DEVICE['UP'] = False

    _driver_ = napalm_base.get_network_driver(NETWORK_DEVICE.get('DRIVER_NAME'))
    # get driver object form NAPALM

    if 'config_lock' not in NETWORK_DEVICE['OPTIONAL_ARGS'].keys():
        NETWORK_DEVICE['OPTIONAL_ARGS']['config_lock'] = False

    try:
        NETWORK_DEVICE['DRIVER'] = _driver_(
            NETWORK_DEVICE.get('HOSTNAME', ''),
            NETWORK_DEVICE.get('USERNAME', ''),
            NETWORK_DEVICE.get('PASSWORD', ''),
            timeout=NETWORK_DEVICE['TIMEOUT'],
            optional_args=NETWORK_DEVICE['OPTIONAL_ARGS']
        )
        NETWORK_DEVICE.get('DRIVER').open()
        # no exception raised here, means connection established
        NETWORK_DEVICE['UP'] = True
        DETAILS['initialized'] = True
    except napalm_base.exceptions.ConnectionException as error:
        log.error(
            "Cannot connect to {hostname}{port} as {username}. Please check error: {error}".format(
                hostname=NETWORK_DEVICE.get('HOSTNAME', ''),
                port=(':{port}'.format(port=NETWORK_DEVICE.get('OPTIONAL_ARGS', {}).get('port'))
                      if NETWORK_DEVICE.get('OPTIONAL_ARGS', {}).get('port') else ''),
                username=NETWORK_DEVICE.get('USERNAME', ''),
                error=error
            )
        )

    return True 
開發者ID:napalm-automation,項目名稱:napalm-salt,代碼行數:46,代碼來源:napalm.py


注:本文中的napalm_base.get_network_driver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。