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


Python ConnectHandler.enable方法代码示例

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


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

示例1: get_cdp_neighbor_details

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import enable [as 别名]
def get_cdp_neighbor_details(ip, username, password, enable_secret):
    """
    get the CDP neighbor detail from the device using SSH

    :param ip: IP address of the device
    :param username: username used for the authentication
    :param password: password used for the authentication
    :param enable_secret: enable secret
    :return:
    """
    # establish a connection to the device
    ssh_connection = ConnectHandler(
        device_type='cisco_ios',
        ip=ip,
        username=username,
        password=password,
        secret=enable_secret
    )

    # enter enable mode
    ssh_connection.enable()

    # prepend the command prompt to the result (used to identify the local device)
    result = ssh_connection.find_prompt() + "\n"

    # execute the show cdp neighbor detail command
    # we increase the delay_factor for this command, because it take some time if many devices are seen by CDP
    result += ssh_connection.send_command("show cdp neighbor detail", delay_factor=2)

    # close SSH connection
    ssh_connection.disconnect()

    return result
开发者ID:ddevalco,项目名称:python-script-examples,代码行数:35,代码来源:collect-cdp-information.py

示例2: setup_module

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

示例3: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import enable [as 别名]
def main():
    '''
    This will run an command via serial on an cisco ios switch and so
    serial cable must be attached to the device
    '''
    serialhandle = {
        'device_type':'cisco_ios_serial',
        'port': 'USB Serial', # can be COM<number> or any line you can get from
                              # serial.tools.list_ports.comports() 
        'username':'<username>',
        'password':'<password>',
        'secret':'<secret>',
        'serial_settings':{ # this are the default values
                'baudrate': 9600,
                'bytesize': serial.EIGHTBITS,
                'parity': serial.PARITY_NONE,
                'stopbits': serial.STOPBITS_ONE
            }
        }
    net_connect = ConnectHandler(**serialhandle)
    net_connect.enable()
    output = net_connect.send_command('show run')
    net_connect.disconnect()
    
    print(output)
开发者ID:ilique,项目名称:netmiko,代码行数:27,代码来源:test_cisco_ios_serial.py

示例4: get_cdp_neighbors

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import enable [as 别名]
def get_cdp_neighbors(ip, username, password, enable_secret):
    ssh_connection = ConnectHandler(
        device_type = 'cisco_ios',
        ip = ip,
        username = username,
        password = password,
        secret = enable_secret
    )
    ssh_connection.enable()
    result = ssh_connection.find_prompt() + "\n"
    result = ssh_connection.send_command("show cdp neighbors", delay_factor=0)

    with open(os.getcwd()+'/temps/'+ip, 'w') as outfile:
        outfile.write(result)
    ssh_connection.disconnect()
开发者ID:jamalshahverdiev,项目名称:cisco-cdp-desc-writer,代码行数:17,代码来源:writedescfromcdp.py

示例5: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import enable [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.")
开发者ID:KlyanYosan,项目名称:scp_sidecar,代码行数:50,代码来源:cisco_config_replace.py

示例6: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import enable [as 别名]
def main():
    """
    This will run an command via serial on an cisco ios switch and so
    serial cable must be attached to the device
    """
    serialhandle = {
        "device_type": "cisco_ios_serial",
        "port": "USB Serial",  # can be COM<number> or any line you can get from
        # serial.tools.list_ports.comports()
        "username": "<username>",
        "password": "<password>",
        "secret": "<secret>",
        "serial_settings": {  # this are the default values
            "baudrate": 9600,
            "bytesize": serial.EIGHTBITS,
            "parity": serial.PARITY_NONE,
            "stopbits": serial.STOPBITS_ONE,
        },
    }
    net_connect = ConnectHandler(**serialhandle)
    net_connect.enable()
    output = net_connect.send_command("show run")
    net_connect.disconnect()

    print(output)
开发者ID:ktbyers,项目名称:netmiko,代码行数:27,代码来源:test_cisco_ios_serial.py

示例7: setup_module

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

示例8: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import enable [as 别名]
def main():
    device_list = [cisco_ios, cisco_xr, arista_veos]
    start_time = datetime.now()
    print

    for a_device in device_list:
        as_number = a_device.pop('as_number')
        net_connect = ConnectHandler(**a_device)
        net_connect.enable()
        print "{}: {}".format(net_connect.device_type, net_connect.find_prompt())
        if check_bgp(net_connect):
            print "BGP currently configured"
            remove_bgp_config(net_connect, as_number=as_number)
        else:
            print "No BGP"

        # Check BGP is now gone
        if check_bgp(net_connect):
            raise ValueError("BGP configuration still detected")

        # Construct file_name based on device_type
        device_type = net_connect.device_type
        file_name = 'bgp_' + device_type.split("_ssh")[0] + '.txt'

        # Configure BGP
        output = configure_bgp(net_connect, file_name)
        print output
        print

    print "Time elapsed: {}\n".format(datetime.now() - start_time)
开发者ID:GnetworkGnome,项目名称:pynet,代码行数:32,代码来源:load_bgp_config_part4.py

示例9: setup_module

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

示例10: main

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

示例11: push_config_commands

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

示例12: write_descr

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import enable [as 别名]
def write_descr(ip, username, password, enable_secret, localint, descr):
    ssh_connection = ConnectHandler(
        device_type = 'cisco_ios',
        ip = ip,
        username = username,
        password = password,
        secret = enable_secret
    )
    ssh_connection.enable()
    rt = ssh_connection.find_prompt() + "\n"
    rt = ssh_connection.send_command("conf t", delay_factor=0)
    rt = ssh_connection.send_command("int "+localint, delay_factor=0)
    rt = ssh_connection.send_command("description "+descr, delay_factor=0)
    ssh_connection.disconnect()
开发者ID:jamalshahverdiev,项目名称:cisco-cdp-desc-writer,代码行数:16,代码来源:writedescfromcdp.py

示例13: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import enable [as 别名]
def main():
    device_list = [cisco_ios, cisco_xr, arista_veos]
    start_time = datetime.now()
    print

    for a_device in device_list:
        net_connect = ConnectHandler(**a_device)
        net_connect.enable()
        print "{}: {}".format(net_connect.device_type, net_connect.find_prompt())
        if check_bgp(net_connect):
            print "BGP currently configured"
        else:
            print "No BGP"
        print

    print "Time elapsed: {}\n".format(datetime.now() - start_time)
开发者ID:GnetworkGnome,项目名称:pynet,代码行数:18,代码来源:load_bgp_config_part2.py

示例14: show_version

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

    device_ip = socket.gethostbyname(current_device)
    command = "show version"
    net_connect = ConnectHandler(
            device_type=device_type,
            ip=device_ip,
            username=current_operator.username,
            password=current_operator.password
    )

    net_connect.find_prompt()
    net_connect.enable()
    output = net_connect.send_command(command)

    return (output)
开发者ID:aadamu,项目名称:network-tools,代码行数:18,代码来源:cisco_status.py

示例15: main

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import enable [as 别名]
def main():
    '''
    Connects to router and switches to config mode
    '''
    pynet_rtr2 = ConnectHandler(**pynet2)
    pynet_rtr2.enable()
    pynet_rtr2.config_mode()
    
    '''
    Checks to see if you are in enable mode and prints results to screen
    '''
    if pynet_rtr2.check_config_mode() is True:
        output = pynet_rtr2.find_prompt()
        print output
    else:
        print 'You are NOT in config mode'
开发者ID:eaboytes,项目名称:pynet_testz,代码行数:18,代码来源:exercise5.py


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