Enhance snapshot handling by backfilling provisioned disk data and updating backfill logic
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -762,6 +762,21 @@ func snapshotFromVM(ctx context.Context, dbConn *sqlx.DB, vmObject *mo.VirtualMa
|
||||
}
|
||||
}
|
||||
|
||||
// Some VMs can be returned without complete virtual disk device metadata.
|
||||
// Fall back to summary storage (committed + uncommitted) when available.
|
||||
if !row.ProvisionedDisk.Valid && vmObject.Summary.Storage != nil {
|
||||
provisionedBytes := vmObject.Summary.Storage.Committed
|
||||
if vmObject.Summary.Storage.Uncommitted > 0 {
|
||||
provisionedBytes += vmObject.Summary.Storage.Uncommitted
|
||||
}
|
||||
if provisionedBytes > 0 {
|
||||
row.ProvisionedDisk = sql.NullFloat64{
|
||||
Float64: float64(provisionedBytes) / 1024.0 / 1024.0 / 1024.0,
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if vmObject.Runtime.PowerState == "poweredOff" {
|
||||
row.PoweredOn = "FALSE"
|
||||
} else {
|
||||
@@ -930,7 +945,7 @@ func snapshotFromVM(ctx context.Context, dbConn *sqlx.DB, vmObject *mo.VirtualMa
|
||||
}
|
||||
}
|
||||
|
||||
if dbConn != nil && needsSnapshotBackfill(row) {
|
||||
if dbConn != nil && (needsSnapshotBackfill(row) || !row.ProvisionedDisk.Valid) {
|
||||
if backfillSnapshotRowFromHourlyCache(ctx, dbConn, &row) && vc.Logger != nil {
|
||||
vc.Logger.Debug("backfilled sparse VM snapshot row from hourly cache", "vm_id", row.VmId.String, "name", row.Name, "vcenter", row.Vcenter)
|
||||
}
|
||||
@@ -957,7 +972,6 @@ func snapshotFromVM(ctx context.Context, dbConn *sqlx.DB, vmObject *mo.VirtualMa
|
||||
|
||||
func needsSnapshotBackfill(row InventorySnapshotRow) bool {
|
||||
return !row.CreationTime.Valid ||
|
||||
!row.ProvisionedDisk.Valid ||
|
||||
!row.VcpuCount.Valid ||
|
||||
!row.RamGB.Valid ||
|
||||
!row.Cluster.Valid ||
|
||||
|
||||
Reference in New Issue
Block a user