本文整理汇总了Python中jnpr.junos.utils.config.Config.rescue方法的典型用法代码示例。如果您正苦于以下问题:Python Config.rescue方法的具体用法?Python Config.rescue怎么用?Python Config.rescue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jnpr.junos.utils.config.Config
的用法示例。
在下文中一共展示了Config.rescue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestConfig
# 需要导入模块: from jnpr.junos.utils.config import Config [as 别名]
# 或者: from jnpr.junos.utils.config.Config import rescue [as 别名]
#.........这里部分代码省略.........
def test_config_lock_exception(self, mock_jxml):
class MyException(Exception):
xml = 'test'
self.conf.rpc.lock_configuration = MagicMock(side_effect=MyException)
self.assertRaises(LockError, self.conf.lock)
def test_config_unlock(self):
self.conf.rpc.unlock_configuration = MagicMock()
self.assertTrue(self.conf.unlock())
@patch('jnpr.junos.utils.config.JXML.rpc_error')
def test_config_unlock_LockError(self, mock_jxml):
ex = RpcError(rsp='ok')
self.conf.rpc.unlock_configuration = MagicMock(side_effect=ex)
self.assertRaises(UnlockError, self.conf.unlock)
@patch('jnpr.junos.utils.config.JXML.remove_namespaces')
def test_config_unlock_exception(self, mock_jxml):
class MyException(Exception):
xml = 'test'
self.conf.rpc.unlock_configuration = MagicMock(side_effect=MyException)
self.assertRaises(UnlockError, self.conf.unlock)
def test_config_rollback(self):
self.conf.rpc.load_configuration = MagicMock()
self.assertTrue(self.conf.rollback())
def test_config_rollback_exception(self):
self.conf.rpc.load_configuration = MagicMock()
self.assertRaises(ValueError, self.conf.rollback, 51)
self.assertRaises(ValueError, self.conf.rollback, -1)
@patch('jnpr.junos.Device.execute')
def test_rescue_action_save(self, mock_exec):
self.dev.request_save_rescue_configuration = MagicMock()
self.assertTrue(self.conf.rescue('save'))
@patch('jnpr.junos.Device.execute')
def test_rescue_action_get_exception(self, mock_exec):
self.dev.rpc.get_rescue_information = MagicMock(side_effect=Exception)
self.assertTrue(self.conf.rescue('get') is None)
@patch('jnpr.junos.Device.execute')
def test_rescue_action_get(self, mock_exec):
self.dev.rpc.get_rescue_information = MagicMock()
self.dev.rpc.get_rescue_information.return_value = 1
self.assertEqual(self.conf.rescue('get', format='xml'), 1)
@patch('jnpr.junos.Device.execute')
def test_rescue_action_delete(self, mock_exec):
self.dev.rpc.request_delete_rescue_configuration = MagicMock()
self.assertTrue(self.conf.rescue('delete'))
@patch('jnpr.junos.Device.execute')
def test_rescue_action_reload(self, mock_exec):
self.dev.rpc.load_configuration = MagicMock()
self.dev.rpc.load_configuration.return_value = True
self.assertTrue(self.conf.rescue('reload'))
@patch('jnpr.junos.Device.execute')
def test_rescue_action_reload_exception(self, mock_exec):
self.dev.rpc.load_configuration = MagicMock(side_effect=Exception)
self.assertFalse(self.conf.rescue('reload'))
@patch('jnpr.junos.Device.execute')
def test_rescue_action_unsupported_action(self, mock_exec):
示例2: TestConfig
# 需要导入模块: from jnpr.junos.utils.config import Config [as 别名]
# 或者: from jnpr.junos.utils.config.Config import rescue [as 别名]
#.........这里部分代码省略.........
def test_config_lock_exception(self, mock_jxml):
class MyException(Exception):
xml = 'test'
self.conf.rpc.lock_configuration = MagicMock(side_effect=MyException)
self.assertRaises(LockError, self.conf.lock)
def test_config_unlock(self):
self.conf.rpc.unlock_configuration = MagicMock()
self.assertTrue(self.conf.unlock())
@patch('jnpr.junos.utils.config.JXML.rpc_error')
def test_config_unlock_LockError(self, mock_jxml):
ex = RpcError(rsp='ok')
self.conf.rpc.unlock_configuration = MagicMock(side_effect=ex)
self.assertRaises(UnlockError, self.conf.unlock)
@patch('jnpr.junos.utils.config.JXML.remove_namespaces')
def test_config_unlock_exception(self, mock_jxml):
class MyException(Exception):
xml = 'test'
self.conf.rpc.unlock_configuration = MagicMock(side_effect=MyException)
self.assertRaises(UnlockError, self.conf.unlock)
def test_config_rollback(self):
self.conf.rpc.load_configuration = MagicMock()
self.assertTrue(self.conf.rollback())
def test_config_rollback_exception(self):
self.conf.rpc.load_configuration = MagicMock()
self.assertRaises(ValueError, self.conf.rollback, 51)
self.assertRaises(ValueError, self.conf.rollback, -1)
@patch('jnpr.junos.Device.execute')
def test_rescue_action_save(self, mock_exec):
self.dev.request_save_rescue_configuration = MagicMock()
self.assertTrue(self.conf.rescue('save'))
@patch('jnpr.junos.Device.execute')
def test_rescue_action_get_exception(self, mock_exec):
self.dev.rpc.get_rescue_information = MagicMock(side_effect=Exception)
self.assertTrue(self.conf.rescue('get') is None)
@patch('jnpr.junos.Device.execute')
def test_rescue_action_get(self, mock_exec):
self.dev.rpc.get_rescue_information = MagicMock()
self.dev.rpc.get_rescue_information.return_value = 1
self.assertEqual(self.conf.rescue('get', format='xml'), 1)
@patch('jnpr.junos.Device.execute')
def test_rescue_action_delete(self, mock_exec):
self.dev.rpc.request_delete_rescue_configuration = MagicMock()
self.assertTrue(self.conf.rescue('delete'))
@patch('jnpr.junos.Device.execute')
def test_rescue_action_reload(self, mock_exec):
self.dev.rpc.load_configuration = MagicMock()
self.dev.rpc.load_configuration.return_value = True
self.assertTrue(self.conf.rescue('reload'))
@patch('jnpr.junos.Device.execute')
def test_rescue_action_reload_exception(self, mock_exec):
self.dev.rpc.load_configuration = MagicMock(side_effect=Exception)
self.assertFalse(self.conf.rescue('reload'))
@patch('jnpr.junos.Device.execute')
def test_rescue_action_unsupported_action(self, mock_exec):
示例3: run
# 需要导入模块: from jnpr.junos.utils.config import Config [as 别名]
# 或者: from jnpr.junos.utils.config.Config import rescue [as 别名]
def run(self):
# import pdb; pdb.set_trace() # dbg
dev = Device(host=self.host, user=self.user, password=self.passw)
try:
dev.open(auto_probe=7)
except:
self.result += "Could not connect to host\n"
return
if not self.mode:
self.result += "A mode of operation must be specified"
elif self.mode == "configure":
confc = Config(dev)
if self.action == "commit":
self.result += confc.commit(confirm=True, comment="Commited " + str( datetime.datetime.now() ) + " by jCnC")
elif self.action == "commit_check":
if confc.commit_check():
self.result += "Commit Check Succeeds"
else:
self.result += "Commit Check Failed"
elif self.action == "diff":
x = int(self.param)
self.result += confc.diff() #self.param)
elif self.action == "load":
self.result += confc.load(path=param, overwrite=True, format='conf')
elif self.action == "lock":
self.result += confc.lock()
elif self.action == "rescue":
self.result += confc.rescue(param)
elif self.action == "rollback":
self.result += confc.rollback(param)
elif self.action == "save":
shell = self.start_shell()
stdin, stdout, stderr = shell.exec_command("cli show configuration | cat")
config = ""
for line in stdout.readlines():
self.result += line
config += line
## check for host dir, create if not found
hostpath = self.host
if not os.path.exists(hostpath):
os.makedirs(hostpath)
hostpath += "/configuration"
## copy file into directory
with open(hostpath, 'w') as output:
output.write(config)
shell.exec_command("rm /tmp/configuration\n")
shell.close
elif self.action == "unlock":
self.result += confc.unlock()
else:
self.result += "Configuration Action not found"
elif self.mode == "software":
softw = SW(dev)
if self.action == "install":
hash = str('')
with open(param+'.md5') as hashfile:
hash = hashfile.read()
hashfile.closed()
self.action += softw.install(param, remote_path='/var/tmp', progress=dev, validate=False, checksum=hash, cleanfs=False, no_copy=False, timout=1800)
elif action == "rollback":
self.action += softw.rollback()
elif self.mode == "cli":
shell = self.start_shell()
if self.action == "terminal":
stdin, stdout, stderr = shell.exec_command("cli")
stdin.write(self.param + '\n')
stdin.write("exit\n")
stdin.flush()
for line in stdout.readlines():
self.result += line
elif self.action == "file":
self.result += "\n"
stdin, stdout, stderr = shell.exec_command("cli")
cfile = open(self.param, 'r')
for line in cfile:
stdin.write(line + '\n')
stdin.write("exit\n")
data = stdout.readlines()
for line in data:
self.result += "\n" + line
shell.close()
elif self.mode == "info":
shell = self.start_shell()
if self.action == "alarms":
stdin, stdout, stderr = shell.exec_command("cli show chassis alarms")
data = stdout.readlines()
for line in data:
self.result += line
elif self.action == "active_ports":
stdin, stdout, stderr = shell.exec_command('cli show interfaces terse | grep -v "\.0" | grep -v down')
data = stdout.readlines()
for line in data:
self.result += line
elif self.action == "inactive_ports":
stdin, stdout, stderr = shell.exec_command('cli show interfaces terse | grep -v "\.0" | grep down')
data = stdout.readlines()
for line in data:
self.result += line
else:
#.........这里部分代码省略.........