add vm power state and template
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-16 10:14:46 +10:00
parent 85bb431de1
commit 57980a860a
6 changed files with 65 additions and 13 deletions

View File

@@ -26,6 +26,8 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
totalDiskGB float64
srmPlaceholder int
foundVm bool
isTemplate int
poweredOn int
)
logger.Debug("Started Events processing", "time", time.Now())
@@ -57,6 +59,7 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
numRam = 0
numVcpus = 0
totalDiskGB = 0
isTemplate = 0
} else {
c.Logger.Debug("found VM")
srmPlaceholder = 0 // Default assumption
@@ -80,11 +83,27 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
srmPlaceholder = 1
}
if vmObject.Vm.Config.Template {
isTemplate = 1
} else {
isTemplate = 0
}
foundVm = true
} else {
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
} else {
poweredOn = 1
}
//}
}
err = vc.Logout()
if err != nil {
@@ -109,6 +128,8 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
Folder: sql.NullString{String: vmObject.FolderPath, Valid: vmObject.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},
}
c.Logger.Debug("database params", "params", params)