当前位置: 首页>>代码示例>>Python>>正文


Python ConnectHandler.send_command_expect方法代码示例

本文整理汇总了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
开发者ID:duncanbarter,项目名称:pynet_ons,代码行数:27,代码来源:ex35_django.py

示例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)
开发者ID:ibyt32,项目名称:pynet_test,代码行数:28,代码来源:w8e5_netmiko.py

示例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
开发者ID:befthimi,项目名称:be_pynet_course,代码行数:30,代码来源:exercise5.py

示例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
开发者ID:agonzo777,项目名称:pynet,代码行数:10,代码来源:exercise7.py

示例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
开发者ID:dracode22,项目名称:pynet_class,代码行数:12,代码来源:ex6.py

示例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
开发者ID:eaboytes,项目名称:pynet_testz,代码行数:15,代码来源:exercise6.py

示例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
开发者ID:bspitzmacher,项目名称:pynet_course,代码行数:16,代码来源:exercise7.py

示例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
开发者ID:LionelKb,项目名称:network-automation,代码行数:17,代码来源:ex7_processes_show_ver.py

示例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
开发者ID:eaboytes,项目名称:pynet_testz,代码行数:17,代码来源:exercise5.py

示例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()
开发者ID:ande0581,项目名称:pynet,代码行数:35,代码来源:class4_ex8.py

示例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')
开发者ID:wantonik,项目名称:pynet_wantonik,代码行数:9,代码来源:e6v3.py

示例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()
开发者ID:ilique,项目名称:netmiko,代码行数:10,代码来源:threads_netmiko.py

示例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)
开发者ID:brianbooher,项目名称:pynet_testz,代码行数:20,代码来源:exercise5.py


注:本文中的netmiko.ConnectHandler.send_command_expect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。