dc/arista-proxy: fix by using github.com/q3k/cursedjson

Change-Id: Id9657a30af8c16afe4ddde7e2ac04f4508a2fd18
This commit is contained in:
q3k 2019-09-26 18:32:39 +02:00
parent 6781f62ec4
commit 47b7e850e7
5 changed files with 78 additions and 15 deletions

View file

@ -295,12 +295,6 @@ go_repository(
importpath = "github.com/ziutek/telnet",
)
go_repository(
name = "com_github_ybbus_jsonrpc",
commit = "94088458a1e880219bd312fc0ccb8548993ebf80",
importpath = "github.com/ybbus/jsonrpc",
)
go_repository(
name = "com_github_digitalocean_go_netbox",
commit = "29433ec527e78486ea0a5758817ab672d977f90e",
@ -712,3 +706,15 @@ go_repository(
commit = "f715ec2f112d1e4195b827ad68cf44017a3ef2b1",
importpath = "gopkg.in/asn1-ber.v1",
)
go_repository(
name = "com_github_q3k_cursedjsonrpc",
commit = "304f0561c9162a2696f3ae7c96f3404324177ab8",
importpath = "github.com/q3k/cursedjsonrpc",
)
go_repository(
name = "com_github_q3k_cursedjson",
commit = "af0e3abb1bcef7197b3b9f91d7d094e6528a2d05",
importpath = "github.com/q3k/cursedjson",
)

View file

@ -12,7 +12,7 @@ go_library(
"//dc/arista-proxy/proto:go_default_library",
"//go/mirko:go_default_library",
"@com_github_golang_glog//:go_default_library",
"@com_github_ybbus_jsonrpc//:go_default_library",
"@com_github_q3k_cursedjsonrpc//:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
],

View file

@ -6,7 +6,7 @@ import (
"code.hackerspace.pl/hscloud/go/mirko"
"github.com/golang/glog"
"github.com/ybbus/jsonrpc"
"github.com/q3k/cursedjsonrpc"
pb "code.hackerspace.pl/hscloud/dc/arista-proxy/proto"
)
@ -16,7 +16,7 @@ var (
)
type aristaClient struct {
rpc jsonrpc.RPCClient
rpc cursedjsonrpc.RPCClient
}
func (c *aristaClient) structuredCall(res interface{}, command ...string) error {
@ -46,7 +46,7 @@ func main() {
flag.Parse()
arista := &aristaClient{
rpc: jsonrpc.NewClient(flagAristaAPI),
rpc: cursedjsonrpc.NewClient(flagAristaAPI),
}
m := mirko.New()

View file

@ -23,6 +23,27 @@ message ShowEnvironmentTemperatureRequest {
};
message ShowEnvironmentTemperatureResponse {
message TemperatureSensor {
bool in_alert_state = 1;
double max_temperature = 2;
string rel_pos = 3;
string description = 4;
string name = 5;
int64 alert_count = 6;
double current_temperature = 7;
double overheat_threshold = 8;
double critical_threshold = 9;
string hw_status = 10;
};
message PowerSupplySlot {
string ent_physical_class = 1;
string rel_pos = 2;
repeated TemperatureSensor temperature_sensors = 3;
};
string system_status = 1;
bool shutdown_on_overheat = 2;
repeated PowerSupplySlot power_supply_slots = 3;
repeated TemperatureSensor temperature_sensors = 4;
};
service AristaProxy {

View file

@ -56,7 +56,7 @@ func (s *server) ShowVersion(ctx context.Context, req *pb.ShowVersionRequest) (*
type temperatureSensor struct {
InAlertState bool `json:"inAlertState"`
MaxTemperature float64 `json:"maxTemperature"`
RelPos int64 `json:"relPos"`
RelPos string `json:"relPos"`
Description string `json:"description"`
Name string `json:"name"`
AlertCount int64 `json:"alertCount"`
@ -66,12 +66,27 @@ type temperatureSensor struct {
HwStatus string `json:"hwStatus"`
}
func (t *temperatureSensor) Proto() *pb.ShowEnvironmentTemperatureResponse_TemperatureSensor {
return &pb.ShowEnvironmentTemperatureResponse_TemperatureSensor{
InAlertState: t.InAlertState,
MaxTemperature: t.MaxTemperature,
RelPos: t.RelPos,
Description: t.Description,
Name: t.Name,
AlertCount: t.AlertCount,
CurrentTemperature: t.CurrentTemperature,
OverheatThreshold: t.OverheatThreshold,
CriticalThreshold: t.CriticalThreshold,
HwStatus: t.HwStatus,
}
}
func (s *server) ShowEnvironmentTemperature(ctx context.Context, req *pb.ShowEnvironmentTemperatureRequest) (*pb.ShowEnvironmentTemperatureResponse, error) {
var response []struct {
PowerSuppplySlots []struct {
PowerSupplySlots []struct {
TempSensors []temperatureSensor `json:"tempSensors"`
EntPhysicalClass string `json:"entPhysicalClass"`
RelPos int64 `json:"relPos"`
RelPos string `json:"relPos"`
} `json:"powerSupplySlots"`
ShutdownOnOverheat bool `json:"shutdownOnOverheat"`
@ -91,7 +106,28 @@ func (s *server) ShowEnvironmentTemperature(ctx context.Context, req *pb.ShowEnv
}
d := response[0]
glog.Infof("%+v", d)
return &pb.ShowEnvironmentTemperatureResponse{}, nil
res := &pb.ShowEnvironmentTemperatureResponse{
SystemStatus: d.SystemStatus,
ShutdownOnOverheat: d.ShutdownOnOverheat,
PowerSupplySlots: make([]*pb.ShowEnvironmentTemperatureResponse_PowerSupplySlot, len(d.PowerSupplySlots)),
TemperatureSensors: make([]*pb.ShowEnvironmentTemperatureResponse_TemperatureSensor, len(d.TempSensors)),
}
for i, t := range d.TempSensors {
res.TemperatureSensors[i] = t.Proto()
}
for i, p := range d.PowerSupplySlots {
res.PowerSupplySlots[i] = &pb.ShowEnvironmentTemperatureResponse_PowerSupplySlot{
EntPhysicalClass: p.EntPhysicalClass,
RelPos: p.RelPos,
TemperatureSensors: make([]*pb.ShowEnvironmentTemperatureResponse_TemperatureSensor, len(p.TempSensors)),
}
for j, t := range p.TempSensors {
res.PowerSupplySlots[i].TemperatureSensors[j] = t.Proto()
}
}
return res, nil
}