Friday, 8 December 2017

Install Netmiko



https://github.com/ktbyers/netmiko

+++

Multi-vendor library to simplify Paramiko SSH connections to network devices
Python 2.7, 3.4, 3.5

Requires:

Paramiko >= 1.13+
scp >= 0.10.0
pyyaml
pytest (for unit tests)

Supports:

Regularly tested
Arista vEOS
Cisco ASA
Cisco IOS
Cisco IOS-XE
Cisco IOS-XR
Cisco NX-OS
Cisco SG300
HP Comware7
HP ProCurve
Juniper Junos
Linux
Limited testing
Alcatel AOS6/AOS8
Avaya ERS
Avaya VSP
Brocade VDX
Brocade ICX/FastIron
Brocade MLX/NetIron
Cisco WLC
Dell-Force10 DNOS9
Dell PowerConnect
Huawei
Mellanox
Palo Alto PAN-OS
Pluribus
Ubiquiti EdgeSwitch Vyatta VyOS
Experimental
A10
Accedian
Alcatel-Lucent SR-OS
Aruba
Ciena SAOS
Cisco Telepresence
CheckPoint Gaia
Enterasys
Extreme EXOS
Extreme Wing
F5 LTM
Fortinet
MRV Communications OptiSwitch

Tutorials:

Standard Tutorial:
SSH Proxy:
Documentation (Stable)

Examples:

Create a dictionary representing the device.

Supported device_types can be found here, see CLASS_MAPPER keys.
from netmiko import ConnectHandler

cisco_881 = {
    'device_type': 'cisco_ios',
    'ip':   '10.10.10.10',
    'username': 'test',
    'password': 'password',
    'port' : 8022,          # optional, defaults to 22
    'secret': 'secret',     # optional, defaults to ''
    'verbose': False,       # optional, defaults to False
}

Establish an SSH connection to the device by passing in the device dictionary.

net_connect = ConnectHandler(**cisco_881)

Execute show commands.

output = net_connect.send_command('show ip int brief')
print(output)
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0              unassigned      YES unset  down                  down    
FastEthernet1              unassigned      YES unset  down                  down    
FastEthernet2              unassigned      YES unset  down                  down    
FastEthernet3              unassigned      YES unset  down                  down    
FastEthernet4              10.10.10.10     YES manual up                    up      
Vlan1                      unassigned      YES unset  down                  down    

For long-running commands, use send_command_expect()

send_command_expect waits for the trailing prompt (or for an optional pattern)
net_connect.send_command_expect('write memory')
Building configuration...
[OK]

Enter and exit enable mode.

net_connect.enable()
net_connect.exit_enable_mode()

Execute configuration change commands (will automatically enter into config mode)

config_commands = [ 'logging buffered 20000',
                    'logging buffered 20010',
                    'no logging console' ]
output = net_connect.send_config_set(config_commands)
print(output)
pynet-rtr1#config term
Enter configuration commands, one per line.  End with CNTL/Z.
pynet-rtr1(config)#logging buffered 20000
pynet-rtr1(config)#logging buffered 20010
pynet-rtr1(config)#no logging console
pynet-rtr1(config)#end
pynet-rtr1#


+++



#!/usr/bin/env python
from netmiko import ConnectHandler
iosv_l2 = {
'device_type': 'cisco_ios',
'ip': '192.168.122.72',
'username': 'david',
'password': 'cisco',
}
net_connect = ConnectHandler(**iosv_l2)
#net_connect.find_prompt()
output = net_connect.send_command('show ip int brief')
print output
config_commands = ['int loop 0', 'ip address 1.1.1.1 255.255.255.0']
output = net_connect.send_config_set(config_commands)
print output
for n in range (2,21):
print "Creating VLAN " + str(n)
config_commands = ['vlan ' + str(n), 'name Python_VLAN ' + str(n)]
output = net_connect.send_config_set(config_commands)
print output






+++


No comments:

Post a Comment

Demo: Interface Profiles

Create Leaf Interface Profile