github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/fleetmanager/rpcd/getMachineInfo.go (about) 1 package rpcd 2 3 import ( 4 "github.com/Cloud-Foundations/Dominator/lib/errors" 5 "github.com/Cloud-Foundations/Dominator/lib/srpc" 6 fm_proto "github.com/Cloud-Foundations/Dominator/proto/fleetmanager" 7 hyper_proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor" 8 ) 9 10 func (t *srpcType) GetMachineInfo(conn *srpc.Conn, 11 request fm_proto.GetMachineInfoRequest, 12 reply *fm_proto.GetMachineInfoResponse) error { 13 if response, err := t.getMachineInfo(request.Hostname); err != nil { 14 *reply = fm_proto.GetMachineInfoResponse{ 15 Error: errors.ErrorToString(err)} 16 } else { 17 *reply = response 18 } 19 return nil 20 } 21 22 func (t *srpcType) getMachineInfo(hostname string) ( 23 fm_proto.GetMachineInfoResponse, error) { 24 topology, err := t.hypervisorsManager.GetTopology() 25 if err != nil { 26 return fm_proto.GetMachineInfoResponse{}, err 27 } 28 location, err := topology.GetLocationOfMachine(hostname) 29 if err != nil { 30 return fm_proto.GetMachineInfoResponse{}, err 31 } 32 machine, err := t.hypervisorsManager.GetMachineInfo(hostname) 33 if err != nil { 34 return fm_proto.GetMachineInfoResponse{}, err 35 } 36 tSubnets, err := topology.GetSubnetsForMachine(hostname) 37 if err != nil { 38 return fm_proto.GetMachineInfoResponse{}, err 39 } 40 subnets := make([]*hyper_proto.Subnet, 0, len(tSubnets)) 41 for _, tSubnet := range tSubnets { 42 subnets = append(subnets, &tSubnet.Subnet) 43 } 44 return fm_proto.GetMachineInfoResponse{ 45 Location: location, 46 Machine: machine, 47 Subnets: subnets, 48 }, nil 49 }