hscloud/main.go

71 lines
1.9 KiB
Go
Raw Normal View History

2018-08-27 19:40:10 +00:00
package main
import (
"flag"
"fmt"
"github.com/golang/glog"
"github.com/ybbus/jsonrpc"
)
var (
flagAristaAPI string
flagListenAddress string
flagDebugAddress string
flagCAPath string
flagCertificatePath string
flagKeyPath string
)
type aristaClient struct {
rpc jsonrpc.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
}
func main() {
flag.StringVar(&flagAristaAPI, "arista_api", "http://admin:password@1.2.3.4:80/command-api", "Arista remote endpoint")
2018-08-27 20:03:03 +00:00
flag.StringVar(&flagListenAddress, "listen_address", "127.0.0.1:42000", "gRPC listen address")
flag.StringVar(&flagDebugAddress, "debug_address", "127.0.0.1:42001", "Debug HTTP listen address, or empty to disable")
2018-08-27 19:40:10 +00:00
flag.StringVar(&flagCAPath, "tls_ca_path", "pki/ca.pem", "Path to PKI CA certificate")
flag.StringVar(&flagCertificatePath, "tls_certificate_path", "pki/service.pem", "Path to PKI service certificate")
flag.StringVar(&flagKeyPath, "tls_key_path", "pki/service-key.pem", "Path to PKI service private key")
flag.Set("logtostderr", "true")
flag.Parse()
arista := &aristaClient{
rpc: jsonrpc.NewClient(flagAristaAPI),
}
opts := &serverOpts{
listenAddress: flagListenAddress,
debugAddress: flagDebugAddress,
tlsCAPath: flagCAPath,
tlsCertificatePath: flagCertificatePath,
tlsKeyPath: flagKeyPath,
}
server, err := newServer(opts, arista)
if err != nil {
glog.Errorf("Could not create server: %v", err)
}
glog.Info("Starting up...")
server.serveForever()
}