Skip to content

Instantly share code, notes, and snippets.

@fredhsu
fredhsu / Activator.java
Created July 11, 2013 13:56
getpackets activator
package com.example.getpackets;
import java.util.Hashtable;
import java.util.Dictionary;
import org.apache.felix.dm.Component;
import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
import org.opendaylight.controller.sal.packet.IDataPacketService;
import org.opendaylight.controller.sal.packet.IListenDataPacket;
import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.slf4j.Logger;
@fredhsu
fredhsu / ssh-router.exs
Last active January 29, 2016 02:40
SSH to router using Elixir
:ssh.start
{:ok, cref} = :ssh.connect('10.55.3.1', 22, [{:user, 'user'}, {:password, 'password'}])
{:ok, cid} = :ssh_connection.session_channel(cref, 5000)
:ssh_connection.exec(cref, cid, String.to_char_list("show ver | xml | no-more"), 3000)
#:ssh_connection.exec(cref, cid, String.to_char_list("show core"), 3000)
# need to do a receive on the cref(pid)
#flush() -- useful to find out what the result will look like
receive do
{:ssh_cm, _, {:data, _, _, d}} -> IO.puts d
end
@fredhsu
fredhsu / libvirt-mac.py
Created October 2, 2013 22:33
Libvirt Python API sample, searching for a VM with a particular MAC address
import libvirt
import xml.etree.ElementTree as ET
def findDomainWithMac(conn, addr):
domlist = map(conn.lookupByID, conn.listDomainsID())
for dom in domlist:
root = ET.fromstring(dom.XMLDesc())
searchString = "./devices/interface/mac[@address='{0}']".format(addr)
if (root.find(searchString) is not None):
return dom
@fredhsu
fredhsu / local.conf
Created January 11, 2014 15:47
Local.conf file for devstack using Neutron, ML2, and allowing connectivity to an external switch
[[local|localrc]]
HOST_IP=172.22.28.204
# Interface connected to switch
FLAT_INTERFACE=eth1
# Logging settings
LOGDAYS=1
LOGFILE=$DEST/logs/stack.sh.log
SCREEN_LOGDIR=$DEST/logs/screen
@fredhsu
fredhsu / AristaOMIPowerShell.ps1
Created January 28, 2014 02:03
Example PowerShell script for talking to an Arista Switch via OMI
# Create an object which represents session options
# -SkipCACheck and -SkipCNCheck are used to skip SSL certificate checks
$so = New-CimSessionOption -SkipCACheck -SkipCNCheck -UseSsl
# Switch credentials
$password = ConvertTo-SecureString "password" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential( "admin", $password )
# Create a session to the switch
$switch = "172.22.28.159"
@fredhsu
fredhsu / eAPI-example-vlans.py
Created February 13, 2014 06:36
Quick example of JSON-RPC for Arista eAPI
import json
from jsonrpclib import Server
switches = ["172.22.28.156", "172.22.28.157", "172.22.28.158"]
username = "admin"
password = "admin"
# Going through all the switch IP addresses listed above
for switch in switches:
urlString = "https://{}:{}@{}/command-api".format(username, password, switch)
@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 / 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"
)