search for vm with datacenter info in cloud event
This commit is contained in:
@@ -21,6 +21,7 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
|
||||
unixTimestamp int64
|
||||
numVcpus int32
|
||||
numRam int32
|
||||
datacenter string
|
||||
)
|
||||
|
||||
reqBody, err := io.ReadAll(r.Body)
|
||||
@@ -63,9 +64,16 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
|
||||
vc := vcenter.New(h.Logger)
|
||||
vc.Login(vm.CloudEvent.Source)
|
||||
//vmObject, err := vc.FindVMByName(vm.CloudEvent.Data.VM.Name)
|
||||
vmObject, err := vc.FindVMByID(vm.CloudEvent.Data.VM.VM.Value)
|
||||
//vmObject, err := vc.FindVMByID(vm.CloudEvent.Data.VM.VM.Value)
|
||||
vmObject, err := vc.FindVMByIDWithDatacenter(vm.CloudEvent.Data.VM.VM.Value, vm.CloudEvent.Data.Datacenter.Datacenter.Value)
|
||||
|
||||
if err != nil {
|
||||
h.Logger.Error("Can't locate vm in vCenter", "vmID", vm.CloudEvent.Data.VM.VM.Value, "error", err)
|
||||
} else if vmObject == nil {
|
||||
h.Logger.Debug("didn't find VM", "vm_id", vm.CloudEvent.Data.VM.VM.Value)
|
||||
numRam = 0
|
||||
numVcpus = 0
|
||||
datacenter = ""
|
||||
} else {
|
||||
h.Logger.Debug("found VM", "object", vmObject)
|
||||
//prettyPrint(vmObject)
|
||||
@@ -86,7 +94,7 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
|
||||
EventId: sql.NullString{String: vm.CloudEvent.ID, Valid: vm.CloudEvent.ID != ""},
|
||||
EventKey: sql.NullString{String: strconv.Itoa(vm.CloudEvent.Data.Key), Valid: strconv.Itoa(vm.CloudEvent.Data.Key) != ""},
|
||||
VmId: sql.NullString{String: vm.CloudEvent.Data.VM.VM.Value, Valid: vm.CloudEvent.Data.VM.VM.Value != ""},
|
||||
Datacenter: sql.NullString{String: vmObject.Datacenter, Valid: vmObject.Datacenter != ""},
|
||||
Datacenter: sql.NullString{String: datacenter, Valid: datacenter != ""},
|
||||
CreationTime: sql.NullInt64{Int64: unixTimestamp, Valid: unixTimestamp > 0},
|
||||
InitialVcpus: sql.NullInt64{Int64: int64(numVcpus), Valid: numVcpus > 0},
|
||||
InitialRam: sql.NullInt64{Int64: int64(numRam), Valid: numRam > 0},
|
||||
|
Reference in New Issue
Block a user