Package: net-automation-usman-u
Network AutomationAnAnsible likeNetwork Automation Framework, Using Python OOP and Netmiko to interface with Cisco IOS, VyOS, EdgeOS network devices.UsageExample 1: Getting Basic Device Information from a VyOS RouterImporting the class from the package.fromnet_automationimportnet_automationCreating an instance of the VyOS class, with specified parameters.router_1=net_automation.Vyos("router-1.com",# Hostname/IP"username",# Username"",# PasswordTrue,# Boolean switch for using SSH Keys. (password not needed if True)"/home/user/.ssh/id_rsa",# SSH Key file location"")# Secret (left empty, as Cisco Only)Establishing the SSH connection to "router_1" and getting interfaces.router_1.init_ssh()# Creates the SSH connection to the VyOS routerprint(router_1.get_interfaces())# Returns Interfaces from the VyOS routerCodes:S-State,L-Link,u-Up,D-Down,A-AdminDownInterfaceIPAddressS/LDescription---------------------------------eth0a.b.c.d/23u/uWANlo127.0.0.1/8u/udn42-vyos10.100.100.4/32::1/128wg12172.22.132.170/30u/up2p_usmanGetting a traceroute to "8.8.8.8".print(router_1.get_route("8.8.8.8"))# Returns traceroute to specific IPtracerouteto8.8.8.8(8.8.8.8),30hopsmax,60bytepackets1vlan32.core01.lil01.fr.virtua.systems(185.154.155.1)0.633ms0.483ms0.350ms2po31.core02.lil01.fr.virtua.systems(188.214.24.177)0.266ms0.125ms0.145ms3188.214.24.204.866ms4.867ms4.848ms4google1.par.franceix.net(37.49.237.172)8.769ms9.160ms8.835ms5108.170.244.1619.585ms108.170.244.2259.982ms108.170.244.1619.647ms6216.239.48.438.850ms142.250.224.19715.357ms216.239.48.459.662ms7dns.google(8.8.8.8)9.607ms8.734ms9.453msStoring returned route table and configuration in variables.configuration = (router_1.get_config())                                
route_table = (router_1.get_route_table())Example 2: Generating and Deploying Configurations to a VyOS Router..py filefromnet_automationimportnet_automationnet_automation.Vyos.deploy_yaml("router.yml")Executing the Python script should generate and deploy configs, based on the contents of the YAML file.router.ymlfilerouters:-name:"vyos-dn42-01"SSH_conf:hostname:"10.0.0.1"username:"username"password:""use_keys:Truekey_location:"C:\\Users\\user\\.ssh\\id_rsa"secret:""firewalls:-name:"WAN_Local"state:"present"default_action:"drop"rules:-rule_no:"10"state:"present"action:"accept"desc:"acceptSSH"dest:"port22"source:""protocol:"tcp_udp"-rule_no:"30"state:"present"action:"accept"desc:"acceptwg51890"dest:"port51890"source:""protocol:"udp"-rule_no:"90"state:"present"action:"accept"desc:"allowestabrelatedtraffic"states:-name:"established"status:"present"-name:"related"status:"enabled"interfaces:-name:"eth0"type:"ethernet"state:"present"ip:"dhcp"mask:""desc:"WAN"-name:"lo"type:"loopback"state:"present"ip:"10.100.100.4"mask:"/32"desc:""static:-type:"interface-route"network:"172.20.16.141/32"nexthop:"wg15"distance:""state:"present"bgpasn:"4242421869"bgp_prefixes:-prefix:"172.22.132.160"mask:"/27"address_family:"ipv4-unicast"state:"present"bgp_peers:-ip:"172.20.53.104"state:"present"remote_as:"4242423914"ebgp_multihop:"255"desc:"kioubit"route_maps:-route_map:"DN42-ROA"action:"import"state:"present"-route_map:"DN42-ROA"action:"export"state:"present"Example 3: Backing up device configurations.Creating instances CiscoIOS and EdgeOS classes, for Cisco switches and Ubiquiti switches.cisco_2960=net_automation.Cisco_IOS("cisco-2960.lan","usman","password",False,"","ciscosecret")cisco_3560=net_automation.Cisco_IOS("cisco-3560.lan","username","password",False,"","ciscosecret")ubiquiti_erx=net_automation.EdgeOS("ubiquiti-erx.lan","username","",True,r"C:\Users\Usman\.ssh\id_rsa","")ubiquiti_er4=net_automation.EdgeOS("ubiquit-er4.lan","usman","",True,r"C:\Users\Usman\.ssh\id_rsa","")For loops that get device configurations and writes them to external files.cisco_switches=[cisco_2960,cisco_3560]fordeviceincisco_switches:# iterates through the "cisco_switches" array and:to_write=Cisco_IOS.get_all_config(device)# stores the outputs from method in the "to_write" variableCisco_IOS.write_file(device,to_write,"")# writes the output to new filesubiquti_routers=[ubiquiti_erx,ubiquiti_er4]fordeviceinubiquti_routers:# iterates through the "ubiquiti_routers" array and:to_write=Vyos.get_config(device)# stores the outputs from method in the "to_write" variableMain.write_file(device,to_write,"")# writes the output to new files