Sergiusz Bazanski | e08e6da | 2018-08-27 20:40:10 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "github.com/golang/glog" |
| 7 | "google.golang.org/grpc/codes" |
| 8 | "google.golang.org/grpc/status" |
| 9 | |
| 10 | pb "code.hackerspace.pl/q3k/arista-proxy/proto" |
| 11 | ) |
| 12 | |
| 13 | func (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 | } |