dc/arista-proxy: fix by using github.com/q3k/cursedjson
Change-Id: Id9657a30af8c16afe4ddde7e2ac04f4508a2fd18
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
}