How to use the netmiko.ssh_dispatcher function in netmiko

To help you get started, we’ve selected a few netmiko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ktbyers / netmiko / tests / old_format / test_cisco_legacy.py View on Github external
def setup_module(module):

    module.EXPECTED_RESPONSES = {
        'base_prompt' : 'pynet-rtr1',
        'interface_ip'  : '10.220.88.20'
    }
    
    show_ver_command = 'show version'
    module.basic_command = 'show ip int brief'
   
    SSHClass = netmiko.ssh_dispatcher(device_type=cisco_881['device_type']) 
    net_connect = SSHClass(**cisco_881)

    module.show_version = net_connect.send_command(show_ver_command)
    module.show_ip = net_connect.send_command(module.basic_command)
    module.base_prompt = net_connect.base_prompt

    module.show_ip_alt = net_connect.send_command_expect(module.basic_command)
    module.show_version_alt = net_connect.send_command_expect(show_ver_command)

    # Test buffer clearing
    net_connect.remote_conn.sendall(show_ver_command)
    time.sleep(2)
    net_connect.clear_buffer()
    # Should not be anything there on the second pass
    module.clear_buffer_check = net_connect.clear_buffer()
github ktbyers / netmiko / tests / test_f5_ltm.py View on Github external
def setup_module(module):

    module.EXPECTED_RESPONSES = {
        'device_type'   : 'BIG-IP',
        'pool_name'     : 'Ltm::Pool: TEST',
    }
    
    show_sys_command = 'tmsh show sys version'
    multiple_line_command = 'tmsh show sys log ltm'
    module.basic_command = 'tmsh show ltm pool TEST'
    
    SSHClass = netmiko.ssh_dispatcher(f5_ltm_1['device_type'])
    net_connect = SSHClass(**f5_ltm_1)
    module.show_version = net_connect.send_command(show_sys_command)
    module.multiple_line_output = net_connect.send_command(multiple_line_command, delay_factor=2)
    module.show_pool = net_connect.send_command(module.basic_command)
github ktbyers / netmiko / tests / test_cisco_xe_enable.py View on Github external
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'
    
    SSHClass = netmiko.ssh_dispatcher(cisco_xe['device_type'])
    net_connect = SSHClass(**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')
github ktbyers / netmiko / tests / test_cisco_xe.py View on Github external
def setup_module(module):

    module.EXPECTED_RESPONSES = {
        'base_prompt' : 'xe-test-rtr',
        'interface_ip'  : '172.30.0.167',
    }
    
    show_ver_command = 'show version'
    module.basic_command = 'show ip int brief'
    
    SSHClass = netmiko.ssh_dispatcher(cisco_xe['device_type'])
    net_connect = SSHClass(**cisco_xe)
    module.show_version = net_connect.send_command(show_ver_command)
    module.show_ip = net_connect.send_command(module.basic_command)
    module.base_prompt = net_connect.base_prompt
github ktbyers / netmiko / tests / test_hp_comware.py View on Github external
def setup_module(module):

    module.EXPECTED_RESPONSES = {
        'base_prompt'   : 'vsr1000',
        'router_prompt' : '',
        'interface_ip'  : '192.168.112.11',
        'config_mode'   : '[vsr1000]',
    }
    
    show_ver_command = 'display version'
    multiple_line_command = 'display logbuffer'
    module.basic_command = 'display ip interface brief'
    
    SSHClass = netmiko.ssh_dispatcher(hp_comware['device_type'])
    net_connect = SSHClass(**hp_comware)

    module.show_version = net_connect.send_command(show_ver_command)
    module.multiple_line_output = net_connect.send_command(multiple_line_command, delay_factor=2)
    module.show_ip = net_connect.send_command(module.basic_command)

    module.base_prompt = net_connect.base_prompt

    # Enter config mode
    module.config_mode = net_connect.config_mode()
    
        # Exit config mode
    module.exit_config_mode = net_connect.exit_config_mode()

    # Send a set of config commands
    config_commands = ['vlan 3000', 'name 3000-test']
github plucena24 / network_discovery / parsers / base.py View on Github external
def connect(self):
        self.is_connected = False
        try:
            SSHClass = netmiko.ssh_dispatcher(self.device_class)
            username = self.credentials.username
            password = self.credentials.password

            ssh = SSHClass(ip=self.device_name, username=username, password=password)
            self.conn = ssh
            is_connected = True
        except Exception as e:
            print("failed to connect to device {}, error was {}. Appending it to failed".format(self.device_name, e))
        return self.is_connected