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
import json
from jsonrpclib import Server
switches = ["bleaf1", "bleaf2", "bleaf3", "bleaf5"]
username = "admin"
password = "admin"
for switch in switches:
urlString = "https://{}:{}@{}/command-api".format(username, password, switch)
switchReq = Server( urlString )
@fredhsu
fredhsu / ChanPipelinesEapi.go
Created January 19, 2015 15:53
Go Pipelines with Arista eAPI
package aristalabstatus
import (
"encoding/json"
"flag"
"fmt"
"github.com/fredhsu/eapigo"
"io/ioutil"
"net/http"
"os"
[package]
name = "ovsdb"
version = "0.1.0"
authors = ["fredlhsu <fredlhsu@aristanetworks.com>"]
[dependencies.serde]
serde = "*"
[dependencies.serde_macros]
serde_macros = "*"
@fredhsu
fredhsu / counting-change.clj
Created May 8, 2011 22:31
SICP 1.2 in Clojure
(defn first-denomination [kinds-of-coins]
(cond (= kinds-of-coins 1) 1
(= kinds-of-coins 2) 5
(= kinds-of-coins 3) 10
(= kinds-of-coins 4) 25
(= kinds-of-coins 5) 50))
(defn cc [amount kinds-of-coins]
(cond (= amount 0) 1
(or (< amount 0) (= kinds-of-coins 0)) 0
:else (+ (cc amount
@fredhsu
fredhsu / twitterdump.java
Created September 11, 2011 23:36
Twitter stream to MongoDB
import com.mongodb.*;
import com.mongodb.util.JSON;
import twitter4j.TwitterException;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.StatusListener;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.internal.org.json.JSONObject;
import twitter4j.json.DataObjectFactory;
@fredhsu
fredhsu / twitterdump.clj
Created September 11, 2011 23:40
Twitter streaming api to mongodb in clojure
(ns twitterstream.core
(:require
[http.async.client :as client]
[org.danlarkin.json :as json])
(:use somnium.congomongo))
(mongo! :db "twitterdb") ; Mongo database called twitterdb
(def url "https://stream.twitter.com/1/statuses/sample.json")
(def cred {:user "username" :password "password"})
@fredhsu
fredhsu / EulerTour.py
Created August 6, 2012 18:51
Eulerian Tour Recursive
# Given a graph that is a list of edges between nodes
# i.e. [(0,1), (1,5), (5, 7), (7,1)]
def find_eulerian_tour(graph):
tour = []
find_tour(graph[0][0], graph, tour)
return tour
def find_tour(u, graph, tour):
for edge in graph:
if u == edge[0]:
@fredhsu
fredhsu / eapi.go
Created April 23, 2014 19:16
Using eAPI with Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/mitchellh/mapstructure"
)
@fredhsu
fredhsu / mystats-pom.xml
Last active December 17, 2015 07:28
POM file for mystats example
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.controller</groupId>
<artifactId>commons.opendaylight</artifactId>
<version>1.4.0-SNAPSHOT</version>
<relativePath>../../../controller/opendaylight/commons/opendaylight</relativePath>
</parent>