dc/arista-proxy: fix by using github.com/q3k/cursedjson
Change-Id: Id9657a30af8c16afe4ddde7e2ac04f4508a2fd18
diff --git a/WORKSPACE b/WORKSPACE
index a1b2b2c..cabd7d7 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -296,12 +296,6 @@
)
go_repository(
- name = "com_github_ybbus_jsonrpc",
- commit = "94088458a1e880219bd312fc0ccb8548993ebf80",
- importpath = "github.com/ybbus/jsonrpc",
-)
-
-go_repository(
name = "com_github_digitalocean_go_netbox",
commit = "29433ec527e78486ea0a5758817ab672d977f90e",
importpath = "github.com/digitalocean/go-netbox",
@@ -712,3 +706,15 @@
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",
+)
diff --git a/dc/arista-proxy/BUILD.bazel b/dc/arista-proxy/BUILD.bazel
index fb7ec6a..e337068 100644
--- a/dc/arista-proxy/BUILD.bazel
+++ b/dc/arista-proxy/BUILD.bazel
@@ -12,7 +12,7 @@
"//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",
],
diff --git a/dc/arista-proxy/main.go b/dc/arista-proxy/main.go
index ccd1046..ed4a9b3 100644
--- a/dc/arista-proxy/main.go
+++ b/dc/arista-proxy/main.go
@@ -6,7 +6,7 @@
"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 @@
)
type aristaClient struct {
- rpc jsonrpc.RPCClient
+ rpc cursedjsonrpc.RPCClient
}
func (c *aristaClient) structuredCall(res interface{}, command ...string) error {
@@ -46,7 +46,7 @@
flag.Parse()
arista := &aristaClient{
- rpc: jsonrpc.NewClient(flagAristaAPI),
+ rpc: cursedjsonrpc.NewClient(flagAristaAPI),
}
m := mirko.New()
diff --git a/dc/arista-proxy/proto/arista.proto b/dc/arista-proxy/proto/arista.proto
index 2874f70..3bd254d 100644
--- a/dc/arista-proxy/proto/arista.proto
+++ b/dc/arista-proxy/proto/arista.proto
@@ -23,6 +23,27 @@
};
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 {
diff --git a/dc/arista-proxy/service.go b/dc/arista-proxy/service.go
index 3144ff7..2d404a6 100644
--- a/dc/arista-proxy/service.go
+++ b/dc/arista-proxy/service.go
@@ -56,7 +56,7 @@
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 @@
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 @@
}
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
}