本文整理汇总了Python中netmiko.ConnectHandler.exit_config_mode方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectHandler.exit_config_mode方法的具体用法?Python ConnectHandler.exit_config_mode怎么用?Python ConnectHandler.exit_config_mode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netmiko.ConnectHandler
的用法示例。
在下文中一共展示了ConnectHandler.exit_config_mode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
password = getpass()
py_router_2 = {
'device_type':'cisco_ios',
'ip':'50.76.53.27',
'username':'pyclass',
'password':password,
'port':8022,
}
rtr2 = ConnectHandler(**py_router_2)
rtr2.config_mode()
output = rtr2.check_config_mode()
print "RTR Config mode is %s" % output
if (output is True):
#config_command = ['loggin buffered 5555']
#output = rtr2.send_config_set(config_command)
output = rtr2.send_config_from_file(config_file='config_file.txt')
print "Changes send to router.\n %s" % output
rtr2.exit_config_mode()
else:
print "Could not get to config mode.\n"
示例2: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
rlist = [pynet1, pynet2]
for router in rlist:
rtr = ConnectHandler(**router)
rtr.config_mode()
rtr.send_config_from_file(config_file='configfile.txt')
rtr.exit_config_mode()
示例3: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
'''Main function, opens connection, enters config mode, changes logging
and verifies'''
pynet_rtr2 = ConnectHandler(**RTR2)
pynet_rtr2.config_mode()
if pynet_rtr2.check_config_mode():
pynet_rtr2.send_command("logging buffered 16384")
pynet_rtr2.exit_config_mode()
output = pynet_rtr2.send_command("show run | include logging buff")
print output
else:
print "We are NOT in Config mode"
示例4: setup_module
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def setup_module(module):
module.EXPECTED_RESPONSES = {
'base_prompt' : 'openstack-rb5',
'config_mode' : '(config)',
}
net_connect = ConnectHandler(**brocade_vdx)
# Enter enable mode
module.prompt_initial = net_connect.find_prompt()
net_connect.enable()
module.enable_prompt = net_connect.find_prompt()
# Send a set of config commands
module.config_mode = net_connect.config_mode()
config_commands = ['logging raslog console WARNING', 'interface vlan 20', 'banner motd test_message']
net_connect.send_config_set(config_commands)
# Exit config mode
module.exit_config_mode = net_connect.exit_config_mode()
# Verify config changes
module.config_commands_output = net_connect.send_command('show vlan brief')
net_connect.disconnect()
示例5: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
# Definition of rtr2.
rtr2 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 8022,
}
# Log into router.
net_connect = ConnectHandler(**rtr2)
# Check current logging buffer size.
output = net_connect.send_command("show run | inc buffered")
print
print "Initial logging buffer size: " + output
# Enter config mode, change logging buffer size, exit config mode.
output = net_connect.config_mode()
output = net_connect.send_command("logging buffer 64000")
output = net_connect.exit_config_mode()
# Check logging buffer size again.
output = net_connect.send_command("show run | inc buffered")
print "Final logging buffer size: " + output
print
示例6: setup_module
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def setup_module(module):
module.EXPECTED_RESPONSES = {
'enable_prompt' : 'n7k1#',
'base_prompt' : 'n7k1',
'interface_ip' : '10.3.3.245',
'config_mode' : '(config)'
}
show_ver_command = 'show version'
module.basic_command = 'show ip int brief'
net_connect = ConnectHandler(**cisco_nxos)
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()
module.config_mode = net_connect.config_mode()
config_commands = ['logging monitor 3', 'logging monitor 7', 'no logging console']
net_connect.send_config_set(config_commands)
module.exit_config_mode = net_connect.exit_config_mode()
module.config_commands_output = net_connect.send_command("show run | inc 'logging monitor'")
net_connect.disconnect()
示例7: setup_module
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def setup_module(module):
module.EXPECTED_RESPONSES = {
'enable_prompt' : 'xe-test-rtr#',
'base_prompt' : 'xe-test-rtr',
'interface_ip' : '172.30.0.167',
'config_mode' : '(config)',
}
show_ver_command = 'show version'
module.basic_command = 'show ip int brief'
net_connect = ConnectHandler(**cisco_xe)
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()
module.config_mode = net_connect.config_mode()
config_commands = ['logging buffered 20000', 'logging buffered 20010', 'no logging console']
net_connect.send_config_set(config_commands)
module.exit_config_mode = net_connect.exit_config_mode()
module.config_commands_output = net_connect.send_command('show run | inc logging buffer')
net_connect.disconnect()
示例8: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
pynet2 = {
'device_type': 'cisco_ios',
'ip' : '50.76.53.27',
'username' : 'pyclass',
'port' : 8022,
'password' : '88newclass'
}
pynet_rtr2 = ConnectHandler(**pynet2)
pynet_rtr2.config_mode()
if pynet_rtr2.check_config_mode():
print "We're in config mode"
else:
print "Nope, We're NOT in config mode"
print pynet_rtr2.find_prompt()
pynet_rtr2.exit_config_mode()
print pynet_rtr2.find_prompt()
示例9: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
device_list = getConfig()
for device in device_list:
print "Please input password for: " + device.get('rtr_name')
device['password']=getpass()
device.pop("rtr_name",None)
conn=ConnectHandler(**device)
conn.config_mode()
if (conn.check_config_mode):
print "In config"
conn.exit_config_mode()
print "Arp table\n" + conn.send_command("sh arp")
if ('cisco_ios' in device.get('device_type')):
config_commands = ["do show run | i buffered","logging buffered 12000","do sh run | i buffered"]
output = conn.send_config_set(config_commands)
print output
output = conn.send_config_from_file(config_file='config_file.txt')
print output
开发者ID:pmusolino-rms,项目名称:Network-Automation-with-Python-and-Ansible-class,代码行数:20,代码来源:netmiko_connect.py
示例10: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
password = getpass()
py_router_2 = {
'device_type':'cisco_ios',
'ip':'50.76.53.27',
'username':'pyclass',
'password':password,
'port':8022,
}
rtr2 = ConnectHandler(**py_router_2)
rtr2.config_mode()
output = rtr2.check_config_mode()
print "RTR Config mode is %s" % output
rtr2.exit_config_mode()
示例11: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
'''
Use Netmiko to change the logging buffer size (logging buffered <size>) on pynet-rtr2
'''
ip_address = raw_input("Enter IP address: ")
password = getpass()
pynet_rtr2['ip'] = ip_address
pynet_rtr2['password'] = password
ssh_conn = ConnectHandler(**pynet_rtr2)
ssh_conn.config_mode()
if ssh_conn.check_config_mode:
ssh_conn.send_command('logging buffered 999999')
ssh_conn.exit_config_mode()
output = ssh_conn.send_command('show run | in logging')
print output
示例12: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
username = 'pyclass'
password = '88newclass'
pynet1 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': username,
'password': password,
'port': 22,
}
pynet2 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': username,
'password': password,
'port': 8022,
}
juniper_srx = {
'device_type': 'juniper',
'ip': '50.76.53.27',
'username': username,
'password': password,
'secret': '',
'port': 9822,
}
pynet_rtr2 = ConnectHandler( **pynet2 )
pynet_rtr2.config_mode()
out_2 = pynet_rtr2.send_command( "logging buffered 1234567" )
pynet_rtr2.exit_config_mode()
out_2 = pynet_rtr2.send_command( "show logging" )
print
print "-----------------------------------------------------------------------------"
print "Logging setting on pynet rtr 2"
print out_2
print "-----------------------------------------------------------------------------"
示例13: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
print 'Username:',
usern = raw_input()
passwd = getpass()
for dev in DEVICES:
net_dev = {
'device_type':DEV_TYPE,
'ip':dev,
'username':usern,
'password':passwd
}
# Initiating netmiko connection
net_connect = ConnectHandler(**net_dev)
resp = net_connect.find_prompt()
print resp
# Entering config mode
net_connect.config_mode()
# Verifying we're in config mode
resp = net_connect.check_config_mode()
print 'Entered Config mode? {}'.format(resp)
# Exiting config mode
net_connect.exit_config_mode()
示例14: ssh_conn
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def ssh_conn(**kwargs):
"""SSH to Device and send commands (Threaded)"""
output_q = kwargs['output_q']
sout = []
try:
net_connect = ConnectHandler(device_type=kwargs['Platform'],
ip=kwargs['FQDN'],
username=config['nsj']['username'],
password=config['nsj']['password'])
net_connect.enable()
for s in kwargs['shcmds']:
output = net_connect.send_command(s)
#print(output)
#output = net_connect.send_config_set(cfg_command)
sout.append(output)
if len(kwargs['confcmds']) > 0:
net_connect.config_mode()
for c in kwargs['confcmds']:
output = ""
logging.debug('Sending Command to %s: %s' % (kwargs['Name'], c))
if args.timing:
output = net_connect.send_command_timing(c)
else:
output = net_connect.send_command(c)
sout.append(output)
net_connect.exit_config_mode()
if args.wrmem:
logging.info("Writing Mem on %s" % (kwargs['Name']))
net_connect.send_command("wr")
sleep(20)
net_connect.disconnect()
except Exception as e:
error = 'Error on {}: {}'.format(kwargs['FQDN'], e)
logger.critical(error)
#print('ERROR on ', kwargs['FQDN'], e)
output = ERROR_PATTERN
output_q.put({kwargs['Name']: sout})
示例15: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import exit_config_mode [as 别名]
def main():
# Definition of rtr2.
rtr1 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
}
rtr2 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 8022,
}
# Create a list of all the routers.
all_routers = [rtr1, rtr2]
# Loop through all the routers and show arp.
for a_router in all_routers:
net_connect = ConnectHandler(**a_router)
# Check current logging buffer size.
print "\n>>>>>>>>> Device {0} <<<<<<<<<".format(a_router['device_type'])
output = net_connect.send_command("show run | inc logging")
print "Initial logging config: "
print output
print
# Enter config mode, change logging buffer and console logging from file,
# exit config mode.
output = net_connect.config_mode()
output = net_connect.send_config_from_file(config_file='config_file.txt')
output = net_connect.exit_config_mode()
# Check logging buffer size again.
output = net_connect.send_command("show run | inc logging")
print "Final logging config: "
print output
print ">>>>>>>>> End <<<<<<<<<\n"