From 47b7e850e736f0898860b2d948f6cdef5dc17a1c Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Thu, 26 Sep 2019 18:32:39 +0200 Subject: [PATCH] dc/arista-proxy: fix by using github.com/q3k/cursedjson Change-Id: Id9657a30af8c16afe4ddde7e2ac04f4508a2fd18 --- WORKSPACE | 18 ++++++++---- dc/arista-proxy/BUILD.bazel | 2 +- dc/arista-proxy/main.go | 6 ++-- dc/arista-proxy/proto/arista.proto | 21 ++++++++++++++ dc/arista-proxy/service.go | 46 ++++++++++++++++++++++++++---- 5 files changed, 78 insertions(+), 15 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index a1b2b2c0..cabd7d78 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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", +) diff --git a/dc/arista-proxy/BUILD.bazel b/dc/arista-proxy/BUILD.bazel index fb7ec6af..e3370681 100644 --- a/dc/arista-proxy/BUILD.bazel +++ b/dc/arista-proxy/BUILD.bazel @@ -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", ], diff --git a/dc/arista-proxy/main.go b/dc/arista-proxy/main.go index ccd10462..ed4a9b36 100644 --- a/dc/arista-proxy/main.go +++ b/dc/arista-proxy/main.go @@ -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() diff --git a/dc/arista-proxy/proto/arista.proto b/dc/arista-proxy/proto/arista.proto index 2874f702..3bd254dd 100644 --- a/dc/arista-proxy/proto/arista.proto +++ b/dc/arista-proxy/proto/arista.proto @@ -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 { diff --git a/dc/arista-proxy/service.go b/dc/arista-proxy/service.go index 3144ff74..2d404a69 100644 --- a/dc/arista-proxy/service.go +++ b/dc/arista-proxy/service.go @@ -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 }