troubleshoot disk size calculation
This commit is contained in:
@@ -241,6 +241,7 @@ func (h *Handler) processConfigChanges(configChanges string) []map[string]string
|
||||
|
||||
func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64 {
|
||||
var diskSize float64
|
||||
var totalDiskBytes int64
|
||||
h.Logger.Debug("connecting to vcenter")
|
||||
vc := vcenter.New(h.Logger)
|
||||
vc.Login(event.CloudEvent.Source)
|
||||
@@ -252,6 +253,7 @@ func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64
|
||||
} else {
|
||||
if vmObject.Vm.Config != nil {
|
||||
h.Logger.Debug("Found VM with config, calculating new total disk size", "vmID", event.CloudEvent.Data.VM.VM.Value)
|
||||
|
||||
// Calculate the total disk allocated in GB
|
||||
for _, device := range vmObject.Vm.Config.Hardware.Device {
|
||||
if disk, ok := device.(*types.VirtualDisk); ok {
|
||||
@@ -263,9 +265,12 @@ func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64
|
||||
h.Logger.Debug("Adding disk, unknown backing type", "size_bytes", disk.CapacityInBytes)
|
||||
}
|
||||
|
||||
diskSize += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB
|
||||
//diskSize += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB
|
||||
totalDiskBytes += disk.CapacityInBytes
|
||||
}
|
||||
}
|
||||
diskSize = float64(totalDiskBytes / 1024 / 1024 / 1024)
|
||||
h.Logger.Debug("Converted total disk size", "bytes", totalDiskBytes, "GB", diskSize)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user