Skip to content

Instantly share code, notes, and snippets.

@mathershifter
Last active March 14, 2024 19:44
Show Gist options
  • Save mathershifter/92223aa6e2313aae2362b334c6b8f2ac to your computer and use it in GitHub Desktop.
Save mathershifter/92223aa6e2313aae2362b334c6b8f2ac to your computer and use it in GitHub Desktop.
Example user-defined module for goeapi
package main
import (
"fmt"
"github.com/aristanetworks/goeapi"
)
type ShowRibRouteIp struct {
RibRoutesByProtocol map[string]Protocol
}
type Protocol struct {
RibRoutes map[string]Route
}
type Route struct {
Tag int
BestRoute bool
Preference int
LoopedRoute bool
Metric int
ResolvedNextHops []NextHop
}
type NextHop struct {
IpNextHop IpNextHop
TransportType string
}
type IpNextHop struct {
Interface string
}
func (s *ShowRibRouteIp) GetCmd() string {
return "show rib route ip"
}
func main() {
node, err := goeapi.Connect("http", "<dut>", "admin", "", 80)
if err != nil {
panic(err)
}
r := &ShowRibRouteIp{}
handle, _ := node.GetHandle("json")
handle.AddCommand(r)
if err := handle.Call(); err != nil {
panic(err)
}
for k, v := range r.RibRoutesByProtocol {
fmt.Printf("Protocol:%s\n", k)
fmt.Printf(" Routes : %+v\n", v.RibRoutes)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment