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


Python ConnectHandler.send_config_from_file方法代码示例

本文整理汇总了Python中netmiko.ConnectHandler.send_config_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectHandler.send_config_from_file方法的具体用法?Python ConnectHandler.send_config_from_file怎么用?Python ConnectHandler.send_config_from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在netmiko.ConnectHandler的用法示例。


在下文中一共展示了ConnectHandler.send_config_from_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [as 别名]
def main():
    '''
    Use Netmiko to change the logging buffer size and to disable console logging
    from a file for both pynet-rtr1 and 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

    for a_device in (pynet1, pynet2):
        net_connect = ConnectHandler(**a_device)
        net_connect.send_config_from_file(config_file='config_file.txt')

        # Verify configuration
        output = net_connect.send_command("show run | inc logging")
        print
        print '#' * 80
        print "Device: {}:{}".format(net_connect.ip, net_connect.port)
        print
        print output
        print '#' * 80
        print
开发者ID:GnetworkGnome,项目名称:pynet,代码行数:29,代码来源:ex8_netmiko.py

示例2: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [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

示例3: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [as 别名]
def main():
    ip_addr = '50.76.53.27'
    port_rtr1 = 22
    port_rtr2 = 8022
    username = 'pyclass'
    password = '88newclass'
    #password = getpass()

    pynet1 = {
        'device_type': 'cisco_ios',
        'ip': ip_addr,
        'username': username,
        'password': password,
        'port': port_rtr1,
    }


    pynet2 = {
        'device_type': 'cisco_ios',
        'ip': ip_addr,
        'username': username,
        'password': password,
        'port': port_rtr2,
    }


    pynet_rtr1 = ConnectHandler(**pynet1)
    pynet_rtr2 = ConnectHandler(**pynet2)

    out1 = pynet_rtr1.send_config_from_file(config_file='w4-8-commands.txt')
    out2 = pynet_rtr2.send_config_from_file(config_file='w4-8-commands.txt')

    print "The output in rtr1 is:\n%s\n" % out1
    print "The output in rtr2 is:\n%s\n" % out2
开发者ID:thomarite,项目名称:pynetw4,代码行数:36,代码来源:w4-8.py

示例4: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [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):
        a_dict['ip'] = ip_addr
        a_dict['password'] = password
        a_dict['verbose'] = False
    
    # Loop through each router and issue config command via config_file
    for a_device in (pynet1, pynet2):
        
        net_connect = ConnectHandler(**a_device)
        net_connect.send_config_from_file(config_file='config_file.txt')
        output = net_connect.send_command("show run | i logging")
    
        print
        print "Device: {}:{}".format(net_connect.ip, net_connect.port)
        print
        print output
        print
开发者ID:mstrocc,项目名称:PyNet-Python-Ansible,代码行数:28,代码来源:class4ex8_netmiko4.py

示例5: login

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [as 别名]
class ConnectivityTest:
    def login(self):
        self.cisco_switch = ConnectHandler(
            device_type='cisco_nxos',
            ip=HOSTNAME,
            username=USERNAME,
            password=PASSWORD,
            verbose=False)

    def setUp(self):
        self.failure = False
        self.login()
        self.cisco_switch.send_command('checkpoint ' + CHECKPOINT_NAME)

    def test_snippets(self):
        for snippet_file in os.listdir(SNIPPET_DIR):
            self.cisco_switch.send_config_from_file(os.path.join(SNIPPET_DIR, snippet_file))
            ping_result = self.cisco_switch.send_command('ping 192.168.56.2')

            print "=========================="
            print snippet_file
            print "--------------------------"
            print ping_result

            if not ping_is_successful(ping_result):
                self.failure = True

    def tearDown(self):
        self.cisco_switch.send_command('rollback running-config checkpoint ' + CHECKPOINT_NAME)
        self.cisco_switch.send_command('no checkpoint ' + CHECKPOINT_NAME)
        self.cisco_switch.disconnect()
开发者ID:ntcpod11,项目名称:training,代码行数:33,代码来源:ping_test.py

示例6: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [as 别名]
def main():
    '''
    Use Netmiko to change the logging buffer size (logging buffered <size>)
    and to disable console logging (no logging console) from a file on
    both pynet-rtr1 and pynet-rtr2
    '''

    ip_address = raw_input("Please enter IP address: ")
    password = getpass()

    pynet_rtr1['ip'] = ip_address
    pynet_rtr2['ip'] = ip_address
    pynet_rtr1['password'] = password
    pynet_rtr2['password'] = password

    #for each router load config from
    #file and print result

    for router in (pynet_rtr1, pynet_rtr2):
        ssh_conn = ConnectHandler(verbose=False, **router)
        ssh_conn.send_config_from_file('ex8_config.txt')

        output = ssh_conn.send_command('show run | in logging')

        print "\n>>> {}:{}  \n".format(ssh_conn.ip, ssh_conn.port)
        print output
        print ">>>\n"
开发者ID:adleff,项目名称:python_ansible,代码行数:29,代码来源:ex8.py

示例7: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [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()
开发者ID:agonzo777,项目名称:pynet,代码行数:10,代码来源:exercise8.py

示例8: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [as 别名]
def main():

    for each_item in [rtr1, rtr2]:
        
        conn1 = ConnectHandler(**each_item)
        conn1.send_config_from_file(config_file = 'config_snippet.txt')

        outp = conn1.send_command("show run | inc logging")
        hostname = get_name_of_obj(each_item, "each_item")
        print "Logging buffer size and logging console info on %s :" % hostname
        print outp + "\n" + "***********************"
开发者ID:zoomhgtk,项目名称:hsun_pynet_exercise,代码行数:13,代码来源:ex8_netmiko.py

示例9: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [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

            # Deploying config commands from file
            resp = net_connect.send_config_from_file(config_file=CONF_COMMANDS_FILE)
            print resp

        except Exception as e:
            print e
            exit(0)
开发者ID:ahsec,项目名称:PyNet_Class_Exercises,代码行数:29,代码来源:exercise_08.py

示例10: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [as 别名]
def main():
    for device in rtr_list:
        rtr_conn = ConnectHandler(**device)
        prompt = rtr_conn.find_prompt()
        rtr_conn.config_mode()
        output = rtr_conn.send_config_from_file(config_file='4_8_cfg.txt')
        print output
开发者ID:ssherman68,项目名称:PyNetAutoClass,代码行数:9,代码来源:4-8.py

示例11: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [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
开发者ID:squeezer,项目名称:pynet_test,代码行数:35,代码来源:my_test26.py

示例12: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [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"
开发者ID:cocoloco69,项目名称:pynet,代码行数:27,代码来源:w4e8.py

示例13: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [as 别名]
def main():


    password = getpass()
    
    
    for a_dict in (pynet1, pynet2):
        a_dict['password'] = password
        
        net_connect = ConnectHandler(**a_dict)
        net_connect.send_config_from_file(config_file='config_file.txt')
            
        output = net_connect.send_command("show run | i logging")
        
        print "Device name:{}".format(net_connect.ip)

        print output
开发者ID:dracode22,项目名称:pynet_class,代码行数:19,代码来源:ex8.py

示例14: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [as 别名]
def main():

    password = getpass()

    pynet_rtr1 = {'device_type': 'cisco_ios', 'ip': '50.76.53.27', 'username': 'pyclass', 'password': password, 'port': 22}
    pynet_rtr2 = {'device_type': 'cisco_ios', 'ip': '50.76.53.27', 'username': 'pyclass', 'password': password, 'port': 8022}

    for ssh in pynet_rtr1, pynet_rtr2:
        ssh_connection = ConnectHandler(**ssh)
        ssh_connection.config_mode()
        ssh_connection.send_config_from_file(config_file='commands_file.txt')

        output = ssh_connection.send_command('show run | inc logging')
        hostname = ssh_connection.send_command('show run | inc hostname pynet').split()

        print '*' * 10 + " New logging configurations for Cisco router %s " % hostname[1] + '*' * 10
        print output
        print '*' * 76
开发者ID:jabibenito,项目名称:pynet_course,代码行数:20,代码来源:exercise8.py

示例15: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import send_config_from_file [as 别名]
def main():
    '''
    Use Netmiko to change the logging buffer size (logging buffered <size>)
    and to disable console logging (no logging console) from a file on both
    pynet-rtr1 and pynet-rtr2.
    '''

    for device in (pynet1, pynet2):
        device['password'] = password

    for device in (pynet1, pynet2):
        connect_device = ConnectHandler(**device)
        prompt = connect_device.find_prompt()
        connect_device.send_config_from_file('config_file.txt')
        output = connect_device.send_command('show run | inc logg')
        print
        print prompt
        print output
开发者ID:ibyt32,项目名称:pynet_test,代码行数:20,代码来源:w4e8_netmiko.py


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