blob: dc0cfb4888eb88d79fa742c2afed71e2f0e1dde8 [file] [log] [blame]
Serge Bazanski753d63f2018-10-14 15:21:46 -07001package main
2
3import (
4 "context"
5 "flag"
6
Serge Bazanski965b78a2018-10-25 12:22:37 +01007 "code.hackerspace.pl/hscloud/go/mirko"
Serge Bazanski753d63f2018-10-14 15:21:46 -07008 "github.com/golang/glog"
9 "google.golang.org/grpc/codes"
10 "google.golang.org/grpc/status"
11
Sergiusz Bazanski61594bb2019-07-21 15:20:51 +020012 pb "code.hackerspace.pl/hscloud/dc/cmc-proxy/proto"
Serge Bazanski753d63f2018-10-14 15:21:46 -070013)
14
15var (
16 flagCMCAddress string
17 flagCMCUsername string
18 flagCMCPassword string
19)
20
21const (
22 pathLogin = "cgi-bin/webcgi/login"
23 pathLogout = "cgi-bin/webcgi/logout"
24 pathiDRACURL = "cgi-bin/webcgi/blade_iDRAC_url"
25)
26
27func init() {
28 flag.Set("logtostderr", "true")
29}
30
31type service struct {
32 cmc *cmcClient
33}
34
35func (s *service) GetKVMData(ctx context.Context, req *pb.GetKVMDataRequest) (*pb.GetKVMDataResponse, error) {
36 if req.BladeNum < 1 || req.BladeNum > 16 {
37 return nil, status.Error(codes.InvalidArgument, "blade_num must be [1,16]")
38 }
39
40 details, err := s.cmc.RequestKVMDetails(ctx, int(req.BladeNum))
41 if err != nil {
42 glog.Errorf("RequestKVMDetails(_, %d): %v", req.BladeNum, err)
43 return nil, status.Error(codes.Unavailable, "CMC unavailable")
44 }
45
46 return &pb.GetKVMDataResponse{
47 Arguments: details.arguments,
48 }, nil
49}
50
51func main() {
52 flag.StringVar(&flagCMCAddress, "cmc_address", "https://10.10.10.10", "URL of Dell M1000e CMC")
53 flag.StringVar(&flagCMCUsername, "cmc_username", "root", "Login username for CMC")
54 flag.StringVar(&flagCMCPassword, "cmc_password", "", "Login password for CMC")
55 flag.Parse()
56
57 m := mirko.New()
58 if err := m.Listen(); err != nil {
59 glog.Exitf("Could not listen: %v", err)
60 }
61
62 s := &service{
63 cmc: NewCMCClient(),
64 }
65 pb.RegisterCMCProxyServer(m.GRPC(), s)
66
67 if err := m.Serve(); err != nil {
68 glog.Exitf("Could not run: %v", err)
69 }
70
71 go s.cmc.Run(m.Context())
72 glog.Info("Running.")
73
74 <-m.Done()
75}