blob: 2d404a696741571849c195ab4bc04b1197b068f2 [file] [log] [blame]
Serge Bazanski8bdee5b2018-10-25 12:05:51 +01001package main
2
3import (
4 "context"
5
6 "github.com/golang/glog"
7 "google.golang.org/grpc/codes"
8 "google.golang.org/grpc/status"
9
Sergiusz Bazanski61594bb2019-07-21 15:20:51 +020010 pb "code.hackerspace.pl/hscloud/dc/arista-proxy/proto"
Serge Bazanski8bdee5b2018-10-25 12:05:51 +010011)
12
13func (s *server) ShowVersion(ctx context.Context, req *pb.ShowVersionRequest) (*pb.ShowVersionResponse, error) {
14 var version []struct {
15 ModelName string `json:"modelName"`
16 InternalVersion string `json:"internalVersion"`
17 SystemMacAddress string `json:"systemMacAddress"`
18 SerialNumber string `json:"serialNumber"`
19 MemTotal int64 `json:"memTotal"`
20 BootupTimestamp float64 `json:"bootupTimestamp"`
21 MemFree int64 `json:"memFree"`
22 Version string `json:"version"`
23 Architecture string `json:"architecture"`
24 InternalBuildId string `json:"internalBuildId"`
25 HardwareRevision string `json:"hardwareRevision"`
26 }
27
28 err := s.arista.structuredCall(&version, "show version")
29 if err != nil {
30 glog.Errorf("EOS Capi: show version: %v", err)
31 return nil, status.Error(codes.Unavailable, "EOS Capi call failed")
32 }
33
34 if len(version) != 1 {
35 glog.Errorf("Expected 1-length result, got %d", len(version))
36 return nil, status.Error(codes.Internal, "Internal error")
37 }
38
39 d := version[0]
40
41 return &pb.ShowVersionResponse{
42 ModelName: d.ModelName,
43 InternalVersion: d.InternalVersion,
44 SystemMacAddress: d.SystemMacAddress,
45 SerialNumber: d.SerialNumber,
46 MemTotal: d.MemTotal,
47 BootupTimestamp: d.BootupTimestamp,
48 MemFree: d.MemFree,
49 Version: d.Version,
50 Architecture: d.Architecture,
51 InternalBuildId: d.InternalBuildId,
52 HardwareRevision: d.HardwareRevision,
53 }, nil
54}
55
56type temperatureSensor struct {
57 InAlertState bool `json:"inAlertState"`
58 MaxTemperature float64 `json:"maxTemperature"`
Sergiusz Bazanski47b7e852019-09-26 18:32:39 +020059 RelPos string `json:"relPos"`
Serge Bazanski8bdee5b2018-10-25 12:05:51 +010060 Description string `json:"description"`
61 Name string `json:"name"`
62 AlertCount int64 `json:"alertCount"`
63 CurrentTemperature float64 `json:"currentTemperature"`
64 OverheatThreshold float64 `json:"overheatThreshold"`
65 CriticalThreshold float64 `json:"criticalThreshold"`
66 HwStatus string `json:"hwStatus"`
67}
68
Sergiusz Bazanski47b7e852019-09-26 18:32:39 +020069func (t *temperatureSensor) Proto() *pb.ShowEnvironmentTemperatureResponse_TemperatureSensor {
70 return &pb.ShowEnvironmentTemperatureResponse_TemperatureSensor{
71 InAlertState: t.InAlertState,
72 MaxTemperature: t.MaxTemperature,
73 RelPos: t.RelPos,
74 Description: t.Description,
75 Name: t.Name,
76 AlertCount: t.AlertCount,
77 CurrentTemperature: t.CurrentTemperature,
78 OverheatThreshold: t.OverheatThreshold,
79 CriticalThreshold: t.CriticalThreshold,
80 HwStatus: t.HwStatus,
81 }
82}
83
Serge Bazanski8bdee5b2018-10-25 12:05:51 +010084func (s *server) ShowEnvironmentTemperature(ctx context.Context, req *pb.ShowEnvironmentTemperatureRequest) (*pb.ShowEnvironmentTemperatureResponse, error) {
85 var response []struct {
Sergiusz Bazanski47b7e852019-09-26 18:32:39 +020086 PowerSupplySlots []struct {
Serge Bazanski8bdee5b2018-10-25 12:05:51 +010087 TempSensors []temperatureSensor `json:"tempSensors"`
88 EntPhysicalClass string `json:"entPhysicalClass"`
Sergiusz Bazanski47b7e852019-09-26 18:32:39 +020089 RelPos string `json:"relPos"`
Serge Bazanski8bdee5b2018-10-25 12:05:51 +010090 } `json:"powerSupplySlots"`
91
92 ShutdownOnOverheat bool `json:"shutdownOnOverheat"`
93 TempSensors []temperatureSensor `json:"tempSensors"`
94 SystemStatus string `json:"systemStatus"`
95 }
96
97 err := s.arista.structuredCall(&response, "show environment temperature")
98 if err != nil {
99 glog.Errorf("EOS Capi: show environment temperature: %v", err)
100 return nil, status.Error(codes.Unavailable, "EOS Capi call failed")
101 }
102
103 if len(response) != 1 {
104 glog.Errorf("Expected 1-length result, got %d", len(response))
105 return nil, status.Error(codes.Internal, "Internal error")
106 }
107
108 d := response[0]
Serge Bazanski8bdee5b2018-10-25 12:05:51 +0100109
Sergiusz Bazanski47b7e852019-09-26 18:32:39 +0200110 res := &pb.ShowEnvironmentTemperatureResponse{
111 SystemStatus: d.SystemStatus,
112 ShutdownOnOverheat: d.ShutdownOnOverheat,
113 PowerSupplySlots: make([]*pb.ShowEnvironmentTemperatureResponse_PowerSupplySlot, len(d.PowerSupplySlots)),
114 TemperatureSensors: make([]*pb.ShowEnvironmentTemperatureResponse_TemperatureSensor, len(d.TempSensors)),
115 }
116
117 for i, t := range d.TempSensors {
118 res.TemperatureSensors[i] = t.Proto()
119 }
120
121 for i, p := range d.PowerSupplySlots {
122 res.PowerSupplySlots[i] = &pb.ShowEnvironmentTemperatureResponse_PowerSupplySlot{
123 EntPhysicalClass: p.EntPhysicalClass,
124 RelPos: p.RelPos,
125 TemperatureSensors: make([]*pb.ShowEnvironmentTemperatureResponse_TemperatureSensor, len(p.TempSensors)),
126 }
127 for j, t := range p.TempSensors {
128 res.PowerSupplySlots[i].TemperatureSensors[j] = t.Proto()
129 }
130 }
131
132 return res, nil
Serge Bazanski8bdee5b2018-10-25 12:05:51 +0100133}