Skip to content

Instantly share code, notes, and snippets.

@fredhsu
fredhsu / poll.py
Created February 13, 2014 18:49
Example of polling an interface for statistics in eAPI and Python
from jsonrpclib import Server
import time
username = "fredlhsu"
password = "arista"
host = "172.22.28.37"
def getInterfaceStats():
dictionary = eApiCall()
interfaces = []
@fredhsu
fredhsu / macrewrite.py
Created February 13, 2014 21:24
Example of rewriting source and destination mac with DirectFlow via eAPI
from jsonrpclib import Server
username = "admin"
password = "admin"
host = "172.22.28.156"
sip = "10.1.1.1"
smac = "0000.aaaa.bbbb"
dmac = "1111.aaaa.bbbb"
urlString = "https://{}:{}@{}/command-api".format(username, password, switch)
switchReq = Server( urlString )
@fredhsu
fredhsu / setoutput.py
Created February 13, 2014 22:10
DirectFlow example that matches on destination IP and sets the output port
from jsonrpclib import Server
username = "admin"
password = "admin"
host = "172.22.28.156"
dip = "10.1.1.1"
outport = "Port-Channel 100"
urlString = "https://{}:{}@{}/command-api".format(username, password, switch)
switchReq = Server( urlString )
# The following rpc request will match on the source IP, then change both source and dest mac
@fredhsu
fredhsu / odlgo.go
Created May 29, 2014 03:00
ODL From Go
package main
import (
"fmt"
"net/http"
"strings"
"io/ioutil"
"encoding/json"
)
@fredhsu
fredhsu / gwfinder.py
Created September 30, 2014 02:48
Simple eAPI script to try out different ip addresses on an interface. Starting a 3 and going until 254
import jsonrpclib
import time
name = "demo1"
switchReq = jsonrpclib.Server("http://admin:admin@" + name +
"/command-api")
for i in range(3,2545:
ipaddr = "ip address 2.2.2.{}/24".format(i)
response = switchReq.runCmds(1, ["enable", "configure", "interface ethernet 52", ipaddr])
print "trying " + ipaddr
@fredhsu
fredhsu / vrf.py
Created October 21, 2014 14:24
eAPI script to see all the arp entries per VRF
from jsonrpclib import Server
switch = Server( "https://admin:admin@leaf1/command-api" )
response = switch.runCmds( 1, ["show vrf"], "text" )
lines = response[0]['output'].splitlines()
for line in lines:
print line
for i in range(2, len(lines) - 1):
@fredhsu
fredhsu / shrun1.go
Last active August 29, 2015 14:08
Some examples of using Go with concurrency for eAPI
package main
import (
"fmt"
"github.com/fredhsu/go-eapi"
//"time"
)
func main() {
cmds2 := []string{"enable", "show running-config"}
package main
import (
"fmt"
"github.com/fredhsu/go-eapi"
)
func main() {
cmds2 := []string{"enable", "show running-config"}
url1 := "https://admin:admin@bleaf1/command-api/"
package main
import (
"fmt"
"github.com/fredhsu/go-eapi"
)
func main() {
cmds2 := []string{"enable", "show running-config"}
url1 := "https://admin:admin@bleaf1/command-api/"
package main
import (
"fmt"
"github.com/fredhsu/go-eapi"
)
func configFetcher(url string, cmds []string, format string, c chan eapi.JsonRpcResponse) {
response := eapi.Call(url, cmds, format)
c <- response