dont query vm folder path unless we need to
This commit is contained in:
@@ -28,6 +28,7 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
foundVm bool
|
||||
isTemplate int
|
||||
poweredOn int
|
||||
folderPath string
|
||||
)
|
||||
|
||||
logger.Debug("Started Events processing", "time", time.Now())
|
||||
@@ -60,6 +61,7 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
numVcpus = 0
|
||||
totalDiskGB = 0
|
||||
isTemplate = 0
|
||||
folderPath = ""
|
||||
} else {
|
||||
c.Logger.Debug("found VM")
|
||||
srmPlaceholder = 0 // Default assumption
|
||||
@@ -89,6 +91,15 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
isTemplate = 0
|
||||
}
|
||||
|
||||
// Retrieve the full folder path of the VM
|
||||
folderPath, err = vc.GetVMFolderPath(vmObject.Vm)
|
||||
if err != nil {
|
||||
c.Logger.Error("failed to get vm folder path", "error", err)
|
||||
folderPath = ""
|
||||
} else {
|
||||
c.Logger.Debug("Found vm folder path", "folder_path", folderPath)
|
||||
}
|
||||
|
||||
foundVm = true
|
||||
} else {
|
||||
c.Logger.Error("Empty VM config")
|
||||
@@ -125,7 +136,7 @@ func (c *CronTask) RunVmCheck(ctx context.Context, logger *slog.Logger) error {
|
||||
InitialVcpus: sql.NullInt64{Int64: int64(numVcpus), Valid: numVcpus > 0},
|
||||
InitialRam: sql.NullInt64{Int64: int64(numRam), Valid: numRam > 0},
|
||||
ProvisionedDisk: sql.NullFloat64{Float64: totalDiskGB, Valid: totalDiskGB > 0},
|
||||
Folder: sql.NullString{String: vmObject.FolderPath, Valid: vmObject.FolderPath != ""},
|
||||
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},
|
||||
|
Reference in New Issue
Block a user