troubleshoot disk size calculation
This commit is contained in:
@@ -75,6 +75,7 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
|||||||
if vmObject.Vm.Config != nil {
|
if vmObject.Vm.Config != nil {
|
||||||
numRam = vmObject.Vm.Config.Hardware.MemoryMB
|
numRam = vmObject.Vm.Config.Hardware.MemoryMB
|
||||||
numVcpus = vmObject.Vm.Config.Hardware.NumCPU
|
numVcpus = vmObject.Vm.Config.Hardware.NumCPU
|
||||||
|
var totalDiskBytes int64
|
||||||
|
|
||||||
// Calculate the total disk allocated in GB
|
// Calculate the total disk allocated in GB
|
||||||
for _, device := range vmObject.Vm.Config.Hardware.Device {
|
for _, device := range vmObject.Vm.Config.Hardware.Device {
|
||||||
@@ -87,9 +88,12 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
|||||||
c.Logger.Debug("Adding disk, unknown backing type", "size_bytes", disk.CapacityInBytes)
|
c.Logger.Debug("Adding disk, unknown backing type", "size_bytes", disk.CapacityInBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
totalDiskGB += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB
|
totalDiskBytes += disk.CapacityInBytes
|
||||||
|
//totalDiskGB += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
totalDiskGB = float64(totalDiskBytes / 1024 / 1024 / 1024)
|
||||||
|
c.Logger.Debug("Converted total disk size", "bytes", totalDiskBytes, "GB", totalDiskGB)
|
||||||
|
|
||||||
// Determine if the VM is a normal VM or an SRM placeholder
|
// Determine if the VM is a normal VM or an SRM placeholder
|
||||||
if vmObject.Vm.Config.ManagedBy != nil && vmObject.Vm.Config.ManagedBy.Type == "com.vmware.vcDr" {
|
if vmObject.Vm.Config.ManagedBy != nil && vmObject.Vm.Config.ManagedBy.Type == "com.vmware.vcDr" {
|
||||||
|
@@ -241,6 +241,7 @@ func (h *Handler) processConfigChanges(configChanges string) []map[string]string
|
|||||||
|
|
||||||
func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64 {
|
func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64 {
|
||||||
var diskSize float64
|
var diskSize float64
|
||||||
|
var totalDiskBytes int64
|
||||||
h.Logger.Debug("connecting to vcenter")
|
h.Logger.Debug("connecting to vcenter")
|
||||||
vc := vcenter.New(h.Logger)
|
vc := vcenter.New(h.Logger)
|
||||||
vc.Login(event.CloudEvent.Source)
|
vc.Login(event.CloudEvent.Source)
|
||||||
@@ -252,6 +253,7 @@ func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64
|
|||||||
} else {
|
} else {
|
||||||
if vmObject.Vm.Config != nil {
|
if vmObject.Vm.Config != nil {
|
||||||
h.Logger.Debug("Found VM with config, calculating new total disk size", "vmID", event.CloudEvent.Data.VM.VM.Value)
|
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
|
// Calculate the total disk allocated in GB
|
||||||
for _, device := range vmObject.Vm.Config.Hardware.Device {
|
for _, device := range vmObject.Vm.Config.Hardware.Device {
|
||||||
if disk, ok := device.(*types.VirtualDisk); ok {
|
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)
|
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