本文整理汇总了Python中netmiko.ConnectHandler.commit方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectHandler.commit方法的具体用法?Python ConnectHandler.commit怎么用?Python ConnectHandler.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netmiko.ConnectHandler
的用法示例。
在下文中一共展示了ConnectHandler.commit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_module
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import commit [as 别名]
def setup_module(module):
module.EXPECTED_RESPONSES = {
'enable_prompt' : 'RP/0/0/CPU0:XRv-1#',
'base_prompt' : 'RP/0/0/CPU0:XRv-1',
'interface_ip' : '169.254.254.181',
'config_mode' : '(config)'
}
show_ver_command = 'show version'
commit_history_cmd = 'show configuration commit list'
module.basic_command = 'show ipv4 int brief'
net_connect = ConnectHandler(**cisco_xr)
module.show_version = net_connect.send_command(show_ver_command)
module.show_ip = net_connect.send_command(module.basic_command)
net_connect.enable()
module.enable_prompt = net_connect.find_prompt()
current_commit_history = net_connect.send_command(commit_history_cmd)
# get the current 10 digit commit Label ID
module.current_commit = current_commit_history.split('\n')[4].split()[1]
module.config_mode = net_connect.config_mode()
config_commands = ['logging monitor warning', 'logging buffered 30720100', 'logging console errors']
net_connect.send_config_set(config_commands)
net_connect.commit()
# get the new 10 digit commit Label ID
new_commit_history = net_connect.send_command(commit_history_cmd)
module.new_commit = new_commit_history.split('\n')[4].split()[1]
module.config_commands_output = net_connect.send_command("show run | inc logging")
net_connect.disconnect()
示例2:
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import commit [as 别名]
Pynet2ExitConfig = Pynet2Connect.exit_config_mode()
JuniperExitConfig = JuniperConnect.exit_config_mode()
print "\n", Pynet1ExitConfig, "\n", Pynet2ExitConfig, "\n", JuniperExitConfig, "\n"
print "Checking interfaces' IPs..."
time.sleep(2)
Pynet1IpInt = Pynet1Connect.send_command('show ip int brief')
Pynet2IpInt = Pynet2Connect.send_command('show ip int brief')
JuniperIpInt = JuniperConnect.send_command('show interfaces terse | match "up up"')
print "\n", Pynet1IpInt, "\n\n", Pynet2IpInt, "\n\n", JuniperIpInt, "\n"
print "Sending a few config commands to the Juniper..."
time.sleep(2)
JuniperConfig = JuniperConnect.config_mode()
JuniperConfigCommands = ['set interfaces vlan unit 0 description "Management Vlan 0"',
'set system host-name pynet-juniper-srx1']
JuniperConfigChange = JuniperConnect.send_config_set(JuniperConfigCommands)
JuniperConfigCheckCommand = ['show | compare']
JuniperConfigChangeCheck = JuniperConnect.send_config_set(JuniperConfigCheckCommand)
print "Displaying the change below...\n"
print JuniperConfigChangeCheck
time.sleep(1)
print "\nCommiting the change..."
JuniperConnect.commit()
time.sleep(60)
示例3: PANOSDriver
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import commit [as 别名]
#.........这里部分代码省略.........
config = content.splitlines()
self._send_merge_commands(config, file_config)
elif config:
file_config = False
self._send_merge_commands(config, file_config)
else:
raise MergeConfigException('You must provide either a file '
'or a set-format string')
def compare_config(self):
"""
Netmiko is being used to obtain config diffs because pan-python
doesn't support the needed command.
"""
if self.ssh_connection is False:
self._open_ssh()
self.ssh_device.exit_config_mode()
diff = self.ssh_device.send_command("show config diff")
return diff.strip()
def _save_backup(self):
self.backup_file = 'config_{0}.xml'.format(str(datetime.now().date()).replace(' ', '_'))
backup_command = '<save><config><to>{0}</to></config></save>'.format(self.backup_file)
self.device.op(cmd=backup_command)
if self.device.status == 'success':
return True
else:
return False
def commit_config(self):
"""
Netmiko is being used to commit the configuration because it takes
a better care of results compared to pan-python.
"""
if self.loaded:
if self.ssh_connection is False:
self._open_ssh()
try:
self.ssh_device.commit()
time.sleep(3)
self.loaded = False
self.changed = True
except: # noqa
if self.merge_config:
raise MergeConfigException('Error while commiting config')
else:
raise ReplaceConfigException('Error while commiting config')
else:
raise ReplaceConfigException('No config loaded.')
def discard_config(self):
if self.loaded:
discard_cmd = '<load><config><from>{0}</from></config></load>'.format(self.backup_file)
self.device.op(cmd=discard_cmd)
if self.device.status == 'success':
self.loaded = False
self.merge_config = False
else:
raise ReplaceConfigException("Error while loading backup config.")
def rollback(self):
示例4: PANOSDriver
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import commit [as 别名]
#.........这里部分代码省略.........
config = content.splitlines()
self._send_merge_commands(config, file_config)
elif config:
file_config = False
self._send_merge_commands(config, file_config)
else:
raise MergeConfigException('You must provide either a file '
'or a set-format string')
def compare_config(self):
"""
Netmiko is being used to obtain config diffs because pan-python
doesn't support the needed command.
"""
if self.ssh_connection is False:
self._open_ssh()
self.ssh_device.exit_config_mode()
diff = self.ssh_device.send_command("show config diff")
return diff.strip()
def _save_backup(self):
self.backup_file = 'config_{0}.xml'.format(str(datetime.now().date()).replace(' ', '_'))
backup_command = '<save><config><to>{0}</to></config></save>'.format(self.backup_file)
self.device.op(cmd=backup_command)
if self.device.status == 'success':
return True
else:
return False
def commit_config(self):
"""
Netmiko is being used to commit the configuration because it takes
a better care of results compared to pan-python.
"""
if self.loaded:
if self.ssh_connection is False:
self._open_ssh()
try:
self.ssh_device.commit()
time.sleep(3)
self.loaded = False
self.changed = True
except:
if self.merge_config:
raise MergeConfigException('Error while commiting config')
else:
raise ReplaceConfigException('Error while commiting config')
else:
raise ReplaceConfigException('No config loaded.')
def discard_config(self):
if self.loaded:
discard_cmd = '<load><config><from>{0}</from></config></load>'.format(self.backup_file)
self.device.op(cmd=discard_cmd)
if self.device.status == 'success':
self.loaded = False
self.merge_config = False
else:
raise ReplaceConfigException("Error while loading backup config.")
def rollback(self):