tidy up
Some checks are pending
CI / Lint (push) Waiting to run
CI / Test (push) Waiting to run
CI / End-to-End (push) Waiting to run
CI / Publish Docker (push) Blocked by required conditions
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-09-16 12:04:14 +10:00
parent cfa9c45e56
commit 659347ad87

View File

@@ -41,7 +41,7 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
return
} else {
h.Logger.Debug("successfully decoded JSON")
prettyPrint(event)
//prettyPrint(event)
}
e := event.CloudEvent.Data
@@ -60,60 +60,10 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
unixTimestamp = eventTime.Unix()
}
/*
// TODO - initiate govmomi query of source vcenter to discover related data
h.Logger.Debug("connecting to vcenter")
vc := vcenter.New(h.Logger)
vc.Login(event.CloudEvent.Source)
//vmObject, err := vc.FindVMByName(vm.CloudEvent.Data.VM.Name)
//vmObject, err := vc.FindVMByID(vm.CloudEvent.Data.VM.VM.Value)
vmObject, err := vc.FindVMByIDWithDatacenter(e.VM.VM.Value, e.Datacenter.Datacenter.Value)
if err != nil {
h.Logger.Error("Can't locate vm in vCenter", "vmID", e.VM.VM.Value, "error", err)
} else if vmObject == nil {
h.Logger.Debug("didn't find VM", "vm_id", e.VM.VM.Value)
numRam = 0
numVcpus = 0
datacenter = e.Datacenter.Name
} else {
h.Logger.Debug("found VM")
//prettyPrint(vmObject)
// calculate VM properties we want to store
if vmObject.Vm.Config != nil {
numRam = vmObject.Vm.Config.Hardware.MemoryMB
numVcpus = vmObject.Vm.Config.Hardware.NumCPU * vmObject.Vm.Config.Hardware.NumCoresPerSocket
} else {
h.Logger.Error("Empty VM config")
}
}
err = vc.Logout()
if err != nil {
h.Logger.Error("unable to logout of vcenter", "error", err)
}
*/
// Create an instance of CreateInventoryParams
h.Logger.Debug("Creating database parameters")
/*
params := queries.CreateInventoryParams{
Name: e.VM.Name,
Vcenter: event.CloudEvent.Source,
EventId: sql.NullString{String: event.CloudEvent.ID, Valid: event.CloudEvent.ID != ""},
EventKey: sql.NullString{String: strconv.Itoa(e.Key), Valid: strconv.Itoa(e.Key) != ""},
VmId: sql.NullString{String: e.VM.VM.Value, Valid: e.VM.VM.Value != ""},
Datacenter: sql.NullString{String: datacenter, Valid: datacenter != ""},
Cluster: sql.NullString{String: e.ComputeResource.Name, Valid: e.ComputeResource.Name != ""},
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},
}
*/
params2 := queries.CreateEventParams{
params := queries.CreateEventParams{
Source: event.CloudEvent.Source,
CloudId: event.CloudEvent.ID,
EventTime: sql.NullInt64{Int64: unixTimestamp, Valid: unixTimestamp > 0},
@@ -128,10 +78,10 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
UserName: sql.NullString{String: e.UserName, Valid: e.UserName != ""},
}
h.Logger.Debug("database params", "params", params2)
h.Logger.Debug("database params", "params", params)
// Insert the new inventory record into the database
result, err := h.Database.Queries().CreateEvent(context.Background(), params2)
result, err := h.Database.Queries().CreateEvent(context.Background(), params)
if err != nil {
h.Logger.Error("unable to perform database insert", "error", err)
w.WriteHeader(http.StatusInternalServerError)