Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Carry vSphere snapshot trees

rcourtman7ffe2e581c20
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 4e068a345e..c0616981cf 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -736,7 +736,7 @@ a separate Docker-only or TrueNAS-local inventory path.
27. Keep alert-side recovery drill-ins on that same shared route-helper contract. When alert investigation surfaces such as resource-incident panels expose recovery follow-up links for TrueNAS or future API-backed platforms, they must route through the canonical `frontend-modern/src/routing/resourceLinks.ts` recovery builder instead of freezing alert-local recovery URLs or introducing another provider-shaped recovery handoff vocabulary.
28. Keep VMware onboarding runtime and recovery semantics separate on that same adjacent platform-connections contract. When `internal/api/router.go`, `internal/api/router_routes_registration.go`, or `internal/api/vmware_handlers.go` evolve VMware connection CRUD, poller-owned `poll` / `observed` summary payloads, saved-test refresh, or observed datastore/VM snapshot visibility, storage and recovery may consume the resulting shared context but must not treat those onboarding/runtime payloads as canonical recovery artifacts, restore capability, or recovery-local control transport.
29. Keep VMware datastore projection on the shared unified-resource and storage-source contracts. When `frontend-modern/src/hooks/useUnifiedResources.ts` or shared `internal/api/router.go` wiring starts surfacing VMware-backed canonical `storage` resources, storage and recovery may expose those datastores through the owned `vmware-vsphere` source/platform vocabulary for inventory, capacity, and handoff flows only; they must not reinterpret that projection as VMware recovery support, restore semantics, or a provider-local protection surface.
-30. Keep VMware placement and guest-detail enrichment descriptive on that same shared unified-resource contract. When `internal/vmware/provider.go`, `internal/unifiedresources/types.go`, and `frontend-modern/src/hooks/useUnifiedResources.ts` project datacenter, cluster, folder, runtime-host, datastore-attachment, guest-hostname, or guest-IP metadata onto canonical VMware `agent` / `vm` / `storage` resources, storage and recovery may use that detail for labeling and navigation only; they must not promote those topology or guest fields into recovery ownership, restore targeting, protection grouping, or a VMware-local recovery taxonomy without a separately governed slice.
+30. Keep VMware placement, guest-detail, and VM snapshot-tree enrichment descriptive on that same shared unified-resource contract. When `internal/vmware/provider.go`, `internal/unifiedresources/types.go`, and `frontend-modern/src/hooks/useUnifiedResources.ts` project datacenter, cluster, folder, runtime-host, datastore-attachment, guest-hostname, guest-IP, `vmware.currentSnapshotId`, `vmware.snapshotTree`, snapshot creation/state/quiesce/current markers, or child snapshot metadata onto canonical VMware `agent` / `vm` / `storage` resources, storage and recovery may use that detail for labeling, navigation, and VM investigation context only; they must not promote those topology, guest, or snapshot-tree fields into recovery ownership, restore targeting, protection grouping, compliance scoring, or a VMware-local recovery taxonomy without a separately governed slice.
31. Keep VMware datastore classification neutral on the shared storage adapter contract. When `frontend-modern/src/features/storageBackups/resourceStorageMapping.ts`, `frontend-modern/src/features/storageBackups/resourceStoragePresentation.ts`, and `frontend-modern/src/features/storageBackups/storageAdapters.ts` evolve canonical storage-record mapping, VMware-backed datastores must continue to land on the shared storage route as inventory-only datastores with neutral protection fallback, not as backup repositories, backup targets, or recovery-protected resources.
That same shared storage adapter boundary also owns canonical platform
family vocabulary through the governed platform manifest.
@@ -3111,7 +3111,11 @@ workload context, but VMware recovery stays out of the support claim.
Storage and recovery must not treat vSphere snapshots, changed-disk/block
visibility, or datastore presence as canonical Pulse recovery artifacts,
restore capability, or recovery-backed Assistant control until a later
-governed slice adds those contracts explicitly.
+governed slice adds those contracts explicitly. The shared VMware
+`Resource.vmware.snapshotTree` projection may show current snapshot, creation
+time, state, quiesce, and child-snapshot context on VM details, but it remains
+descriptive workload evidence and must not feed recovery policy, restore
+targeting, protection grouping, or backup/snapshot compliance scoring.
That same storage/recovery boundary also keeps the onboarding runtime separate
from recovery semantics. `internal/api/router.go`,
`internal/api/router_routes_registration.go`, and
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 6645b5546b..aab00d03ed 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -1155,9 +1155,14 @@ carry runtime-host, folder, resource-pool, datastore, and guest-identity
metadata plus canonical parentage to the owning ESXi `agent`; datastores may
carry datacenter/folder placement plus shared storage-node and workload
consumer metadata through `storage.nodes`, `storage.consumerCount`, and
-`storage.topConsumers`. Those enrichments must remain subordinate to shared
-`agent`, `vm`, and `storage` resources rather than becoming a VMware-only
-topology graph or a separate provider detail drawer contract.
+`storage.topConsumers`. VMs may also carry VI JSON snapshot-tree context under
+`vmware.currentSnapshotId` and `vmware.snapshotTree`, including snapshot
+managed-object reference, display name, description, creation time, power
+state, quiesce flag, current marker, replay support, and child snapshots.
+Those enrichments must remain subordinate to shared `agent`, `vm`, and
+`storage` resources rather than becoming a VMware-only topology graph, recovery
+artifact, canonical identity alias, or separate provider detail drawer
+contract.
TrueNAS disk telemetry now follows the same rule. API-backed TrueNAS disks must
populate canonical `physicalDisk.temperature` and reuse the shared
physical-disk risk semantics, so infrastructure, storage, charts, and AI read
diff --git a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.identity-runtime.test.tsx b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.identity-runtime.test.tsx
index 3ae179ca69..9dc33ffd86 100644
--- a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.identity-runtime.test.tsx
+++ b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.identity-runtime.test.tsx
@@ -315,6 +315,27 @@ describe('ResourceDetailDrawer runtime and identity cards', () => {
recentTaskCount: 1,
recentTaskSummary: 'Create snapshot (success)',
snapshotCount: 2,
+ currentSnapshotId: 'snapshot-202',
+ snapshotTree: [
+ {
+ snapshot: 'snapshot-201',
+ name: 'pre-upgrade',
+ description: 'Before application upgrade',
+ createdAt: '2026-03-28T18:15:00Z',
+ state: 'poweredOn',
+ quiesced: true,
+ children: [
+ {
+ snapshot: 'snapshot-202',
+ name: 'post-migration-checkpoint',
+ createdAt: '2026-03-29T18:15:00Z',
+ state: 'poweredOn',
+ current: true,
+ quiesced: false,
+ },
+ ],
+ },
+ ],
},
},
vmware: {
@@ -336,6 +357,27 @@ describe('ResourceDetailDrawer runtime and identity cards', () => {
recentTaskCount: 1,
recentTaskSummary: 'Create snapshot (success)',
snapshotCount: 2,
+ currentSnapshotId: 'snapshot-202',
+ snapshotTree: [
+ {
+ snapshot: 'snapshot-201',
+ name: 'pre-upgrade',
+ description: 'Before application upgrade',
+ createdAt: '2026-03-28T18:15:00Z',
+ state: 'poweredOn',
+ quiesced: true,
+ children: [
+ {
+ snapshot: 'snapshot-202',
+ name: 'post-migration-checkpoint',
+ createdAt: '2026-03-29T18:15:00Z',
+ state: 'poweredOn',
+ current: true,
+ quiesced: false,
+ },
+ ],
+ },
+ ],
},
});
@@ -361,6 +403,7 @@ describe('ResourceDetailDrawer runtime and identity cards', () => {
expect(within(section).getByText('Placement')).toBeInTheDocument();
expect(within(section).getByText('Guest')).toBeInTheDocument();
expect(within(section).getByText('Signals')).toBeInTheDocument();
+ expect(within(section).getByText('Snapshot tree')).toBeInTheDocument();
expect(within(section).getByText('vc.lab.local')).toBeInTheDocument();
expect(within(section).getByText('Compute Cluster')).toBeInTheDocument();
expect(within(section).getByText('esxi-01.lab.local')).toBeInTheDocument();
@@ -368,6 +411,9 @@ describe('ResourceDetailDrawer runtime and identity cards', () => {
expect(within(section).getByText(/Create snapshot \(success\)/)).toBeInTheDocument();
expect(within(section).getByText(/Host fan degraded/)).toBeInTheDocument();
expect(within(section).getByText('2 snapshots')).toBeInTheDocument();
+ expect(within(section).getByText('pre-upgrade')).toBeInTheDocument();
+ expect(within(section).getByText('- post-migration-checkpoint')).toBeInTheDocument();
+ expect(within(section).getByText(/current · poweredOn/)).toBeInTheDocument();
});
it('keeps source provenance in the header when no source health issue is present', () => {
diff --git a/frontend-modern/src/components/Infrastructure/__tests__/resourceDetailDrawerVmwareModel.test.ts b/frontend-modern/src/components/Infrastructure/__tests__/resourceDetailDrawerVmwareModel.test.ts
new file mode 100644
index 0000000000..c2477ab969
--- /dev/null
+++ b/frontend-modern/src/components/Infrastructure/__tests__/resourceDetailDrawerVmwareModel.test.ts
@@ -0,0 +1,54 @@
+import { describe, expect, it } from 'vitest';
+import {
+ buildVMwareDetailSections,
+ buildVMwareDetailsSummary,
+} from '@/components/Infrastructure/resourceDetailDrawerVmwareModel';
+import type { ResourceVMwareMeta } from '@/types/resource';
+
+describe('resourceDetailDrawerVmwareModel', () => {
+ it('surfaces vSphere snapshot trees as read-only VM detail context', () => {
+ const vmware: ResourceVMwareMeta = {
+ connectionName: 'Lab VC',
+ snapshotTree: [
+ {
+ snapshot: 'snapshot-201',
+ name: 'pre-upgrade',
+ createdAt: '2026-03-28T18:15:00Z',
+ state: 'poweredOn',
+ quiesced: true,
+ children: [
+ {
+ snapshot: 'snapshot-202',
+ name: 'post-migration-checkpoint',
+ createdAt: '2026-03-29T18:15:00Z',
+ state: 'poweredOn',
+ current: true,
+ quiesced: false,
+ },
+ ],
+ },
+ ],
+ };
+
+ expect(buildVMwareDetailsSummary('vm', vmware)).toBe(
+ 'Lab VC · Read-only vCenter context · 2 snapshots',
+ );
+
+ const snapshots = buildVMwareDetailSections('vm', vmware).find(
+ (section) => section.id === 'snapshots',
+ );
+
+ expect(snapshots?.rows).toEqual([
+ {
+ label: 'pre-upgrade',
+ value: 'poweredOn · 2026-03-28 18:15 UTC · quiesced',
+ tone: 'default',
+ },
+ {
+ label: '- post-migration-checkpoint',
+ value: 'current · poweredOn · 2026-03-29 18:15 UTC · not quiesced',
+ tone: 'accent',
+ },
+ ]);
+ });
+});
diff --git a/frontend-modern/src/components/Infrastructure/resourceDetailDrawerVmwareModel.ts b/frontend-modern/src/components/Infrastructure/resourceDetailDrawerVmwareModel.ts
index bf85110f52..7f90a442c5 100644
--- a/frontend-modern/src/components/Infrastructure/resourceDetailDrawerVmwareModel.ts
+++ b/frontend-modern/src/components/Infrastructure/resourceDetailDrawerVmwareModel.ts
@@ -1,4 +1,4 @@
-import type { ResourceType, ResourceVMwareMeta } from '@/types/resource';
+import type { ResourceType, ResourceVMwareMeta, ResourceVMwareSnapshot } from '@/types/resource';
export type ResourceDetailDrawerVMwareRowTone = 'default' | 'accent' | 'warning';
@@ -9,7 +9,7 @@ export type ResourceDetailDrawerVMwareRow = {
};
export type ResourceDetailDrawerVMwareSection = {
- id: 'state' | 'placement' | 'guest' | 'signals';
+ id: 'state' | 'placement' | 'guest' | 'signals' | 'snapshots';
label: string;
rows: ResourceDetailDrawerVMwareRow[];
};
@@ -24,6 +24,54 @@ const formatBoolLabel = (value?: boolean): string => {
return value ? 'Yes' : 'No';
};
+const countSnapshotTree = (snapshots?: ResourceVMwareSnapshot[]): number =>
+ (snapshots ?? []).reduce(
+ (total, snapshot) => total + 1 + countSnapshotTree(snapshot.children),
+ 0,
+ );
+
+const snapshotDisplayName = (snapshot: ResourceVMwareSnapshot): string =>
+ asTrimmedString(snapshot.name) ||
+ asTrimmedString(snapshot.snapshot) ||
+ (typeof snapshot.id === 'number' ? `Snapshot ${snapshot.id}` : 'Snapshot');
+
+const formatSnapshotDate = (value?: string | number): string => {
+ if (value === undefined || value === null || value === '') return '';
+ const date = new Date(value);
+ if (Number.isNaN(date.getTime())) return asTrimmedString(String(value));
+ const pad = (part: number) => String(part).padStart(2, '0');
+ return `${date.getUTCFullYear()}-${pad(date.getUTCMonth() + 1)}-${pad(
+ date.getUTCDate(),
+ )} ${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())} UTC`;
+};
+
+const snapshotValue = (snapshot: ResourceVMwareSnapshot): string => {
+ const parts = [
+ snapshot.current ? 'current' : '',
+ asTrimmedString(snapshot.state),
+ formatSnapshotDate(snapshot.createdAt),
+ snapshot.quiesced === undefined ? '' : snapshot.quiesced ? 'quiesced' : 'not quiesced',
+ asTrimmedString(snapshot.description),
+ ].filter(Boolean);
+ return parts.join(' · ');
+};
+
+const flattenSnapshotRows = (
+ snapshots: ResourceVMwareSnapshot[] | undefined,
+ depth = 0,
+): ResourceDetailDrawerVMwareRow[] => {
+ const rows: ResourceDetailDrawerVMwareRow[] = [];
+ for (const snapshot of snapshots ?? []) {
+ rows.push({
+ label: `${depth > 0 ? `${'-'.repeat(depth)} ` : ''}${snapshotDisplayName(snapshot)}`,
+ value: snapshotValue(snapshot) || asTrimmedString(snapshot.snapshot),
+ tone: snapshot.current ? 'accent' : 'default',
+ });
+ rows.push(...flattenSnapshotRows(snapshot.children, depth + 1));
+ }
+ return rows;
+};
+
const vmwareEntityLabel = (entityType?: string): string => {
const normalized = asTrimmedString(entityType).toLowerCase();
switch (normalized) {
@@ -84,8 +132,12 @@ export const buildVMwareDetailsSummary = (
}
parts.push('Read-only vCenter context');
- if (resourceType === 'vm' && typeof vmware.snapshotCount === 'number') {
- parts.push(formatCount(Math.max(0, vmware.snapshotCount), 'snapshot'));
+ const snapshotCount =
+ typeof vmware.snapshotCount === 'number'
+ ? Math.max(0, vmware.snapshotCount)
+ : countSnapshotTree(vmware.snapshotTree);
+ if (resourceType === 'vm' && snapshotCount > 0) {
+ parts.push(formatCount(snapshotCount, 'snapshot'));
}
if ((vmware.activeAlarmCount ?? 0) > 0) {
parts.push(formatCount(vmware.activeAlarmCount ?? 0, 'alarm'));
@@ -228,16 +280,27 @@ export const buildVMwareDetailSections = (
label: 'Snapshots',
value:
resourceType === 'vm' || typeof vmware.snapshotCount === 'number'
- ? formatCount(Math.max(0, vmware.snapshotCount ?? 0), 'snapshot')
+ ? formatCount(
+ Math.max(
+ 0,
+ typeof vmware.snapshotCount === 'number'
+ ? vmware.snapshotCount
+ : countSnapshotTree(vmware.snapshotTree),
+ ),
+ 'snapshot',
+ )
: '',
},
]);
+ const snapshotRows = resourceType === 'vm' ? flattenSnapshotRows(vmware.snapshotTree) : [];
+
const sections: ResourceDetailDrawerVMwareSection[] = [
{ id: 'state', label: 'State', rows: stateRows },
{ id: 'placement', label: 'Placement', rows: placementRows },
{ id: 'guest', label: 'Guest', rows: guestRows },
{ id: 'signals', label: 'Signals', rows: signalRows },
+ { id: 'snapshots', label: 'Snapshot tree', rows: snapshotRows },
];
return sections.filter((section) => hasRows(section.rows));
diff --git a/frontend-modern/src/features/vmware/VsphereVirtualMachinesTable.tsx b/frontend-modern/src/features/vmware/VsphereVirtualMachinesTable.tsx
index 930d9485f4..1af01e8aea 100644
--- a/frontend-modern/src/features/vmware/VsphereVirtualMachinesTable.tsx
+++ b/frontend-modern/src/features/vmware/VsphereVirtualMachinesTable.tsx
@@ -33,7 +33,7 @@ import {
createPlatformResourceLabelResolver,
getPlatformResourceDetailRowClass,
} from '@/features/platformPage/PlatformResourceDetailTableRow';
-import type { Resource } from '@/types/resource';
+import type { Resource, ResourceVMwareSnapshot } from '@/types/resource';
import {
filterVmwareVirtualMachines,
mapVmwareVirtualMachineStatus,
@@ -117,6 +117,25 @@ const summarizeValues = (
return { label: `${visible.join(', ')}${suffix}`, title: compact.join(', ') };
};
+const countSnapshotTree = (snapshots: ResourceVMwareSnapshot[] | undefined): number =>
+ (snapshots ?? []).reduce(
+ (total, snapshot) => total + 1 + countSnapshotTree(snapshot.children),
+ 0,
+ );
+
+const flattenSnapshotNames = (snapshots: ResourceVMwareSnapshot[] | undefined): string[] => {
+ const names: string[] = [];
+ for (const snapshot of snapshots ?? []) {
+ const name =
+ asTrimmedString(snapshot.name) ||
+ asTrimmedString(snapshot.snapshot) ||
+ (typeof snapshot.id === 'number' ? `Snapshot ${snapshot.id}` : '');
+ if (name) names.push(snapshot.current ? `${name} (current)` : name);
+ names.push(...flattenSnapshotNames(snapshot.children));
+ }
+ return names;
+};
+
const formatGuest = (resource: Resource): { label: string; detail: string; title: string } => {
const family = asTrimmedString(resource.vmware?.guestOsFamily);
const host = asTrimmedString(resource.vmware?.guestHostname);
@@ -329,7 +348,13 @@ export const VsphereVirtualMachinesTable: Component<{
const datastores = createMemo(() =>
summarizeValues(meta()?.datastoreNames ?? [], '-', 1),
);
- const snapshots = () => Math.max(0, meta()?.snapshotCount ?? 0);
+ const snapshots = () =>
+ Math.max(
+ 0,
+ meta()?.snapshotCount ?? countSnapshotTree(meta()?.snapshotTree),
+ );
+ const snapshotTitle = () =>
+ flattenSnapshotNames(meta()?.snapshotTree).join(', ');
const metricsKey = () => buildMetricKeyForUnifiedResource(vm);
const cpuPercent = () => finiteMetric(vm.cpu?.current);
const memoryTotal = () => finiteMetric(vm.memory?.total) ?? 0;
@@ -459,6 +484,7 @@ export const VsphereVirtualMachinesTable: Component<{
</TableCell>
<TableCell
class={`${getPlatformTableCellClassForKind('numeric-value')} hidden text-base-content tabular-nums md:table-cell`}
+ title={snapshotTitle()}
>
{snapshots()}
</TableCell>
diff --git a/frontend-modern/src/features/vmware/__tests__/VsphereVirtualMachinesTable.test.tsx b/frontend-modern/src/features/vmware/__tests__/VsphereVirtualMachinesTable.test.tsx
index c8eed20fca..d1480d671e 100644
--- a/frontend-modern/src/features/vmware/__tests__/VsphereVirtualMachinesTable.test.tsx
+++ b/frontend-modern/src/features/vmware/__tests__/VsphereVirtualMachinesTable.test.tsx
@@ -35,7 +35,14 @@ const makeVM = (overrides: Partial<Resource> & Pick<Resource, 'id'>): Resource =
guestHostname: 'warehouse-api-01.internal',
guestIpAddresses: ['10.42.10.21'],
datastoreNames: ['nvme-primary', 'backup-nfs'],
- snapshotCount: 2,
+ snapshotTree: [
+ {
+ snapshot: 'snapshot-201',
+ name: 'pre-upgrade',
+ quiesced: true,
+ children: [{ snapshot: 'snapshot-202', name: 'post-upgrade', current: true }],
+ },
+ ],
},
...overrides,
}) as Resource;
@@ -91,6 +98,7 @@ describe('VsphereVirtualMachinesTable', () => {
expect(screen.getByText('warehouse-api-01.internal')).toBeInTheDocument();
expect(screen.getByText('nvme-primary +1')).toBeInTheDocument();
expect(screen.getByText('Healthy')).toBeInTheDocument();
+ expect(screen.getByTitle('pre-upgrade, post-upgrade (current)')).toHaveTextContent('2');
const row = screen.getByText('warehouse-api-01').closest('tr');
expect(row).toHaveAttribute('aria-expanded', 'false');
diff --git a/frontend-modern/src/types/__tests__/resource.test.ts b/frontend-modern/src/types/__tests__/resource.test.ts
index 1ae3b38b11..c77de0f060 100644
--- a/frontend-modern/src/types/__tests__/resource.test.ts
+++ b/frontend-modern/src/types/__tests__/resource.test.ts
@@ -268,6 +268,24 @@ describe('Resource Helper Functions', () => {
recentTaskCount: 1,
recentTaskSummary: 'Clone VM task finished',
snapshotCount: 3,
+ currentSnapshotId: 'snapshot-103',
+ snapshotTree: [
+ {
+ snapshot: 'snapshot-101',
+ name: 'baseline',
+ createdAt: '2026-03-30T18:10:00Z',
+ state: 'poweredOn',
+ quiesced: true,
+ children: [
+ {
+ snapshot: 'snapshot-103',
+ name: 'post-upgrade',
+ current: true,
+ quiesced: false,
+ },
+ ],
+ },
+ ],
};
expect(vmware.overallStatus).toBe('yellow');
@@ -278,6 +296,8 @@ describe('Resource Helper Functions', () => {
expect(vmware.activeAlarmCount).toBe(2);
expect(vmware.recentTaskSummary).toBe('Clone VM task finished');
expect(vmware.snapshotCount).toBe(3);
+ expect(vmware.currentSnapshotId).toBe('snapshot-103');
+ expect(vmware.snapshotTree?.[0]?.children?.[0]?.current).toBe(true);
});
});
diff --git a/frontend-modern/src/types/resource.ts b/frontend-modern/src/types/resource.ts
index b3b5a75bca..4b25a9ead3 100644
--- a/frontend-modern/src/types/resource.ts
+++ b/frontend-modern/src/types/resource.ts
@@ -825,6 +825,19 @@ export interface ResourcePMGMeta {
lastUpdated?: string | number;
}
+export interface ResourceVMwareSnapshot {
+ snapshot?: string;
+ name?: string;
+ description?: string;
+ id?: number;
+ createdAt?: string | number;
+ state?: string;
+ quiesced?: boolean;
+ replaySupported?: boolean;
+ current?: boolean;
+ children?: ResourceVMwareSnapshot[];
+}
+
export interface ResourceVMwareMeta {
connectionId?: string;
connectionName?: string;
@@ -866,6 +879,8 @@ export interface ResourceVMwareMeta {
recentTaskCount?: number;
recentTaskSummary?: string;
snapshotCount?: number;
+ currentSnapshotId?: string;
+ snapshotTree?: ResourceVMwareSnapshot[];
}
export interface ResourceAvailabilityMeta {
diff --git a/internal/unifiedresources/canonical_identity_test.go b/internal/unifiedresources/canonical_identity_test.go
index c7a38926f6..832b8ce717 100644
--- a/internal/unifiedresources/canonical_identity_test.go
+++ b/internal/unifiedresources/canonical_identity_test.go
@@ -490,6 +490,19 @@ func TestRefreshCanonicalIdentityIgnoresVMwarePlacementDetailAliases(t *testing.
GuestIPAddresses: []string{"10.0.0.10", "10.0.0.11"},
InstanceUUID: "vm-instance-uuid-1",
BIOSUUID: "vm-bios-uuid-1",
+ CurrentSnapshotID: "snapshot-202",
+ SnapshotTree: []VMwareSnapshotData{{
+ Snapshot: "snapshot-201",
+ Name: "pre-upgrade",
+ Description: "Before application upgrade",
+ State: "poweredOn",
+ Quiesced: true,
+ Children: []VMwareSnapshotData{{
+ Snapshot: "snapshot-202",
+ Name: "post-upgrade",
+ Current: true,
+ }},
+ }},
},
}
@@ -531,6 +544,12 @@ func TestRefreshCanonicalIdentityIgnoresVMwarePlacementDetailAliases(t *testing.
"10.0.0.10",
"10.0.0.11",
"vm-bios-uuid-1",
+ "snapshot-201",
+ "snapshot-202",
+ "pre-upgrade",
+ "post-upgrade",
+ "Before application upgrade",
+ "poweredOn",
}
for _, disallowed := range disallowedAliases {
for _, alias := range resource.Canonical.Aliases {
diff --git a/internal/unifiedresources/types.go b/internal/unifiedresources/types.go
index 02e1f7cb2c..71d99f53a6 100644
--- a/internal/unifiedresources/types.go
+++ b/internal/unifiedresources/types.go
@@ -995,46 +995,63 @@ type PMGData struct {
// VMwareData contains VMware vSphere metadata for canonical agent, vm, and
// storage resources projected from one vCenter connection.
type VMwareData struct {
- ConnectionID string `json:"connectionId,omitempty"`
- ConnectionName string `json:"connectionName,omitempty"`
- VCenterHost string `json:"vcenterHost,omitempty"`
- ManagedObjectID string `json:"managedObjectId,omitempty"`
- EntityType string `json:"entityType,omitempty"`
- HostUUID string `json:"hostUuid,omitempty"`
- DatacenterID string `json:"datacenterId,omitempty"`
- DatacenterName string `json:"datacenterName,omitempty"`
- ComputeResourceID string `json:"computeResourceId,omitempty"`
- ComputeResourceName string `json:"computeResourceName,omitempty"`
- ClusterID string `json:"clusterId,omitempty"`
- ClusterName string `json:"clusterName,omitempty"`
- FolderID string `json:"folderId,omitempty"`
- FolderName string `json:"folderName,omitempty"`
- ResourcePoolID string `json:"resourcePoolId,omitempty"`
- ResourcePoolName string `json:"resourcePoolName,omitempty"`
- RuntimeHostID string `json:"runtimeHostId,omitempty"`
- RuntimeHostName string `json:"runtimeHostName,omitempty"`
- ConnectionState string `json:"connectionState,omitempty"`
- PowerState string `json:"powerState,omitempty"`
- OverallStatus string `json:"overallStatus,omitempty"`
- CPUCount int `json:"cpuCount,omitempty"`
- MemorySizeMiB int64 `json:"memorySizeMib,omitempty"`
- DatastoreType string `json:"datastoreType,omitempty"`
- DatastoreIDs []string `json:"datastoreIds,omitempty"`
- DatastoreNames []string `json:"datastoreNames,omitempty"`
- DatastoreURL string `json:"datastoreUrl,omitempty"`
- DatastoreAccessible *bool `json:"datastoreAccessible,omitempty"`
- MultipleHostAccess *bool `json:"multipleHostAccess,omitempty"`
- MaintenanceMode string `json:"maintenanceMode,omitempty"`
- InstanceUUID string `json:"instanceUuid,omitempty"`
- BIOSUUID string `json:"biosUuid,omitempty"`
- GuestOSFamily string `json:"guestOsFamily,omitempty"`
- GuestHostname string `json:"guestHostname,omitempty"`
- GuestIPAddresses []string `json:"guestIpAddresses,omitempty"`
- ActiveAlarmCount int `json:"activeAlarmCount,omitempty"`
- ActiveAlarmSummary string `json:"activeAlarmSummary,omitempty"`
- RecentTaskCount int `json:"recentTaskCount,omitempty"`
- RecentTaskSummary string `json:"recentTaskSummary,omitempty"`
- SnapshotCount int `json:"snapshotCount,omitempty"`
+ ConnectionID string `json:"connectionId,omitempty"`
+ ConnectionName string `json:"connectionName,omitempty"`
+ VCenterHost string `json:"vcenterHost,omitempty"`
+ ManagedObjectID string `json:"managedObjectId,omitempty"`
+ EntityType string `json:"entityType,omitempty"`
+ HostUUID string `json:"hostUuid,omitempty"`
+ DatacenterID string `json:"datacenterId,omitempty"`
+ DatacenterName string `json:"datacenterName,omitempty"`
+ ComputeResourceID string `json:"computeResourceId,omitempty"`
+ ComputeResourceName string `json:"computeResourceName,omitempty"`
+ ClusterID string `json:"clusterId,omitempty"`
+ ClusterName string `json:"clusterName,omitempty"`
+ FolderID string `json:"folderId,omitempty"`
+ FolderName string `json:"folderName,omitempty"`
+ ResourcePoolID string `json:"resourcePoolId,omitempty"`
+ ResourcePoolName string `json:"resourcePoolName,omitempty"`
+ RuntimeHostID string `json:"runtimeHostId,omitempty"`
+ RuntimeHostName string `json:"runtimeHostName,omitempty"`
+ ConnectionState string `json:"connectionState,omitempty"`
+ PowerState string `json:"powerState,omitempty"`
+ OverallStatus string `json:"overallStatus,omitempty"`
+ CPUCount int `json:"cpuCount,omitempty"`
+ MemorySizeMiB int64 `json:"memorySizeMib,omitempty"`
+ DatastoreType string `json:"datastoreType,omitempty"`
+ DatastoreIDs []string `json:"datastoreIds,omitempty"`
+ DatastoreNames []string `json:"datastoreNames,omitempty"`
+ DatastoreURL string `json:"datastoreUrl,omitempty"`
+ DatastoreAccessible *bool `json:"datastoreAccessible,omitempty"`
+ MultipleHostAccess *bool `json:"multipleHostAccess,omitempty"`
+ MaintenanceMode string `json:"maintenanceMode,omitempty"`
+ InstanceUUID string `json:"instanceUuid,omitempty"`
+ BIOSUUID string `json:"biosUuid,omitempty"`
+ GuestOSFamily string `json:"guestOsFamily,omitempty"`
+ GuestHostname string `json:"guestHostname,omitempty"`
+ GuestIPAddresses []string `json:"guestIpAddresses,omitempty"`
+ ActiveAlarmCount int `json:"activeAlarmCount,omitempty"`
+ ActiveAlarmSummary string `json:"activeAlarmSummary,omitempty"`
+ RecentTaskCount int `json:"recentTaskCount,omitempty"`
+ RecentTaskSummary string `json:"recentTaskSummary,omitempty"`
+ SnapshotCount int `json:"snapshotCount,omitempty"`
+ CurrentSnapshotID string `json:"currentSnapshotId,omitempty"`
+ SnapshotTree []VMwareSnapshotData `json:"snapshotTree,omitempty"`
+}
+
+// VMwareSnapshotData contains one node in the vSphere VM snapshot tree. It is
+// read-side workload context only, not a Pulse recovery artifact.
+type VMwareSnapshotData struct {
+ Snapshot string `json:"snapshot,omitempty"`
+ Name string `json:"name,omitempty"`
+ Description string `json:"description,omitempty"`
+ ID int `json:"id,omitempty"`
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
+ State string `json:"state,omitempty"`
+ Quiesced bool `json:"quiesced"`
+ ReplaySupported bool `json:"replaySupported,omitempty"`
+ Current bool `json:"current,omitempty"`
+ Children []VMwareSnapshotData `json:"children,omitempty"`
}
// TrueNASData contains TrueNAS-specific metadata for TrueNAS resources.
diff --git a/internal/vmware/client_signals.go b/internal/vmware/client_signals.go
index d7c030163d..3c9e6c7dca 100644
--- a/internal/vmware/client_signals.go
+++ b/internal/vmware/client_signals.go
@@ -62,10 +62,19 @@ type viJSONEvent struct {
}
type viJSONSnapshotInfo struct {
+ CurrentSnapshot *viJSONReference `json:"currentSnapshot"`
RootSnapshotList []viJSONSnapshotTree `json:"rootSnapshotList"`
}
type viJSONSnapshotTree struct {
+ Snapshot viJSONReference `json:"snapshot"`
+ Name string `json:"name"`
+ Description string `json:"description"`
+ ID int `json:"id"`
+ CreateTime *time.Time `json:"createTime"`
+ State string `json:"state"`
+ Quiesced bool `json:"quiesced"`
+ ReplaySupported bool `json:"replaySupported"`
ChildSnapshotList []viJSONSnapshotTree `json:"childSnapshotList"`
}
@@ -117,7 +126,7 @@ func (c *Client) validateSignalFloor(
if _, err := c.collectManagedEntitySignals(ctx, release, sessionID, "VirtualMachine", vm.VM, perfManagerMoID, eventManagerMoID, cache, false); err != nil {
return err
}
- if _, err := c.collectVMSnapshotCount(ctx, release, sessionID, vm.VM); err != nil && !isVIJSONNotFound(err) {
+ if _, _, err := c.collectVMSnapshotTree(ctx, release, sessionID, vm.VM); err != nil && !isVIJSONNotFound(err) {
return err
}
vmMetrics, err := c.collectVMPerformanceMetrics(ctx, release, sessionID, perfManagerMoID, perfCounters, vm)
@@ -221,12 +230,15 @@ func (c *Client) enrichInventorySnapshot(
snapshot.VMs[i].TriggeredAlarms = signals.Alarms
snapshot.VMs[i].RecentTasks = signals.RecentTasks
snapshot.VMs[i].RecentEvents = signals.RecentEvents
- snapshot.VMs[i].SnapshotCount, err = c.collectVMSnapshotCount(ctx, release, sessionID, snapshot.VMs[i].VM)
+ snapshotTree, currentSnapshotID, err := c.collectVMSnapshotTree(ctx, release, sessionID, snapshot.VMs[i].VM)
if issue, ok := classifyInventoryEnrichmentIssue("signals", "vm", snapshot.VMs[i].VM, err); ok {
recordIssue(issue)
} else if err != nil && !isVIJSONNotFound(err) {
return err
}
+ snapshot.VMs[i].SnapshotTree = snapshotTree
+ snapshot.VMs[i].CurrentSnapshotID = currentSnapshotID
+ snapshot.VMs[i].SnapshotCount = countInventoryVMSnapshotTrees(snapshotTree)
metrics, err := c.collectVMPerformanceMetrics(ctx, release, sessionID, perfManagerMoID, perfCounters, snapshot.VMs[i])
if issue, ok := classifyInventoryEnrichmentIssue("signals", "vm", snapshot.VMs[i].VM, err); ok {
recordIssue(issue)
@@ -485,13 +497,20 @@ func (c *Client) collectRecentEvents(ctx context.Context, release, sessionID, ev
return events, nil
}
-func (c *Client) collectVMSnapshotCount(ctx context.Context, release, sessionID, managedObjectID string) (int, error) {
+func (c *Client) collectVMSnapshotTree(ctx context.Context, release, sessionID, managedObjectID string) ([]InventoryVMSnapshot, string, error) {
var payload viJSONSnapshotInfo
path := fmt.Sprintf("/sdk/vim25/%s/VirtualMachine/%s/snapshot", release, managedObjectID)
if err := c.getVIJSONJSON(ctx, sessionID, path, "vmware vm snapshot tree", &payload); err != nil {
- return 0, err
+ if isVIJSONNotFound(err) {
+ return nil, "", nil
+ }
+ return nil, "", err
+ }
+ currentSnapshotID := ""
+ if payload.CurrentSnapshot != nil {
+ currentSnapshotID = strings.TrimSpace(payload.CurrentSnapshot.Value)
}
- return countSnapshotTrees(payload.RootSnapshotList), nil
+ return mapVIJSONSnapshotTrees(payload.RootSnapshotList, currentSnapshotID), currentSnapshotID, nil
}
func (c *Client) resolveAlarmName(ctx context.Context, release, sessionID, alarmID string, cache *alarmNameCache) (string, error) {
@@ -585,11 +604,39 @@ func inventoryEventSortTime(event InventoryEvent) time.Time {
return event.CreatedAt.UTC()
}
-func countSnapshotTrees(roots []viJSONSnapshotTree) int {
+func mapVIJSONSnapshotTrees(roots []viJSONSnapshotTree, currentSnapshotID string) []InventoryVMSnapshot {
+ if len(roots) == 0 {
+ return nil
+ }
+ out := make([]InventoryVMSnapshot, 0, len(roots))
+ for _, root := range roots {
+ snapshotID := strings.TrimSpace(root.Snapshot.Value)
+ var createdAt *time.Time
+ if root.CreateTime != nil {
+ created := root.CreateTime.UTC()
+ createdAt = &created
+ }
+ out = append(out, InventoryVMSnapshot{
+ Snapshot: snapshotID,
+ Name: strings.TrimSpace(root.Name),
+ Description: strings.TrimSpace(root.Description),
+ ID: root.ID,
+ CreatedAt: createdAt,
+ State: strings.TrimSpace(root.State),
+ Quiesced: root.Quiesced,
+ ReplaySupported: root.ReplaySupported,
+ Current: snapshotID != "" && snapshotID == currentSnapshotID,
+ Children: mapVIJSONSnapshotTrees(root.ChildSnapshotList, currentSnapshotID),
+ })
+ }
+ return out
+}
+
+func countInventoryVMSnapshotTrees(roots []InventoryVMSnapshot) int {
count := 0
for _, root := range roots {
count++
- count += countSnapshotTrees(root.ChildSnapshotList)
+ count += countInventoryVMSnapshotTrees(root.Children)
}
return count
}
diff --git a/internal/vmware/client_test.go b/internal/vmware/client_test.go
index c79be08e43..666b537d30 100644
--- a/internal/vmware/client_test.go
+++ b/internal/vmware/client_test.go
@@ -78,6 +78,15 @@ func TestClientCollectInventoryEnrichesSignals(t *testing.T) {
if vm.SnapshotCount != 2 {
t.Fatalf("vm snapshot count = %d, want 2", vm.SnapshotCount)
}
+ if vm.CurrentSnapshotID != "snapshot-202" {
+ t.Fatalf("vm current snapshot id = %q, want snapshot-202", vm.CurrentSnapshotID)
+ }
+ if len(vm.SnapshotTree) != 1 || vm.SnapshotTree[0].Name != "pre-upgrade" || len(vm.SnapshotTree[0].Children) != 1 {
+ t.Fatalf("expected VM snapshot tree with one child, got %+v", vm.SnapshotTree)
+ }
+ if !vm.SnapshotTree[0].Quiesced || !vm.SnapshotTree[0].Children[0].Current {
+ t.Fatalf("expected quiesced root and current child snapshot, got %+v", vm.SnapshotTree)
+ }
if len(vm.RecentTasks) != 1 || vm.RecentTasks[0].State != "success" {
t.Fatalf("expected VM recent task info, got %+v", vm.RecentTasks)
}
@@ -563,8 +572,24 @@ func newVMwareTestServer(t *testing.T, cfg vmwareTestServerConfig) *httptest.Ser
mux.HandleFunc("/sdk/vim25/9.0.0.0/VirtualMachine/vm-201/snapshot", func(w http.ResponseWriter, r *http.Request) {
requireVISession(t, r)
writeJSON(w, map[string]any{
+ "currentSnapshot": map[string]any{"type": "VirtualMachineSnapshot", "value": "snapshot-202"},
"rootSnapshotList": []map[string]any{{
- "childSnapshotList": []map[string]any{{"childSnapshotList": []map[string]any{}}},
+ "snapshot": map[string]any{"type": "VirtualMachineSnapshot", "value": "snapshot-201"},
+ "name": "pre-upgrade",
+ "description": "Before application upgrade",
+ "id": 101,
+ "createTime": "2026-03-28T18:15:00Z",
+ "state": "poweredOn",
+ "quiesced": true,
+ "childSnapshotList": []map[string]any{{
+ "snapshot": map[string]any{"type": "VirtualMachineSnapshot", "value": "snapshot-202"},
+ "name": "post-migration-checkpoint",
+ "id": 102,
+ "createTime": "2026-03-29T18:15:00Z",
+ "state": "poweredOn",
+ "quiesced": false,
+ "childSnapshotList": []map[string]any{},
+ }},
}},
})
})
diff --git a/internal/vmware/fixtures.go b/internal/vmware/fixtures.go
index 202eb8f517..880e1a5b25 100644
--- a/internal/vmware/fixtures.go
+++ b/internal/vmware/fixtures.go
@@ -207,6 +207,17 @@ func defaultFixturesPrimaryCluster(
GuestIPAddresses: []string{"10.42.10.21"},
OverallStatus: "green",
SnapshotCount: 1,
+ CurrentSnapshotID: "snapshot-201",
+ SnapshotTree: []InventoryVMSnapshot{{
+ Snapshot: "snapshot-201",
+ Name: "pre-deploy-checkpoint",
+ Description: "Before service deployment",
+ ID: 201,
+ CreatedAt: inventorySnapshotTime(collectedAt.Add(-46 * time.Minute)),
+ State: "poweredOn",
+ Quiesced: true,
+ Current: true,
+ }},
Metrics: &InventoryMetrics{
CPUPercent: float64Ptr(36.2),
MemoryPercent: float64Ptr(64.4),
@@ -252,6 +263,31 @@ func defaultFixturesPrimaryCluster(
GuestIPAddresses: []string{"10.42.10.32"},
OverallStatus: "yellow",
SnapshotCount: 3,
+ CurrentSnapshotID: "snapshot-213",
+ SnapshotTree: []InventoryVMSnapshot{{
+ Snapshot: "snapshot-211",
+ Name: "baseline",
+ ID: 211,
+ CreatedAt: inventorySnapshotTime(collectedAt.Add(-72 * time.Hour)),
+ State: "poweredOn",
+ Quiesced: true,
+ Children: []InventoryVMSnapshot{{
+ Snapshot: "snapshot-212",
+ Name: "schema-migration",
+ ID: 212,
+ CreatedAt: inventorySnapshotTime(collectedAt.Add(-36 * time.Hour)),
+ State: "poweredOn",
+ Quiesced: true,
+ Children: []InventoryVMSnapshot{{
+ Snapshot: "snapshot-213",
+ Name: "post-migration",
+ ID: 213,
+ CreatedAt: inventorySnapshotTime(collectedAt.Add(-18 * time.Hour)),
+ State: "poweredOn",
+ Current: true,
+ }},
+ }},
+ }},
Metrics: &InventoryMetrics{
CPUPercent: float64Ptr(58.8),
MemoryPercent: float64Ptr(82.1),
@@ -750,3 +786,8 @@ func guestOSFamily(name string) string {
return "LINUX"
}
}
+
+func inventorySnapshotTime(value time.Time) *time.Time {
+ timestamp := value.UTC()
+ return &timestamp
+}
diff --git a/internal/vmware/provider.go b/internal/vmware/provider.go
index ae9443169e..601c087573 100644
--- a/internal/vmware/provider.go
+++ b/internal/vmware/provider.go
@@ -38,6 +38,21 @@ type InventoryEvent struct {
CreatedAt time.Time `json:"created_at,omitempty"`
}
+// InventoryVMSnapshot preserves the VI JSON snapshot tree as read-only VM
+// context. It must not be promoted into Pulse recovery artifacts.
+type InventoryVMSnapshot struct {
+ Snapshot string `json:"snapshot,omitempty"`
+ Name string `json:"name,omitempty"`
+ Description string `json:"description,omitempty"`
+ ID int `json:"id,omitempty"`
+ CreatedAt *time.Time `json:"created_at,omitempty"`
+ State string `json:"state,omitempty"`
+ Quiesced bool `json:"quiesced"`
+ ReplaySupported bool `json:"replay_supported,omitempty"`
+ Current bool `json:"current,omitempty"`
+ Children []InventoryVMSnapshot `json:"children,omitempty"`
+}
+
// InventoryMetrics captures the current runtime metric floor projected onto
// canonical Pulse metrics for VMware-backed hosts and VMs.
type InventoryMetrics struct {
@@ -90,36 +105,38 @@ type InventoryHost struct {
// InventoryVM is the canonical phase-1 VM summary returned by the vCenter
// Automation API list endpoint.
type InventoryVM struct {
- VM string `json:"vm"`
- Name string `json:"name"`
- PowerState string `json:"power_state"`
- CPUCount int `json:"cpu_count,omitempty"`
- MemorySizeMiB int64 `json:"memory_size_mib,omitempty"`
- DatacenterID string `json:"datacenter_id,omitempty"`
- DatacenterName string `json:"datacenter_name,omitempty"`
- ComputeResourceID string `json:"compute_resource_id,omitempty"`
- ComputeResourceName string `json:"compute_resource_name,omitempty"`
- ClusterID string `json:"cluster_id,omitempty"`
- ClusterName string `json:"cluster_name,omitempty"`
- FolderID string `json:"folder_id,omitempty"`
- FolderName string `json:"folder_name,omitempty"`
- ResourcePoolID string `json:"resource_pool_id,omitempty"`
- ResourcePoolName string `json:"resource_pool_name,omitempty"`
- RuntimeHostID string `json:"runtime_host_id,omitempty"`
- RuntimeHostName string `json:"runtime_host_name,omitempty"`
- DatastoreIDs []string `json:"datastore_ids,omitempty"`
- DatastoreNames []string `json:"datastore_names,omitempty"`
- InstanceUUID string `json:"instance_uuid,omitempty"`
- BIOSUUID string `json:"bios_uuid,omitempty"`
- GuestOSFamily string `json:"guest_os_family,omitempty"`
- GuestHostname string `json:"guest_hostname,omitempty"`
- GuestIPAddresses []string `json:"guest_ip_addresses,omitempty"`
- OverallStatus string `json:"overall_status,omitempty"`
- TriggeredAlarms []InventoryAlarm `json:"triggered_alarms,omitempty"`
- RecentTasks []InventoryTask `json:"recent_tasks,omitempty"`
- RecentEvents []InventoryEvent `json:"recent_events,omitempty"`
- SnapshotCount int `json:"snapshot_count,omitempty"`
- Metrics *InventoryMetrics `json:"metrics,omitempty"`
+ VM string `json:"vm"`
+ Name string `json:"name"`
+ PowerState string `json:"power_state"`
+ CPUCount int `json:"cpu_count,omitempty"`
+ MemorySizeMiB int64 `json:"memory_size_mib,omitempty"`
+ DatacenterID string `json:"datacenter_id,omitempty"`
+ DatacenterName string `json:"datacenter_name,omitempty"`
+ ComputeResourceID string `json:"compute_resource_id,omitempty"`
+ ComputeResourceName string `json:"compute_resource_name,omitempty"`
+ ClusterID string `json:"cluster_id,omitempty"`
+ ClusterName string `json:"cluster_name,omitempty"`
+ FolderID string `json:"folder_id,omitempty"`
+ FolderName string `json:"folder_name,omitempty"`
+ ResourcePoolID string `json:"resource_pool_id,omitempty"`
+ ResourcePoolName string `json:"resource_pool_name,omitempty"`
+ RuntimeHostID string `json:"runtime_host_id,omitempty"`
+ RuntimeHostName string `json:"runtime_host_name,omitempty"`
+ DatastoreIDs []string `json:"datastore_ids,omitempty"`
+ DatastoreNames []string `json:"datastore_names,omitempty"`
+ InstanceUUID string `json:"instance_uuid,omitempty"`
+ BIOSUUID string `json:"bios_uuid,omitempty"`
+ GuestOSFamily string `json:"guest_os_family,omitempty"`
+ GuestHostname string `json:"guest_hostname,omitempty"`
+ GuestIPAddresses []string `json:"guest_ip_addresses,omitempty"`
+ OverallStatus string `json:"overall_status,omitempty"`
+ TriggeredAlarms []InventoryAlarm `json:"triggered_alarms,omitempty"`
+ RecentTasks []InventoryTask `json:"recent_tasks,omitempty"`
+ RecentEvents []InventoryEvent `json:"recent_events,omitempty"`
+ SnapshotCount int `json:"snapshot_count,omitempty"`
+ CurrentSnapshotID string `json:"current_snapshot_id,omitempty"`
+ SnapshotTree []InventoryVMSnapshot `json:"snapshot_tree,omitempty"`
+ Metrics *InventoryMetrics `json:"metrics,omitempty"`
}
// InventoryDatastore is the canonical phase-1 datastore summary returned by
@@ -465,6 +482,8 @@ func vmwareRecordsFromSnapshot(snapshot *InventorySnapshot, now func() time.Time
RecentTaskCount: len(vm.RecentTasks),
RecentTaskSummary: vmwareRecentTaskSummary(vm.RecentTasks),
SnapshotCount: vm.SnapshotCount,
+ CurrentSnapshotID: strings.TrimSpace(vm.CurrentSnapshotID),
+ SnapshotTree: vmwareSnapshotTreeData(vm.SnapshotTree),
},
Tags: filterNonEmptyStrings(
"vmware",
@@ -622,6 +641,7 @@ func cloneInventoryVMs(in []InventoryVM) []InventoryVM {
out[i].TriggeredAlarms = cloneInventoryAlarms(in[i].TriggeredAlarms)
out[i].RecentTasks = cloneInventoryTasks(in[i].RecentTasks)
out[i].RecentEvents = cloneInventoryEvents(in[i].RecentEvents)
+ out[i].SnapshotTree = cloneInventoryVMSnapshots(in[i].SnapshotTree)
out[i].Metrics = cloneInventoryMetrics(in[i].Metrics)
}
return out
@@ -674,6 +694,19 @@ func cloneInventoryEvents(in []InventoryEvent) []InventoryEvent {
return out
}
+func cloneInventoryVMSnapshots(in []InventoryVMSnapshot) []InventoryVMSnapshot {
+ if in == nil {
+ return nil
+ }
+ out := make([]InventoryVMSnapshot, len(in))
+ for i := range in {
+ out[i] = in[i]
+ out[i].CreatedAt = cloneTimePointer(in[i].CreatedAt)
+ out[i].Children = cloneInventoryVMSnapshots(in[i].Children)
+ }
+ return out
+}
+
func cloneInventoryEnrichmentIssues(in []InventoryEnrichmentIssue) []InventoryEnrichmentIssue {
if in == nil {
return nil
@@ -707,6 +740,14 @@ func cloneInventoryMetrics(in *InventoryMetrics) *InventoryMetrics {
return &out
}
+func cloneTimePointer(in *time.Time) *time.Time {
+ if in == nil {
+ return nil
+ }
+ out := in.UTC()
+ return &out
+}
+
func vmwareSourceID(connectionID, entityType, managedObjectID string) string {
parts := filterNonEmptyStrings(strings.TrimSpace(connectionID), strings.TrimSpace(entityType), strings.TrimSpace(managedObjectID))
return strings.Join(parts, ":")
@@ -975,6 +1016,29 @@ func vmwareDatastoreTopConsumers(datastore InventoryDatastore) []unifiedresource
return consumers
}
+func vmwareSnapshotTreeData(snapshots []InventoryVMSnapshot) []unifiedresources.VMwareSnapshotData {
+ if len(snapshots) == 0 {
+ return nil
+ }
+ out := make([]unifiedresources.VMwareSnapshotData, 0, len(snapshots))
+ for _, snapshot := range snapshots {
+ item := unifiedresources.VMwareSnapshotData{
+ Snapshot: strings.TrimSpace(snapshot.Snapshot),
+ Name: strings.TrimSpace(snapshot.Name),
+ Description: strings.TrimSpace(snapshot.Description),
+ ID: snapshot.ID,
+ CreatedAt: cloneTimePointer(snapshot.CreatedAt),
+ State: strings.TrimSpace(snapshot.State),
+ Quiesced: snapshot.Quiesced,
+ ReplaySupported: snapshot.ReplaySupported,
+ Current: snapshot.Current,
+ Children: vmwareSnapshotTreeData(snapshot.Children),
+ }
+ out = append(out, item)
+ }
+ return out
+}
+
func diskMetric(total, used int64) *unifiedresources.MetricValue {
if total <= 0 {
return nil
diff --git a/internal/vmware/provider_test.go b/internal/vmware/provider_test.go
index 5c63dcaf2a..8309663b4a 100644
--- a/internal/vmware/provider_test.go
+++ b/internal/vmware/provider_test.go
@@ -106,7 +106,25 @@ func TestProviderRecords_ProjectCanonicalVMwareResources(t *testing.T) {
State: "success",
StartedAt: collectedAt.Add(-5 * time.Minute),
}},
- SnapshotCount: 2,
+ SnapshotCount: 2,
+ CurrentSnapshotID: "snapshot-202",
+ SnapshotTree: []InventoryVMSnapshot{{
+ Snapshot: "snapshot-201",
+ Name: "pre-upgrade",
+ Description: "Before application upgrade",
+ ID: 101,
+ CreatedAt: timePtr(collectedAt.Add(-48 * time.Hour)),
+ State: "poweredOn",
+ Quiesced: true,
+ Children: []InventoryVMSnapshot{{
+ Snapshot: "snapshot-202",
+ Name: "post-migration-checkpoint",
+ ID: 102,
+ CreatedAt: timePtr(collectedAt.Add(-24 * time.Hour)),
+ State: "poweredOn",
+ Current: true,
+ }},
+ }},
}},
Datastores: []InventoryDatastore{{
Datastore: "datastore-11",
@@ -207,6 +225,12 @@ func TestProviderRecords_ProjectCanonicalVMwareResources(t *testing.T) {
if got := vmRecord.Resource.VMware.SnapshotCount; got != 2 {
t.Fatalf("vm snapshot count = %d, want 2", got)
}
+ if got := vmRecord.Resource.VMware.CurrentSnapshotID; got != "snapshot-202" {
+ t.Fatalf("vm current snapshot id = %q, want snapshot-202", got)
+ }
+ if got := vmRecord.Resource.VMware.SnapshotTree; len(got) != 1 || got[0].Name != "pre-upgrade" || len(got[0].Children) != 1 || !got[0].Children[0].Current {
+ t.Fatalf("vm snapshot tree projection = %+v, want root pre-upgrade with current child", got)
+ }
if got := vmRecord.Resource.ParentName; got != "esxi-01.lab.local" {
t.Fatalf("vm parent name = %q, want esxi-01.lab.local", got)
}
@@ -358,3 +382,7 @@ func TestProviderActivityChanges_ProjectCanonicalTimelineEntries(t *testing.T) {
func boolPtr(value bool) *bool {
return &value
}
+
+func timePtr(value time.Time) *time.Time {
+ return &value
+}