Skip to content

Instantly share code, notes, and snippets.

import json
from jsonrpclib import Server
username = "admin"
password = "admin"
urlString = "https://{}:{}@{}/command-api".format(username, password, "bleaf1")
switchReq = Server( urlString )
response = switchReq.runCmds( 1, ["enable", "show running-config"], "text" )
print response
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
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/"
@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"}
@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 / 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 / packstack-answers.txt
Created September 16, 2014 17:13
Packstack answers file for building OpenStack with VLAN type driver
[general]
# Path to a Public key to install on servers. If a usable key has not
# been installed on the remote servers the user will be prompted for a
# password and this key will be installed so the password will not be
# required again
CONFIG_SSH_KEY=/root/.ssh/id_rsa.pub
# Set to 'y' if you would like Packstack to install MySQL
CONFIG_MYSQL_INSTALL=y
@fredhsu
fredhsu / eAPI-simple.ps1
Last active September 12, 2016 10:48
eAPI from Powershell
$username = "admin"
$password = "admin"
$switchIp = "172.22.28.157"
#URL
$eApiUrl = "https://$switchIp/command-api"
# Command(s) we want to send
$cmds = @('show version')
@fredhsu
fredhsu / odlgo.go
Created May 29, 2014 03:00
ODL From Go
package main
import (
"fmt"
"net/http"
"strings"
"io/ioutil"
"encoding/json"
)