本文整理汇总了Python中netmiko.ConnectHandler.send_config_set方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectHandler.send_config_set方法的具体用法?Python ConnectHandler.send_config_set怎么用?Python ConnectHandler.send_config_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netmiko.ConnectHandler
的用法示例。
在下文中一共展示了ConnectHandler.send_config_set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def main():
router = {
'device_type': 'cisco_ios',
'ip': '10.9.0.67',
'username': 'myuser',
'password': 'mypass'
}
# Connect to device
device_conn = ConnectHandler(**router)
# Show logging buffered
print "Pre Change Logging Check:"
print device_conn.send_command("show run | in logging")
# To change the logging buffered value
config_commands = ['logging buffered 25000', 'do wr mem']
output = device_conn.send_config_set(config_commands)
print output
# Show logging buffered
print "Post Change Logging Check:"
print device_conn.send_command("show run | in logging")
# Close connection
device_conn.disconnect()
示例2: setup_module
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [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()
示例3: __init__
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
class Router:
def __init__(self):
self.net_connect = ConnectHandler(**homeRTR)
def show_dhcp_binding(self, mac_end):
command = 'show ip dhcp binding | incl ' + mac_end
output = self.net_connect.send_command(command)
# self.net_connect.disconnect()
return output.split('\n')
def ping_ipaddr(self, ipaddr):
command = 'ping ' + ipaddr
output = self.net_connect.send_command(command)
# self.net_connect.disconnect()
return output.split('\n')
def show_arp(self, mac_end):
command = 'show arp | incl ' + mac_end
output = self.net_connect.send_command(command)
# self.net_connect.disconnect()
return output.split('\n')
def add_dhcp_client(self, config_list):
output = self.net_connect.send_config_set(config_list)
return output.split('\n')
def delete_dhcp_client(self, config_list):
output = self.net_connect.send_config_set(config_list)
return output.split('\n')
示例4: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def main():
'''
Use Netmiko to change the logging buffer size on pynet-rtr2.
'''
ip_addr = raw_input("Enter IP address: ")
password = getpass()
# Get connection parameters setup correctly
for a_dict in (pynet1, pynet2, juniper_srx):
a_dict['ip'] = ip_addr
a_dict['password'] = password
a_dict['verbose'] = False
net_connect = ConnectHandler(**pynet2)
config_commands = ['logging buffered 20000']
net_connect.send_config_set(config_commands)
output = net_connect.send_command("show run | i logging buffer")
print
print "Device: {}:{}".format(net_connect.ip, net_connect.port)
print
print output
print
示例5: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def main():
'''
SCP transfer cisco_logging.txt to network device
Use ssh_conn as ssh channel into network device
scp_conn must be closed after file transfer
'''
ssh_conn = ConnectHandler(**cisco_881)
scp_conn = SCPConn(ssh_conn)
s_file = 'cisco_logging.txt'
d_file = 'cisco_logging.txt'
print "\n\n"
scp_conn.scp_transfer_file(s_file, d_file)
scp_conn.close()
output = ssh_conn.send_command("show flash: | inc cisco_logging")
print ">> " + output + '\n'
# Disable file copy confirmation
output = ssh_conn.send_config_set(["file prompt quiet"])
# Execute config merge
print "Performing config merge\n"
output = ssh_conn.send_command("copy flash:cisco_logging.txt running-config")
# Verify change
print "Verifying logging buffer change"
output = ssh_conn.send_command("show run | inc logging buffer")
print ">> " + output + '\n'
# Restore copy confirmation
output = ssh_conn.send_config_set(["file prompt alert"])
示例6: setup_module
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [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()
示例7: setup_module
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [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()
示例8: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def main():
'''
Ansible module to perform config merge on Cisco IOS devices.
'''
module = AnsibleModule(
argument_spec=dict(
host=dict(required=True),
port=dict(default=22, required=False),
username=dict(required=True),
password=dict(required=True),
merge_file=dict(required=True),
dest_file_system=dict(default='flash:', required=False),
),
supports_check_mode=False
)
net_device = {
'device_type': 'cisco_ios',
'ip': module.params['host'],
'username': module.params['username'],
'password': module.params['password'],
'port': int(module.params['port']),
'verbose': False,
}
ssh_conn = ConnectHandler(**net_device)
ssh_conn.enable()
merge_file = module.params['merge_file']
dest_file_system = module.params['dest_file_system']
# Disable file copy confirmation
ssh_conn.send_config_set(['file prompt quiet'])
# Perform configure replace
cmd = "configure replace {0}{1}".format(dest_file_system, merge_file)
output = ssh_conn.send_command(cmd, delay_factor=8)
# Enable file copy confirmation
ssh_conn.send_config_set(['file prompt alert'])
if 'The rollback configlet from the last pass is listed below' in output:
module.exit_json(msg="The new configuration has been loaded successfully",
changed=True)
else:
module.fail_json(msg="Unexpected failure during attempted configure replace. "
"Please verify the current configuration of the network device.")
示例9: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def main():
"""Exercises using Netmiko"""
# 99saturday
sw1_pass = getpass("Enter switch password: ")
pynet_sw1 = {
'device_type': 'arista_eos',
'ip': '184.105.247.72',
'username': 'admin1',
'password': sw1_pass,
}
cfg_commands = [
'vlan 901',
'name red',
]
net_connect = ConnectHandler(**pynet_sw1)
print "Current Prompt: " + net_connect.find_prompt()
print "\nConfiguring VLAN"
print "#" * 80
output = net_connect.send_config_set(cfg_commands)
print output
print "#" * 80
print
print "\nConfiguring VLAN from file"
print "#" * 80
output = net_connect.send_config_from_file("vlan_cfg.txt")
print output
print "#" * 80
print
示例10: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def main():
print 'Username:',
usern = raw_input()
passwd = getpass()
for i in range(len(DEVICES)):
try:
net_dev = {
'device_type':DEV_TYPE[i],
'ip':DEVICES[i],
'username':usern,
'password':passwd
}
print '>>>>>>>>>>>>> DEVICE: {} <<<<<<<<<<<<<<'.format(DEVICES[i])
# Initiating netmiko connection
net_connect = ConnectHandler(**net_dev)
resp = net_connect.find_prompt()
print resp
# Entering config mode, deploying commands and exiting config mode
resp = net_connect.send_config_set(CONF_COMMANDS)
print resp
except Exception as e:
print e
exit(0)
示例11: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def main():
'''
Ansible module to perform config merge on Cisco IOS devices.
'''
module = AnsibleModule(
argument_spec=dict(
host=dict(required=True),
port=dict(default=22, required=False),
username=dict(required=True),
password=dict(required=True),
merge_file=dict(required=True),
dest_file_system=dict(default='flash:', required=False),
),
supports_check_mode=False
)
net_device = {
'device_type': 'cisco_ios',
'ip': module.params['host'],
'username': module.params['username'],
'password': module.params['password'],
'port': int(module.params['port']),
'verbose': False,
}
ssh_conn = ConnectHandler(**net_device)
ssh_conn.enable()
merge_file = module.params['merge_file']
dest_file_system = module.params['dest_file_system']
# Disable file copy confirmation
ssh_conn.send_config_set(['file prompt quiet'])
# Perform config merge
cmd = "copy {0}{1} running-config".format(dest_file_system, merge_file)
output = ssh_conn.send_command(cmd)
# Enable file copy confirmation
ssh_conn.send_config_set(['file prompt alert'])
if ' bytes copied in ' in output:
module.exit_json(msg="File merged on remote device",
changed=True)
else:
module.fail_json(msg="Unexpected failure during attempted config merge. "
"Please verify the current configuration on the network device.")
示例12: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def main():
inputfile, config_commands = get_cmd_line()
print("Switch configuration updater. Please provide login information.\n")
# Get username and password information.
username = input("Username: ")
password = getpass("Password: ")
enasecret = getpass("Enable Secret: ")
print("{}{:<20}{:<40}{:<20}".format(
"\n", "IP Address", "Name", "Results"), end="")
for switchip in inputfile:
ciscosw = {
"device_type": "cisco_ios",
"ip": switchip.strip(),
"username": username.strip(),
"password": password.strip(),
"secret": enasecret.strip(),
}
print()
print("{:<20}".format(switchip.strip()), end="", flush=True)
try:
# Connect to switch and enter enable mode.
net_connect = ConnectHandler(**ciscosw)
except Exception:
print("** Failed to connect.", end="", flush=True)
continue
prompt = net_connect.find_prompt()
# Print out the prompt/hostname of the device
print("{:<40}".format(prompt), end="", flush=True)
try:
# Ensure we are in enable mode and can make changes.
if "#" not in prompt[-1]:
net_connect.enable()
print("#", end="", flush=True)
except Exception:
print("Unable to enter enable mode.", end="", flush=True)
continue
else:
for cmd in config_commands:
# Make requested configuration changes.
try:
if cmd in ("w", "wr"):
output = net_connect.save_config()
print("w", end="", flush=True)
else:
output = net_connect.send_config_set(cmd)
if "Invalid input" in output:
# Unsupported command in this IOS version.
print("Invalid input: ", cmd, end="", flush=True)
print("*", end="", flush=True)
except Exception:
# Command failed! Stop processing further commands.
print("!")
break
net_connect.disconnect()
示例13: push_config_commands
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def push_config_commands(username, password, ip_address, vendor_class, secret, commands):
try:
net_connect = ConnectHandler(device_type=vendor_class, ip=ip_address, username=username, password=password, secret=secret)
net_connect.enable()
output = net_connect.send_config_set(commands)
print output
except:
print 'Error in either connecting or executing configuration command @ ' + ip_address
示例14: _cisco_push
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def _cisco_push(user, password, ip, command_list, device_type="cisco_ios"):
""" This function helps to push configurations inside Cisco IOS devices. """
device = {
'device_type': device_type,
'ip': ip,
'username': user,
'password': password,
'secret': password
}
try:
net_connect = ConnectHandler(**device)
net_connect.enable()
net_connect.send_config_set(command_list)
output = net_connect.send_command_expect(SHOW_RUN)
print "Configuration pushed!"
return output
except:
print "ERROR! Something wrong happened during the configuration process."
return 0
示例15: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_set [as 别名]
def main():
password = getpass()
pynet_rtr2 = {
"device_type": "cisco_ios",
"ip": "50.76.53.27",
"username": "pyclass",
"password": password,
"port": 8022,
}
ssh_connection = ConnectHandler(**pynet_rtr2)
ssh_connection.config_mode()
logging_command = ["logging buffered 20031"]
ssh_connection.send_config_set(logging_command)
output = ssh_connection.send_command("show run | inc logging buffered")
outp = output.split()
print "The new size of logging buffered is %s" % outp[2]