improve handling of disk change modify events
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-10-14 15:26:05 +11:00
parent ce1f28d9c3
commit 665750548f

View File

@@ -131,7 +131,6 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
var diskChangeFound = false var diskChangeFound = false
// TODO - query current disk size from Inventory table and only create an update if the size is now changed
if testConfig.DeviceChange != nil { if testConfig.DeviceChange != nil {
for i := range testConfig.DeviceChange { for i := range testConfig.DeviceChange {
if testConfig.DeviceChange[i].Device.Backing != nil { if testConfig.DeviceChange[i].Device.Backing != nil {
@@ -195,6 +194,18 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
params.InventoryId = sql.NullInt64{Int64: invResult.Iid, Valid: invResult.Iid > 0} params.InventoryId = sql.NullInt64{Int64: invResult.Iid, Valid: invResult.Iid > 0}
} }
// Check current disk size from Inventory table and don't create an update if the size is still the same
if params.UpdateType == "diskChange" && invResult.ProvisionedDisk.Float64 == params.NewProvisionedDisk.Float64 {
h.Logger.Info("VM update type was for disk size but current size of VM matches inventory record, no need for update record",
"vm_name", invResult.Name, "db_value", invResult.ProvisionedDisk.Float64, "new_value", params.NewProvisionedDisk.Float64)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{
"status": "OK",
"message": fmt.Sprintf("Successfully processed vm modify event"),
})
return
}
// Parse the datetime string to a time.Time object // Parse the datetime string to a time.Time object
eventTime, err := time.Parse(time.RFC3339, event.CloudEvent.Data.CreatedTime) eventTime, err := time.Parse(time.RFC3339, event.CloudEvent.Data.CreatedTime)
if err != nil { if err != nil {