avoid unnecessary disk size calculations
This commit is contained in:
@@ -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, ".vmdk") ||
|
||||||
strings.Contains(event.CloudEvent.Data.FullFormattedMessage, "capacityInKB")) {
|
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
|
// 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 {
|
||||||
@@ -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) {
|
if strings.ToLower(matches[1]) == strings.ToLower(event.CloudEvent.Data.VM.Name) {
|
||||||
h.Logger.Debug("This disk belongs to this VM")
|
h.Logger.Debug("This disk belongs to this VM")
|
||||||
found = true
|
found = true
|
||||||
params.UpdateType = "diskchange"
|
diskChangeFound = true
|
||||||
diskSize := h.calculateNewDiskSize(event)
|
|
||||||
params.NewProvisionedDisk = sql.NullFloat64{Float64: diskSize, Valid: diskSize > 0}
|
// don't need to keep searching through the rest of the backing devices in this VM
|
||||||
|
break
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
h.Logger.Debug("This disk belongs to a different VM, don't record this config change")
|
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}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user