skip to Main Content
Automation Arista EVPN-VXLAN with Python

EVPN-VXLAN technology, which can be used to connect two different datacenters over the Internet, can be done with Python on Arista. The important part; In this architecture, connection will be established over the internet, not via MPLS or special circuits. EVPN-VXLAN provides extension of VLANs at layer2 level. In such a topology, it can often create VLANs and announce these VLAN information to each other on routers. However, care should be taken in live systems when creating or announcing these VLANs. By making use of REST API technology in Arista switches, network operations can be made simpler with Python in the EVPN-VXLAN environment. Thus, daily operations can be carried out in a more controlled and automated manner.

The example topology has two datacenters connected over the internet via BGP. Clients are connected to datacenter switches and reside in the same layer2 broadcast domain via EVPN-VXLAN.

Some requirements are needed to use Python on Arista switches.

  • The jsonrclib library must be imported to use some json methods. This library is required to use REST API in json format.
  • Arista switches’ API URL of the jsonrpclib library. It can be accessed by the server method. This method; username, password, IP, port etc. requires parameters. In the sample code; The eapi_url parameter is the variable.
  • The ssl library must be imported to pass the SSL verification.
  • We define parameters and some variables to be used in commands to access the API. In the sample code; The 1500-1779 vlan range will be created and migrated to EVPN.
  • In the sample code; The cmds list will be used to apply commands to devices. Commands take variables to be more flexible.

 

Python Code

import jsonrpclib
from pprint import pprint
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

port=443
username=’admin’
password=’arista’
ip=’172.16.91.200′
vlan= “1500-1779”
asnumber=”100″

cmds= [
“configure”,
“vlan” +’ ‘+str(vlan),
“interface vxlan 1”,
“vxlan vlan add”+’ ‘+ str(vlan)+’ ‘+”vni”+’ ‘+str(vlan),
“router bgp “+’ ‘+str(asnumber),
“vlan-aware-bundle A”,
“vlan add”+’ ‘+str(vlan),
“write memory”
]

eapi_url=’https://{}:{}@{}:{}/command-api’.format(username, password, ip, port)
eapi_conn = jsonrpclib.Server(eapi_url)
response = eapi_conn.runCmds(1,cmds)
pprint(response)

Result


DC-1#show vlan >>>>>>>>>>>>>>>CREATED VLANs
VLAN Name Status Ports
1500 VLAN1500 active Vx1
1501 VLAN1501 active Vx1
1502 VLAN1502 active Vx1
(…omitted)
1778 VLAN1778 active Vx1
1779 VLAN1779 active Vx1

DC-1#show running-config interfaces vxlan 1 >>>>>>>>>CREATED VNIs
interface Vxlan1
vxlan source-interface Loopback1
vxlan udp-port 4789
vxlan vlan 100,1500-1779 vni 100,1500-1779

DC-1#show running-config section bgp >>>>>>>>>ADVERTISED VLANs
router bgp 100
(…omitted)
vlan-aware-bundle A
rd 100:1.1.1.1
route-target import 400:100
route-target export 100:100
redistribute learned
vlan 100,1500-1779

This Post Has 0 Comments

Leave a Reply

Your email address will not be published.

The Potential of Blockchain Technology in Cyber ​​Security

Blockchain technology has paved another way for innovative developments in…

Read more
Back To Top