本文整理汇总了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)
示例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)
示例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))
示例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)
示例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
示例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)
示例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