blob: 15c9262fe894adbffcc8cc1098c8e995f008e18e [file] [log] [blame]
package main
import (
"flag"
"fmt"
"code.hackerspace.pl/hscloud/go/mirko"
"github.com/golang/glog"
cursedjsonrpc "github.com/q3k/cursedjsonrpc"
pb "code.hackerspace.pl/hscloud/dc/arista-proxy/proto"
)
var (
flagAristaAPI string
)
type aristaClient struct {
rpc cursedjsonrpc.RPCClient
}
func (c *aristaClient) structuredCall(res interface{}, command ...string) error {
cmd := struct {
Version int `json:"version"`
Cmds []string `json:"cmds"`
Format string `json:"format"`
}{
Version: 1,
Cmds: command,
Format: "json",
}
err := c.rpc.CallFor(res, "runCmds", cmd)
if err != nil {
return fmt.Errorf("could not execute structured call: %v", err)
}
return nil
}
type server struct {
arista *aristaClient
}
func main() {
flag.StringVar(&flagAristaAPI, "arista_api", "http://admin:password@1.2.3.4:80/command-api", "Arista remote endpoint")
flag.Parse()
arista := &aristaClient{
rpc: cursedjsonrpc.NewClient(flagAristaAPI),
}
m := mirko.New()
if err := m.Listen(); err != nil {
glog.Exitf("Listen(): %v", err)
}
s := &server{
arista: arista,
}
pb.RegisterAristaProxyServer(m.GRPC(), s)
if err := m.Serve(); err != nil {
glog.Exitf("Serve(): %v", err)
}
select {}
}