本文整理汇总了Python中netmiko.ConnectHandler.send_command_expect方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectHandler.send_command_expect方法的具体用法?Python ConnectHandler.send_command_expect怎么用?Python ConnectHandler.send_command_expect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netmiko.ConnectHandler
的用法示例。
在下文中一共展示了ConnectHandler.send_command_expect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def main():
"""
Write a Python script that retrieves all of the network devices from the database
Using this data, make a Netmiko connection to each device.
Retrieve 'show run'.
Record the time that the program takes to execute.
"""
start_time = datetime.now()
django.setup()
my_devices = NetworkDevice.objects.all()
print
for a_device in my_devices:
a_device_netmiko = create_netmiko_dict(a_device)
remote_conn = ConnectHandler(**a_device_netmiko)
if 'juniper' in a_device.device_type:
show_run = remote_conn.send_command_expect("show configuration")
else:
show_run = remote_conn.send_command_expect("show run")
print a_device.device_name
print '-' * 80
print show_run
print '-' * 80
print
print ">>>>>>>> Total Time: {}".format(datetime.now() - start_time)
print
示例2: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def main():
'''
Use Netmiko to connect to each of the devices in the database. Execute
'show version' on each device. Calculate the amount of time required to
do this.
'''
django.setup()
devices = NetworkDevice.objects.all()
start_time = datetime.now()
for a_device in devices:
creds = a_device.credentials
remote_conn = ConnectHandler(device_type=a_device.device_type,
ip=a_device.ip_address,
username=creds.username,
password=creds.password,
port=a_device.port, secret='')
print
print a_device
print '#' * 80
print remote_conn.send_command_expect("show version")
print '#' * 80
print
elapsed_time = datetime.now() - start_time
print "Elapsed time: {}".format(elapsed_time)
示例3: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def main():
"""
The main function
"""
django.setup()
total_elapsed_time = 0
device_list = NetworkDevice.objects.all()
for device in device_list:
starttime = time.time()
remote_connection = ConnectHandler(device_type=device.device_type,
ip=device.ip_address, port=device.port,
username=device.credentials.username,
password=device.credentials.password)
print '=' * 50
print device.device_name
print '-' * 15
print remote_connection.send_command_expect('show version')
finishtime = time.time()
timedelta = finishtime - starttime
total_elapsed_time = total_elapsed_time + timedelta
print 'Retrieval duration: %.2f seconds' % round(timedelta, 2)
print
print '*' * 50
print 'Overall retrieval duration: %.2f seconds' % round(total_elapsed_time, 2)
print '*' * 50
示例4: show_version
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def show_version(dev):
print "#"*30 + " " + dev.device_name + " " + "#" * 30
conn = ConnectHandler(device_type=dev.device_type, ip=dev.ip_address, username=dev.credentials.username,
password=dev.credentials.password, port=dev.port)
print conn.send_command_expect('show version')
print "#" * 80
print
开发者ID:pmusolino-rms,项目名称:Network-Automation-with-Python-and-Ansible-class,代码行数:10,代码来源:db_connect_sh_ver_w_process.py
示例5: show_version
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def show_version(a_device):
creds = a_device.credentials
remote_conn = ConnectHandler(device_type=a_device.device_type,ip=a_device.ip_address,username=creds.username,password=creds.password,port=a_device.port)
print '#' * 20 + 'SHOW VERSION OUTPUT' + '#'* 20
print '\n'
print remote_conn.send_command_expect("show version")
print
print '#' * 60
示例6: show_version
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def show_version(a_device):
creds = a_device.credentials
remote_conn = ConnectHandler(device_type=a_device.device_type, ip=a_device.ip_address, username=creds.username, password=creds.password, port=a_device.port, secret='')
print
print '='*37,a_device.device_name,'='*37
print remote_conn.send_command_expect("show version")
print '='*80
print
示例7: show_ver
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def show_ver(a_device):
'''function connects to device using ORM and retrieves output from a "show version" command'''
creds = a_device.credentials
remote_conn = ConnectHandler(device_type=a_device.device_type,
ip=a_device.ip_address,
password=creds.password,
username=creds.username,
port=a_device.port,
secret='')
print
print '#' * 80
print remote_conn.send_command_expect("show ver")
print '#' * 80
示例8: show_ver
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def show_ver(net_device):
device_type = net_device.device_type
port = net_device.port
secret = ''
ip_address = net_device.ip_address
creds = net_device.credentials
username = creds.username
password = creds.password
remote_conn = ConnectHandler(device_type=device_type, ip=ip_address, username=username, password=password, port=port, secret=secret)
print "=" * 90
print remote_conn.send_command_expect("show version")
print "=" * 90
示例9: show_version
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def show_version(a_device):
'''
Execute show version command using Netmiko
'''
creds = a_device.credentials
remote_conn = ConnectHandler(device_type=a_device.device_type,
ip=a_device.ip_address,
username=creds.username,
password=creds.password,
port=a_device.port, secret='')
print
print '#' * 80
print remote_conn.send_command_expect("show version")
print '#' * 80
print
示例10: show_ver
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def show_ver(a_device):
'''Handles logging into each device and doing the show command.
the "print remote_conn.send_command("show ver")"was tried and worked well
but expect method was recommended'''
creds = a_device.credentials
remote_conn = ConnectHandler(device_type=a_device.device_type,
ip=a_device.ip_address,
password=creds.password,
username=creds.username,
port=a_device.port,
secret='')
print a_device
print '#' * 80
print remote_conn.send_command_expect('show ver')
print '#' * 80
示例11: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def main():
router1 = {
'device_type': 'cisco_ios',
'ip': '10.9.0.67',
'username': 'myuser',
'password': 'mypass'
}
router2 = {
'device_type': 'cisco_ios',
'ip': '10.63.176.57',
'username': 'myuser',
'password': 'mypass'
}
routers = [router1, router2]
for router in routers:
# Connect to device
device_conn = ConnectHandler(**router)
# Change config from file
device_conn.send_config_from_file(config_file='config_commands.txt')
# Validate changes
print ">>> " + device_conn.find_prompt() + " <<<"
#output = device_conn.send_command("show run | in logging", delay_factor=.5)
output = device_conn.send_command_expect("show run | in logging")
print output + "\n\n"
# Close connection
device_conn.disconnect()
示例12: show_version
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def show_version(a_device):
'''Establish connection with Netmiko + 'show version' command.'''
creds = a_device.credentials
remote_conn = ConnectHandler(device_type=a_device.device_type, port=a_device.port, ip=a_device.ip_address, username=creds.username, password=creds.password, secret='')
print 'Establishing connection via Netmiko to all net devices ', '\n', remote_conn
print 80 * '_'
command_outp = remote_conn.send_command_expect('show version')
示例13: show_version
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def show_version(a_device):
'''Execute show version command using Netmiko.'''
remote_conn = ConnectHandler(**a_device)
print()
print('#' * 80)
print(remote_conn.send_command_expect("show version"))
print('#' * 80)
print()
示例14: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def main():
django.setup()
devices = NetworkDevice.objects.all()
starttime = datetime.now()
for dev in devices:
print "#"*30 + " " + dev.device_name + " " + "#" * 30
conn = ConnectHandler(device_type=dev.device_type, ip=dev.ip_address, username=dev.credentials.username,
password=dev.credentials.password, port=dev.port)
print conn.send_command_expect('show version')
print "#" * 80
print
totaltime = datetime.now() - starttime
print
print "Elapsed time " + str(totaltime)
print
开发者ID:pmusolino-rms,项目名称:Network-Automation-with-Python-and-Ansible-class,代码行数:19,代码来源:db_connect-sh-ver.py
示例15: main
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_command_expect [as 别名]
def main():
# I would define any variables that are specific to this script here
django.setup()
devices = NetworkDevice.objects.all()
start_time = datetime.now()
for a_device in devices:
remote_conn = ConnectHandler(device_type=a_device.device_type,
ip=a_device.ip_address,
username=a_device.credentials.username,
password=a_device.credentials.password,
port=a_device.port)
print a_device
print '#' * 40
print remote_conn.send_command_expect("show version")
print '#' * 40
print
elapsed_time = datetime.now() - start_time
print "Elsapsed time: {}".format(elapsed_time)