avoid unnecessary disk size calculations
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:20:02 +11:00
parent 1ecdb10cf7
commit ce1f28d9c3

View File

@@ -129,6 +129,8 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
(strings.Contains(event.CloudEvent.Data.FullFormattedMessage, ".vmdk") ||
strings.Contains(event.CloudEvent.Data.FullFormattedMessage, "capacityInKB")) {
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 {
for i := range testConfig.DeviceChange {
@@ -146,9 +148,10 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
if strings.ToLower(matches[1]) == strings.ToLower(event.CloudEvent.Data.VM.Name) {
h.Logger.Debug("This disk belongs to this VM")
found = true
params.UpdateType = "diskchange"
diskSize := h.calculateNewDiskSize(event)
params.NewProvisionedDisk = sql.NullFloat64{Float64: diskSize, Valid: diskSize > 0}
diskChangeFound = true
// don't need to keep searching through the rest of the backing devices in this VM
break
} else {
h.Logger.Debug("This disk belongs to a different VM, don't record this config change")
@@ -157,6 +160,13 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
}
}
}
// If we found a disk change belonging to this VM then recalculate the disk size
if diskChangeFound {
params.UpdateType = "diskchange"
diskSize := h.calculateNewDiskSize(event)
params.NewProvisionedDisk = sql.NullFloat64{Float64: diskSize, Valid: diskSize > 0}
}
}
}