update database schema to avoid bool confusion
This commit is contained in:
@@ -26,10 +26,10 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
numVcpus int32
|
||||
numRam int32
|
||||
totalDiskGB float64
|
||||
srmPlaceholder int
|
||||
srmPlaceholder string
|
||||
foundVm bool
|
||||
isTemplate int
|
||||
poweredOn int
|
||||
isTemplate string
|
||||
poweredOn string
|
||||
folderPath string
|
||||
)
|
||||
|
||||
@@ -64,11 +64,11 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
numRam = 0
|
||||
numVcpus = 0
|
||||
totalDiskGB = 0
|
||||
isTemplate = 0
|
||||
isTemplate = "FALSE"
|
||||
folderPath = ""
|
||||
} else {
|
||||
c.Logger.Debug("found VM")
|
||||
srmPlaceholder = 0 // Default assumption
|
||||
srmPlaceholder = "FALSE" // Default assumption
|
||||
//prettyPrint(vmObject)
|
||||
|
||||
// calculate VM properties we want to store
|
||||
@@ -79,6 +79,14 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
// Calculate the total disk allocated in GB
|
||||
for _, device := range vmObject.Vm.Config.Hardware.Device {
|
||||
if disk, ok := device.(*types.VirtualDisk); ok {
|
||||
|
||||
// Print the filename of the backing device
|
||||
if backing, ok := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
|
||||
c.Logger.Debug("Adding disk", "size_bytes", disk.CapacityInBytes, "backing_file", backing.FileName)
|
||||
} else {
|
||||
c.Logger.Debug("Adding disk, unknown backing type", "size_bytes", disk.CapacityInBytes)
|
||||
}
|
||||
|
||||
totalDiskGB += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB
|
||||
}
|
||||
}
|
||||
@@ -86,13 +94,13 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
// 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" {
|
||||
c.Logger.Debug("VM ManagedBy indicates managed by SRM")
|
||||
srmPlaceholder = 1
|
||||
srmPlaceholder = "TRUE"
|
||||
}
|
||||
|
||||
if vmObject.Vm.Config.Template {
|
||||
isTemplate = 1
|
||||
isTemplate = "TRUE"
|
||||
} else {
|
||||
isTemplate = 0
|
||||
isTemplate = "FALSE"
|
||||
}
|
||||
|
||||
// Retrieve the full folder path of the VM
|
||||
@@ -109,15 +117,12 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
c.Logger.Error("Empty VM config")
|
||||
}
|
||||
|
||||
//if (types.VirtualMachineRuntimeInfo{}) != vmObject.Vm.Runtime {
|
||||
//if runtime, ok := vmObject.Vm.Runtime.(types.VirtualMachineRuntimeInfo); ok {
|
||||
c.Logger.Debug("VM has runtime data", "power_state", vmObject.Vm.Runtime.PowerState)
|
||||
if vmObject.Vm.Runtime.PowerState == "" {
|
||||
poweredOn = 0
|
||||
if vmObject.Vm.Runtime.PowerState == "poweredOff" {
|
||||
poweredOn = "FALSE"
|
||||
} else {
|
||||
poweredOn = 1
|
||||
poweredOn = "TRUE"
|
||||
}
|
||||
//}
|
||||
|
||||
}
|
||||
err = vc.Logout()
|
||||
@@ -142,9 +147,9 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
ProvisionedDisk: sql.NullFloat64{Float64: totalDiskGB, Valid: totalDiskGB > 0},
|
||||
Folder: sql.NullString{String: folderPath, Valid: folderPath != ""},
|
||||
ResourcePool: sql.NullString{String: vmObject.ResourcePool, Valid: vmObject.ResourcePool != ""},
|
||||
SrmPlaceholder: sql.NullInt64{Int64: int64(srmPlaceholder), Valid: true},
|
||||
IsTemplate: sql.NullInt64{Int64: int64(isTemplate), Valid: true},
|
||||
PowerState: sql.NullInt64{Int64: int64(poweredOn), Valid: true},
|
||||
SrmPlaceholder: srmPlaceholder,
|
||||
IsTemplate: isTemplate,
|
||||
PoweredOn: poweredOn,
|
||||
}
|
||||
|
||||
c.Logger.Debug("database params", "params", params)
|
||||
|
Reference in New Issue
Block a user