{"id":1846,"date":"2023-01-23T16:14:56","date_gmt":"2023-01-23T13:14:56","guid":{"rendered":"https:\/\/www.netsys.com.tr\/en\/?p=1846"},"modified":"2023-01-23T16:15:41","modified_gmt":"2023-01-23T13:15:41","slug":"automation-arista-evpn-vxlan-with-python","status":"publish","type":"post","link":"https:\/\/www.netsys.com.tr\/en\/automation-arista-evpn-vxlan-with-python\/","title":{"rendered":"Automation Arista EVPN-VXLAN with Python"},"content":{"rendered":"[vc_row][vc_column][vc_column_text el_class=&#8221;paraglead themeprimarydark&#8221;]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.<\/p>\n<p>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.<\/p>\n<p>Some requirements are needed to use Python on Arista switches.<\/p>\n<ul>\n<li>The jsonrclib library must be imported to use some json methods. This library is required to use REST API in json format.<\/li>\n<li>Arista switches&#8217; API URL of the jsonrpclib library.\u00a0It 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.<\/li>\n<li>The ssl library must be imported to pass the SSL verification.<\/li>\n<li>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.<\/li>\n<li>In the sample code; The cmds list will be used to apply commands to devices. Commands take variables to be more flexible.<\/li>\n<\/ul>\n<div class=\"wpb_text_column wpb_content_element themeprimarydark theme-h3\">\n<div class=\"wpb_wrapper\">\n<p>&nbsp;<\/p>\n<p><strong>Python Code<\/strong><\/p>\n<div class=\"vcex-spacing wpex-w-100 wpex-clear\" style=\"height:30px;\"><\/div>\n<\/div>\n<\/div>\n<p><em><div class=\"su-note\"  style=\"border-color:#dbdbdb;border-radius:10px;-moz-border-radius:10px;-webkit-border-radius:10px;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#f5f5f5;border-color:#ffffff;color:#333333;border-radius:10px;-moz-border-radius:10px;-webkit-border-radius:10px;\"><\/em>import jsonrpclib<br \/>\nfrom pprint import pprint<br \/>\nimport ssl<br \/>\nssl._create_default_https_context = ssl._create_unverified_context<\/p>\n<p>port=443<br \/>\nusername=&#8217;admin&#8217;<br \/>\npassword=&#8217;arista&#8217;<br \/>\nip=&#8217;172.16.91.200&#8242;<br \/>\nvlan= &#8220;1500-1779&#8221;<br \/>\nasnumber=&#8221;100&#8243;<\/p>\n<p>cmds= [<br \/>\n&#8220;configure&#8221;,<br \/>\n&#8220;vlan&#8221; +&#8217; &#8216;+str(vlan),<br \/>\n&#8220;interface vxlan 1&#8221;,<br \/>\n&#8220;vxlan vlan add&#8221;+&#8217; &#8216;+ str(vlan)+&#8217; &#8216;+&#8221;vni&#8221;+&#8217; &#8216;+str(vlan),<br \/>\n&#8220;router bgp &#8220;+&#8217; &#8216;+str(asnumber),<br \/>\n&#8220;vlan-aware-bundle A&#8221;,<br \/>\n&#8220;vlan add&#8221;+&#8217; &#8216;+str(vlan),<br \/>\n&#8220;write memory&#8221;<br \/>\n]\n<p>eapi_url=&#8217;https:\/\/{}:{}@{}:{}\/command-api&#8217;.format(username, password, ip, port)<br \/>\neapi_conn = jsonrpclib.Server(eapi_url)<br \/>\nresponse = eapi_conn.runCmds(1,cmds)<br \/>\npprint(response)<\/div><\/div> <div class=\"vcex-spacing wpex-w-100 wpex-clear\" style=\"height:30px;\"><\/div>\n<p><strong>Result<\/strong><\/p>\n<div class=\"vcex-spacing wpex-w-100 wpex-clear\" style=\"height:30px;\"><\/div>\n<em><div class=\"su-note\"  style=\"border-color:#dbdbdb;border-radius:10px;-moz-border-radius:10px;-webkit-border-radius:10px;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#f5f5f5;border-color:#ffffff;color:#333333;border-radius:10px;-moz-border-radius:10px;-webkit-border-radius:10px;\"><\/em>DC-1#show vlan &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;CREATED VLANs<br \/>\nVLAN Name Status Ports<br \/>\n1500 VLAN1500 active Vx1<br \/>\n1501 VLAN1501 active Vx1<br \/>\n1502 VLAN1502 active Vx1<br \/>\n(&#8230;omitted)<br \/>\n1778 VLAN1778 active Vx1<br \/>\n1779 VLAN1779 active Vx1<\/p>\n<p>DC-1#show running-config interfaces vxlan 1 &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;CREATED VNIs<br \/>\ninterface Vxlan1<br \/>\nvxlan source-interface Loopback1<br \/>\nvxlan udp-port 4789<br \/>\nvxlan vlan 100,1500-1779 vni 100,1500-1779<\/p>\n<p>DC-1#show running-config section bgp &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;ADVERTISED VLANs<br \/>\nrouter bgp 100<br \/>\n(&#8230;omitted)<br \/>\nvlan-aware-bundle A<br \/>\nrd 100:1.1.1.1<br \/>\nroute-target import 400:100<br \/>\nroute-target export 100:100<br \/>\nredistribute learned<br \/>\nvlan 100,1500-1779<\/div><\/div>[\/vc_column_text][\/vc_column][\/vc_row]\n","protected":false},"excerpt":{"rendered":"<p>[vc_row][vc_column][vc_column_text el_class=&#8221;paraglead themeprimarydark&#8221;]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&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1849,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/posts\/1846"}],"collection":[{"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/comments?post=1846"}],"version-history":[{"count":2,"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/posts\/1846\/revisions"}],"predecessor-version":[{"id":1848,"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/posts\/1846\/revisions\/1848"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/media\/1849"}],"wp:attachment":[{"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/media?parent=1846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/categories?post=1846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.netsys.com.tr\/en\/wp-json\/wp\/v2\/tags?post=1846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}