本文整理汇总了Python中pyIOSXR.IOSXR类的典型用法代码示例。如果您正苦于以下问题:Python IOSXR类的具体用法?Python IOSXR怎么用?Python IOSXR使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IOSXR类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_open_no_lock
def test_open_no_lock(self, mock_spawn):
'''
Test pyiosxr class open - without lock
Should return None
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
self.assertIsNone(device.open())
开发者ID:mygoda,项目名称:pyiosxr,代码行数:7,代码来源:test.py
示例2: test_load_candidate_config
def test_load_candidate_config(self, mock_rpc, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class load_candidate_config
Should return None
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
device.open()
self.assertIsNone(device.load_candidate_config(config='config'))
开发者ID:runborg,项目名称:pyiosxr,代码行数:9,代码来源:test.py
示例3: test_close_locked
def test_close_locked(self, mock_rpc, mock_lock, mock_close, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class close with lock
Should return None
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=True)
mock_spawn.return_value = None
device.open()
self.assertIsNone(device.close())
开发者ID:runborg,项目名称:pyiosxr,代码行数:9,代码来源:test.py
示例4: test_getattr_AttributeError
def test_getattr_AttributeError(self, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class getattr
Should return AttributeError
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
device.open()
self.assertRaises(AttributeError, getattr, device, 'foo')
开发者ID:runborg,项目名称:pyiosxr,代码行数:9,代码来源:test.py
示例5: test_execute_config_show
def test_execute_config_show(self, mock_rpc, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr helper __execute_config_show__
Should return True
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
device.open()
self.assertTrue(__execute_config_show__(device=device, show_command='show interfaces', timeout=10))
开发者ID:runborg,项目名称:pyiosxr,代码行数:9,代码来源:test.py
示例6: test_commit_config
def test_commit_config(self, mock_rpc, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class commit_config
Should return None
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
device.open()
self.assertIsNone(device.commit_config(label='label', comment='comment', confirmed=30))
开发者ID:runborg,项目名称:pyiosxr,代码行数:9,代码来源:test.py
示例7: test_commit_replace_config_InvalidInputError
def test_commit_replace_config_InvalidInputError(self, mock_rpc, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class commit_replace_config
Should return InvalidInputError
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
device.open()
self.assertRaises(InvalidInputError, device.commit_replace_config, label='label', comment='comment', confirmed=900)
开发者ID:runborg,项目名称:pyiosxr,代码行数:9,代码来源:test.py
示例8: test_rollback
def test_rollback(self, mock_rpc, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class rollback
Should return None
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
device.open()
self.assertIsNone(device.rollback())
开发者ID:mygoda,项目名称:pyiosxr,代码行数:9,代码来源:test.py
示例9: test_open_no_passwd
def test_open_no_passwd(self, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class open - pexpect.EOF
Should return Nona
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
mock_expect.return_value = 3
self.assertIsNone(device.open())
开发者ID:runborg,项目名称:pyiosxr,代码行数:9,代码来源:test.py
示例10: test_make_rpc_call
def test_make_rpc_call(self, mock_rpc, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class make_rpc_call
Should return True
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
mock_rpc.return_value = ElementTree.fromstring('<xml></xml>')
device.open()
self.assertTrue(device.make_rpc_call("<Get><Operational><LLDP><NodeTable></NodeTable></LLDP></Operational></Get>"))
开发者ID:runborg,项目名称:pyiosxr,代码行数:10,代码来源:test.py
示例11: test_get_candidate_config
def test_get_candidate_config(self, mock_show, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class get_candidate_config
Should return True
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
device.open()
mock_show.return_value = '!! IOS XR Configuration'
self.assertTrue(device.get_candidate_config(merge=True, formal=True))
开发者ID:runborg,项目名称:pyiosxr,代码行数:10,代码来源:test.py
示例12: test_getattr_show_config
def test_getattr_show_config(self, mock_show, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class getattr
Should return True
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
device.open()
mock_show.return_value = '!! IOS XR Configuration [email protected]#$ </Exec>'
self.assertTrue(device.show_configuration_merge(config=True))
开发者ID:runborg,项目名称:pyiosxr,代码行数:10,代码来源:test.py
示例13: test_compare_replace_config
def test_compare_replace_config(self, mock_show, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class compare_replace_config
Should return True
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
device.open()
mock_show.return_value = ''
self.assertEqual('', device.compare_replace_config())
开发者ID:runborg,项目名称:pyiosxr,代码行数:10,代码来源:test.py
示例14: test_load_candidate_config_InvalidInputError
def test_load_candidate_config_InvalidInputError(self, mock_rpc, mock_discard, mock_sendline, mock_expect, mock_spawn):
'''
Test pyiosxr class load_candidate_config
Should return InvalidInputError
'''
device = IOSXR(hostname='hostname', username='ejasinska', password='passwd', port=22, timeout=60, logfile=None, lock=False)
mock_spawn.return_value = None
mock_rpc.side_effect = InvalidInputError('error')
device.open()
self.assertRaises(InvalidInputError, device.load_candidate_config, config='config')
开发者ID:runborg,项目名称:pyiosxr,代码行数:10,代码来源:test.py
示例15: __init__
def __init__(self, hostname, username, password):
self.hostname = hostname
self.username = username
self.password = password
self.device = IOSXR(hostname, username, password)
self.pending_changes = False
self.replace = False
开发者ID:coxley,项目名称:napalm,代码行数:7,代码来源:iosxr.py
示例16: __init__
def __init__(self, hostname, username, password, timeout=60, optional_args=None):
self.hostname = hostname
self.username = username
self.password = password
self.timeout = timeout
self.device = IOSXR(hostname, username, password, timeout=timeout)
self.pending_changes = False
self.replace = False
开发者ID:taijiji,项目名称:napalm,代码行数:8,代码来源:iosxr.py
示例17: test_lock_raises_LockError
def test_lock_raises_LockError(self):
"""Tests if DB already locked raises LockError"""
if self.MOCK:
self.assertRaises(
LockError,
self.device.lock
)
self.assertFalse(self.device.locked)
else:
self.device.unlock() # make sure the config is not locked
same_device = IOSXR(self.HOSTNAME,
self.USERNAME,
self.PASSWORD,
port=self.PORT,
lock=self.LOCK,
logfile=self.LOG,
timeout=self.TIMEOUT)
same_device.open()
same_device.lock()
# the other instance locks the config DB
try:
# trying to acquire the config DB
self.device.lock()
except LockError:
self.assertFalse(self.device.locked)
else:
self.assertTrue(self.device.locked)
same_device.close()
开发者ID:courtsmith,项目名称:pyiosxr,代码行数:32,代码来源:test.py
示例18: provision_iosxr
def provision_iosxr(port, username, password):
device = IOSXR(hostname='127.0.0.1', username=username, password=password, port=port)
device.open()
device.load_candidate_config(filename='../iosxr/initial.conf')
try:
device.commit_replace_config()
except pexpect.TIMEOUT:
# This actually means everything went fine
print_info_message()
开发者ID:DiogoAndre,项目名称:napalm,代码行数:10,代码来源:provision.py
示例19: __init__
def __init__(self, hostname, username, password, timeout=60, optional_args=None):
self.hostname = hostname
self.username = username
self.password = password
self.timeout = timeout
self.pending_changes = False
self.replace = False
if optional_args is None:
optional_args = {}
self.port = optional_args.pop('port', 22)
self.device = IOSXR(hostname, username, password, timeout=timeout, port=self.port)
开发者ID:jerry-bonner,项目名称:napalm,代码行数:12,代码来源:iosxr.py
示例20: IOSXRDriver
class IOSXRDriver(NetworkDriver):
def __init__(self, hostname, username, password, timeout=60):
self.hostname = hostname
self.username = username
self.password = password
self.timeout = timeout
self.device = IOSXR(hostname, username, password, timeout=timeout)
self.pending_changes = False
self.replace = False
def open(self):
self.device.open()
def close(self):
self.device.close()
def load_replace_candidate(self, filename=None, config=None):
self.pending_changes = True
self.replace = True
try:
self.device.load_candidate_config(filename=filename, config=config)
except InvalidInputError as e:
self.pending_changes = False
self.replace = False
raise ReplaceConfigException(e.message)
def load_merge_candidate(self, filename=None, config=None):
self.pending_changes = True
self.replace = False
try:
self.device.load_candidate_config(filename=filename, config=config)
except InvalidInputError as e:
self.pending_changes = False
self.replace = False
raise MergeConfigException(e.message)
def compare_config(self):
if not self.pending_changes:
return ''
elif self.replace:
return self.device.compare_replace_config().strip()
else:
return self.device.compare_config().strip()
def commit_config(self):
if self.replace:
self.device.commit_replace_config()
else:
self.device.commit_config()
self.pending_changes = False
def discard_config(self):
self.device.discard_config()
self.pending_changes = False
def rollback(self):
self.device.rollback()
def get_facts(self):
sh_ver = self.device.show_version()
for line in sh_ver.splitlines():
if 'Cisco IOS XR Software' in line:
os_version = line.split()[-1]
elif 'uptime' in line:
uptime = string_parsers.convert_uptime_string_seconds(line)
hostname = line.split()[0]
fqdn = line.split()[0]
elif 'Series' in line:
model = ' '.join(line.split()[1:3])
interface_list = list()
for x in self.device.show_interface_description().splitlines()[3:-1]:
if '.' not in x:
interface_list.append(x.split()[0])
result = {
'vendor': u'Cisco',
'os_version': unicode(os_version),
'hostname': unicode(hostname),
'uptime': uptime,
'model': unicode(model),
'serial_number': u'',
'fqdn': unicode(fqdn),
'interface_list': interface_list,
}
return result
def get_interfaces(self):
# init result dict
result = {}
# fetch show interface output
sh_int = self.device.show_interfaces()
#.........这里部分代码省略.........
开发者ID:t2d,项目名称:napalm,代码行数:101,代码来源:iosxr.py
注:本文中的pyIOSXR.IOSXR类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论