Make Simpler Your Network Operation with Python on Arista EVPN-VXLAN

Today, I will give real example which we use in one of customer in order to connect two different DC over Internet with EVPN-VXLAN. Careful, it is over INTERNET, not MPLS or dedicated circuits. As we discussed before posts, EVPN-VXLAN provides layer 2 extension. In such a topology, you can often create VLANs and advertise to eachother. But you should be careful in running environment when creating or advertising those VLANs. We will make simpler our network operation with python script on EVPN-VXLAN of Arista environment. We will benefit from API of Arista switches.

In topology, there are two DCs that are connected over Internet via BGP. Customers’ PCs are conected to DC switches and they will be in same Layer2 broadcast domain via EVPN-VXLAN.


In order to use Python to Arista, we need some requirements for code. First, you should import jsonrpclib library to use some json methods. Because we will use REST API interaction to Arista. REST API is in json format and we will try to access API URL of Arista switch with Server method of jsonrpclib. This method requires some parameters as username, password, IP, port. It is eapi_url variable in our code.

Second, we need to bypass SSL verification. If not, it will give warning.So import ssl library as in code.

Third part, we define our parameters in order to access API and some varibles that will be used in commands to apply device. In this example, we will create vlan range 1500-1779 and advertise them to EVPN.

Last, cmds variable is our commands to apply devices. It is a list that include our commands. As you will see, our commands take some variables to be more flexible.

Python Code Partition

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

vlan= "1500-1779"

cmds= [
            "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)

Results on Switch

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
vlan-aware-bundle A
rd 100:
route-target import 400:100
route-target export 100:100
redistribute learned
vlan 100,1500-1779

Mahmut Aydin
CCIE R&S #63405

Leave a Reply