troubleshoot disk size calculation
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-09-27 12:44:23 +10:00
parent d76bcf5ca5
commit a7dc838c83
2 changed files with 11 additions and 2 deletions

View File

@@ -75,6 +75,7 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
if vmObject.Vm.Config != nil {
numRam = vmObject.Vm.Config.Hardware.MemoryMB
numVcpus = vmObject.Vm.Config.Hardware.NumCPU
var totalDiskBytes int64
// Calculate the total disk allocated in GB
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)
}
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
if vmObject.Vm.Config.ManagedBy != nil && vmObject.Vm.Config.ManagedBy.Type == "com.vmware.vcDr" {

View File

@@ -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)
}
}