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.

Make vSphere datastores API-native

rcourtmanb19beb197639
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 51141607a2..bf323c2749 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -115,6 +115,7 @@ cross-source deduplication.
91. `internal/unifiedresources/policy_posture.go`
92. `internal/unifiedresources/clone.go`
93. `frontend-modern/src/components/Infrastructure/resourceDetailDrawerPresentation.ts`
+94. `internal/unifiedresources/storage_consumers.go`
## Shared Boundaries
@@ -403,6 +404,13 @@ AI-only summary payloads, or page-local heuristics.
`internal/unifiedresources/registry.go` so matcher seeding, manual links,
and merge semantics stay unified-resource-owned instead of being rebuilt in
consumers.
+ Storage consumer projection is unified-resource-owned through
+ `internal/unifiedresources/storage_consumers.go`. When a provider publishes
+ source-native storage consumer metadata that cannot be derived from shared
+ Proxmox/PBS relationship indexes, refresh must preserve that source-owned
+ consumer count, consumer type list, and top-consumer summary on the
+ canonical storage resource unless a stronger shared consumer projection has
+ already populated those fields in the same refresh.
Operator-facing storage posture wording is part of that same ownership:
when multiple storage-risk reasons exist, shared posture helpers must prefer
the most decision-useful protection loss summary such as lost parity over a
diff --git a/frontend-modern/src/features/platformPage/__tests__/platformOverviewLayout.guardrails.test.ts b/frontend-modern/src/features/platformPage/__tests__/platformOverviewLayout.guardrails.test.ts
index c9aecae460..cb95ca93e0 100644
--- a/frontend-modern/src/features/platformPage/__tests__/platformOverviewLayout.guardrails.test.ts
+++ b/frontend-modern/src/features/platformPage/__tests__/platformOverviewLayout.guardrails.test.ts
@@ -24,6 +24,7 @@ import truenasStorageTopologyTableSource from '@/features/truenas/TrueNASStorage
import truenasSystemsTableSource from '@/features/truenas/TrueNASSystemsTable.tsx?raw';
import truenasVirtualMachinesTableSource from '@/features/truenas/TrueNASVirtualMachinesTable.tsx?raw';
import vmwarePageSurfaceSource from '@/features/vmware/VmwarePageSurface.tsx?raw';
+import vsphereDatastoresTableSource from '@/features/vmware/VsphereDatastoresTable.tsx?raw';
import vsphereHostsTableSource from '@/features/vmware/VsphereHostsTable.tsx?raw';
const platformTableSources = [
@@ -40,6 +41,7 @@ const platformTableSources = [
truenasStorageTopologyTableSource,
truenasSystemsTableSource,
truenasVirtualMachinesTableSource,
+ vsphereDatastoresTableSource,
vsphereHostsTableSource,
];
@@ -191,8 +193,8 @@ describe('platform overview layout guardrails', () => {
expect(truenasVirtualMachinesTableSource).toContain('md:min-w-[960px]');
expect(vmwarePageSurfaceSource).toContain('<VsphereHostsTable');
expect(vmwarePageSurfaceSource).toContain('<WorkloadsSurface');
- expect(vmwarePageSurfaceSource).toContain('<StorageSurface');
- expect(vmwarePageSurfaceSource).toContain('suppressNodeFilter');
+ expect(vmwarePageSurfaceSource).toContain('<VsphereDatastoresTable');
+ expect(vmwarePageSurfaceSource).not.toContain('<StorageSurface');
expect(vmwarePageSurfaceSource).not.toContain('forcedView="pools"');
expect(proxmoxPageSurfaceSource).toContain('suppressNodeFilter');
});
diff --git a/frontend-modern/src/features/vmware/VmwarePageSurface.tsx b/frontend-modern/src/features/vmware/VmwarePageSurface.tsx
index 3ca1988d84..d1618cbd58 100644
--- a/frontend-modern/src/features/vmware/VmwarePageSurface.tsx
+++ b/frontend-modern/src/features/vmware/VmwarePageSurface.tsx
@@ -1,7 +1,6 @@
import { useLocation } from '@solidjs/router';
import CpuIcon from 'lucide-solid/icons/cpu';
import { Show, createMemo, type Accessor } from 'solid-js';
-import StorageSurface from '@/components/Storage/Storage';
import { WorkloadsFilter } from '@/components/Workloads/WorkloadsFilter';
import { WorkloadsSurface } from '@/components/Workloads/WorkloadsSurface';
import { useWorkloadsState } from '@/components/Workloads/useWorkloadsState';
@@ -21,10 +20,11 @@ import {
type VmwarePageModel,
type VmwarePageTabId,
} from './vmwarePageModel';
+import { VsphereDatastoresTable } from './VsphereDatastoresTable';
-// `datastore` is not a first-class type token at the API boundary; vSphere
-// datastores are emitted as canonical `storage` rows. Including it
-// triggers a 400 from `/api/resources`.
+// vSphere phase 1 projects ESXi hosts as canonical `agent`, virtual machines
+// as canonical `vm`, and datastores as canonical `storage`; provider-native
+// topology stays in VMware metadata under those shared resources.
const VMWARE_RESOURCE_QUERY = 'type=agent,vm,storage';
const VMWARE_PLATFORM_FILTER = 'vmware-vsphere';
const VALID_TABS = new Set<VmwarePageTabId>(VMWARE_TAB_SPECS.map((tab) => tab.id));
@@ -91,15 +91,12 @@ export function VmwarePageSurface() {
<VmwareOverview model={model} />
</Show>
<Show when={activeTab() === 'storage'}>
- <StorageSurface
- embedded
- tableOnly
- showFilterToolbar
- forcedSourceFilter={VMWARE_PLATFORM_FILTER}
- suppressNodeFilter
- filterAriaLabel="vSphere datastore filters"
- filterSearchPlaceholder="Search vSphere datastores by name, host, or capacity group"
- filterSearchEmptyMessage="Recent vSphere datastore searches appear here."
+ <VsphereDatastoresTable
+ datastores={model().datastores}
+ scope={model().resources}
+ emptyIcon={vmwareIcon()}
+ emptyTitle="No vSphere datastores"
+ emptyDescription="Datastores appear here once the vCenter connection enumerates them."
/>
</Show>
</Show>
diff --git a/frontend-modern/src/features/vmware/VsphereDatastoresTable.tsx b/frontend-modern/src/features/vmware/VsphereDatastoresTable.tsx
new file mode 100644
index 0000000000..8133de7177
--- /dev/null
+++ b/frontend-modern/src/features/vmware/VsphereDatastoresTable.tsx
@@ -0,0 +1,353 @@
+import { For, Show, createMemo, type Component, type JSX } from 'solid-js';
+import { StatusDot } from '@/components/shared/StatusDot';
+import { TableCard } from '@/components/shared/TableCard';
+import { TableCardHeader } from '@/components/shared/TableCardHeader';
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from '@/components/shared/Table';
+import { formatBytes, formatPercent } from '@/utils/format';
+import { getSimpleStatusIndicator } from '@/utils/status';
+import { asTrimmedString } from '@/utils/stringUtils';
+import {
+ PLATFORM_TABLE_BODY_CLASS,
+ PLATFORM_TABLE_CARD_CLASS,
+ PLATFORM_TABLE_HEADER_ROW_CLASS,
+ PlatformTableEmptyState,
+ PlatformTableToolbar,
+ createPlatformTableFilterState,
+ getPlatformTableCellClassForKind,
+ getPlatformTableHeadClassForKind,
+ type PlatformTableFilterOption,
+} from '@/features/platformPage/sharedPlatformPage';
+import {
+ PlatformResourceDetailTableRow,
+ createPlatformResourceDetailState,
+ createPlatformResourceLabelResolver,
+ getPlatformResourceDetailRowClass,
+} from '@/features/platformPage/PlatformResourceDetailTableRow';
+import type { Resource } from '@/types/resource';
+import {
+ filterVmwareDatastores,
+ mapVmwareDatastoreStatus,
+ type VmwareDatastoreStatusFilter,
+} from './vmwarePageModel';
+
+const VSPHERE_DATASTORE_STATUS_OPTIONS: PlatformTableFilterOption<VmwareDatastoreStatusFilter>[] = [
+ { value: 'all', label: 'All' },
+ { value: 'accessible', label: 'Accessible', tone: 'success' },
+ { value: 'attention', label: 'Attention', tone: 'warning' },
+ { value: 'inaccessible', label: 'Inaccessible', tone: 'danger' },
+ { value: 'maintenance', label: 'Maintenance', tone: 'warning' },
+ { value: 'unknown', label: 'Unknown' },
+];
+
+const datastoreName = (resource: Resource): string =>
+ asTrimmedString(resource.displayName) || asTrimmedString(resource.name) || resource.id;
+
+const datastoreType = (resource: Resource): string =>
+ asTrimmedString(resource.vmware?.datastoreType) ||
+ asTrimmedString(resource.storage?.type)?.toUpperCase() ||
+ '-';
+
+const compactList = (values: Array<string | undefined>): string[] =>
+ values.map((value) => asTrimmedString(value)).filter((value): value is string => Boolean(value));
+
+const summarizeValues = (
+ values: string[],
+ empty = '-',
+ visibleCount = 2,
+): { label: string; title: string } => {
+ if (values.length === 0) return { label: empty, title: '' };
+ const visible = values.slice(0, visibleCount);
+ const suffix = values.length > visible.length ? ` +${values.length - visible.length}` : '';
+ return { label: `${visible.join(', ')}${suffix}`, title: values.join(', ') };
+};
+
+const hostSummary = (resource: Resource): { label: string; title: string } =>
+ summarizeValues(compactList(resource.storage?.nodes ?? []), '-', 2);
+
+const consumerSummary = (resource: Resource): { label: string; title: string } => {
+ const consumers = resource.storage?.topConsumers?.map((consumer) => consumer.name) ?? [];
+ return summarizeValues(compactList(consumers), '-', 2);
+};
+
+const consumerCount = (resource: Resource): number => resource.storage?.consumerCount ?? 0;
+
+const capacityPercent = (resource: Resource): number | undefined => {
+ if (typeof resource.disk?.current === 'number' && Number.isFinite(resource.disk.current)) {
+ return resource.disk.current;
+ }
+ if (
+ typeof resource.disk?.used === 'number' &&
+ typeof resource.disk?.total === 'number' &&
+ resource.disk.total > 0
+ ) {
+ return (resource.disk.used / resource.disk.total) * 100;
+ }
+ return undefined;
+};
+
+const capacityLabel = (resource: Resource): string => {
+ if (typeof resource.disk?.used === 'number' && typeof resource.disk?.total === 'number') {
+ return `${formatBytes(resource.disk.used)} / ${formatBytes(resource.disk.total)}`;
+ }
+ const percent = capacityPercent(resource);
+ return percent === undefined ? '-' : formatPercent(percent);
+};
+
+const CapacityCell: Component<{ resource: Resource }> = (props) => {
+ const percent = () => capacityPercent(props.resource);
+ return (
+ <div class="min-w-0">
+ <div class="truncate text-base-content" title={capacityLabel(props.resource)}>
+ {capacityLabel(props.resource)}
+ </div>
+ <Show when={percent() !== undefined}>
+ <div class="mt-1 h-1.5 overflow-hidden rounded bg-surface-alt">
+ <div
+ class="h-full rounded bg-emerald-500"
+ style={{ width: `${Math.max(0, Math.min(100, percent() ?? 0))}%` }}
+ />
+ </div>
+ </Show>
+ </div>
+ );
+};
+
+const statusLabel = (resource: Resource): string => {
+ switch (mapVmwareDatastoreStatus(resource)) {
+ case 'accessible':
+ return 'Accessible';
+ case 'attention':
+ return 'Attention';
+ case 'inaccessible':
+ return 'Inaccessible';
+ case 'maintenance':
+ return 'Maintenance';
+ case 'unknown':
+ return 'Unknown';
+ }
+};
+
+const statusPillClass = (resource: Resource): string => {
+ switch (mapVmwareDatastoreStatus(resource)) {
+ case 'accessible':
+ return 'border-emerald-300/50 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300';
+ case 'attention':
+ case 'maintenance':
+ return 'border-amber-300/50 bg-amber-500/10 text-amber-700 dark:text-amber-300';
+ case 'inaccessible':
+ return 'border-red-300/50 bg-red-500/10 text-red-700 dark:text-red-300';
+ case 'unknown':
+ return 'border-border bg-surface-alt text-muted';
+ }
+};
+
+const StatusPill: Component<{ resource: Resource }> = (props) => (
+ <span
+ class={`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-medium ${statusPillClass(
+ props.resource,
+ )}`}
+ >
+ {statusLabel(props.resource)}
+ </span>
+);
+
+export const VsphereDatastoresTable: Component<{
+ datastores: Resource[];
+ scope: Resource[];
+ emptyIcon: JSX.Element;
+ emptyTitle: string;
+ emptyDescription: string;
+ showToolbar?: boolean;
+}> = (props) => {
+ const tableState = createPlatformTableFilterState({
+ resources: () => props.datastores,
+ initialStatus: 'all' as VmwareDatastoreStatusFilter,
+ filter: filterVmwareDatastores,
+ });
+ const drawer = createPlatformResourceDetailState({ idPrefix: 'vsphere-datastore-drawer' });
+ const resolveResourceLabel = createPlatformResourceLabelResolver(() => props.scope);
+
+ return (
+ <Show
+ when={props.datastores.length > 0}
+ fallback={
+ <PlatformTableEmptyState
+ icon={props.emptyIcon}
+ title={props.emptyTitle}
+ description={props.emptyDescription}
+ />
+ }
+ >
+ <div class="space-y-3">
+ <Show when={props.showToolbar !== false}>
+ <PlatformTableToolbar
+ search={tableState.search}
+ onSearchChange={tableState.setSearch}
+ searchPlaceholder="Search vSphere datastores"
+ status={tableState.status()}
+ onStatusChange={tableState.setStatus}
+ statusOptions={VSPHERE_DATASTORE_STATUS_OPTIONS}
+ visible={tableState.visible()}
+ total={tableState.total()}
+ rowNoun="datastores"
+ />
+ </Show>
+
+ <Show
+ when={tableState.filtered().length > 0}
+ fallback={
+ <PlatformTableEmptyState
+ icon={props.emptyIcon}
+ title="No datastores match current filters"
+ description="Adjust the search or status filter to see more vSphere datastores."
+ />
+ }
+ >
+ <TableCard class={PLATFORM_TABLE_CARD_CLASS}>
+ <TableCardHeader title="Datastores" />
+ <Table class="min-w-full table-fixed text-xs md:min-w-[1080px]">
+ <TableHeader>
+ <TableRow class={PLATFORM_TABLE_HEADER_ROW_CLASS}>
+ <TableHead class={`${getPlatformTableHeadClassForKind('name')} md:w-[21%]`}>
+ Datastore
+ </TableHead>
+ <TableHead class={`${getPlatformTableHeadClassForKind('text')} md:w-[9%]`}>
+ Type
+ </TableHead>
+ <TableHead class={`${getPlatformTableHeadClassForKind('metric-bar')} md:w-[18%]`}>
+ Capacity
+ </TableHead>
+ <TableHead
+ class={`${getPlatformTableHeadClassForKind('text')} hidden md:table-cell md:w-[14%]`}
+ >
+ Hosts
+ </TableHead>
+ <TableHead
+ class={`${getPlatformTableHeadClassForKind('numeric-value')} hidden md:table-cell md:w-[7%]`}
+ >
+ VMs
+ </TableHead>
+ <TableHead
+ class={`${getPlatformTableHeadClassForKind('text')} hidden lg:table-cell md:w-[13%]`}
+ >
+ Consumers
+ </TableHead>
+ <TableHead
+ class={`${getPlatformTableHeadClassForKind('text')} hidden md:table-cell md:w-[10%]`}
+ >
+ Datacenter
+ </TableHead>
+ <TableHead class={`${getPlatformTableHeadClassForKind('badge')} md:w-[8%]`}>
+ State
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody class={PLATFORM_TABLE_BODY_CLASS}>
+ <For each={tableState.filtered()}>
+ {(datastore) => {
+ const hosts = createMemo(() => hostSummary(datastore));
+ const consumers = createMemo(() => consumerSummary(datastore));
+ const indicator = () => getSimpleStatusIndicator(datastore.status);
+ const name = () => datastoreName(datastore);
+ const datacenter = () =>
+ asTrimmedString(datastore.vmware?.datacenterName) || '-';
+ const detailRowId = () => drawer.detailRowId(datastore);
+ const isExpanded = () => drawer.isExpanded(datastore);
+ return (
+ <>
+ <TableRow
+ class={`${getPlatformResourceDetailRowClass(isExpanded())} text-[11px] sm:text-xs`}
+ aria-controls={isExpanded() ? detailRowId() : undefined}
+ aria-expanded={isExpanded() ? 'true' : 'false'}
+ data-vsphere-datastore-row={datastore.id}
+ onClick={() => drawer.toggle(datastore)}
+ onKeyDown={drawer.handleActivationKey(datastore)}
+ tabIndex={0}
+ >
+ <TableCell class={getPlatformTableCellClassForKind('name')}>
+ <div class="flex min-w-0 items-center gap-2">
+ <StatusDot
+ size="sm"
+ variant={indicator().variant}
+ title={indicator().label}
+ />
+ <div class="min-w-0">
+ <div class="truncate font-medium text-base-content" title={name()}>
+ {name()}
+ </div>
+ <div
+ class="truncate text-[10px] text-muted"
+ title={datastore.vmware?.datastoreUrl}
+ >
+ {datastore.vmware?.datastoreUrl ||
+ datastore.vmware?.folderName ||
+ datastore.vmware?.vcenterHost ||
+ 'vSphere datastore'}
+ </div>
+ </div>
+ </div>
+ </TableCell>
+ <TableCell class={getPlatformTableCellClassForKind('text')}>
+ <span class="font-mono text-[11px] text-base-content">
+ {datastoreType(datastore)}
+ </span>
+ </TableCell>
+ <TableCell class={getPlatformTableCellClassForKind('metric-bar')}>
+ <CapacityCell resource={datastore} />
+ </TableCell>
+ <TableCell
+ class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content md:table-cell`}
+ title={hosts().title}
+ >
+ <span class="block truncate">{hosts().label}</span>
+ </TableCell>
+ <TableCell
+ class={`${getPlatformTableCellClassForKind('numeric-value')} hidden text-base-content tabular-nums md:table-cell`}
+ >
+ {consumerCount(datastore)}
+ </TableCell>
+ <TableCell
+ class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content lg:table-cell`}
+ title={consumers().title}
+ >
+ <span class="block truncate">{consumers().label}</span>
+ </TableCell>
+ <TableCell
+ class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content md:table-cell`}
+ title={datacenter()}
+ >
+ <span class="block truncate">{datacenter()}</span>
+ </TableCell>
+ <TableCell class={getPlatformTableCellClassForKind('badge')}>
+ <StatusPill resource={datastore} />
+ </TableCell>
+ </TableRow>
+ <PlatformResourceDetailTableRow
+ resource={datastore}
+ open={isExpanded()}
+ detailRowId={detailRowId()}
+ colSpan={8}
+ resolveResourceLabel={resolveResourceLabel}
+ onClose={() => drawer.close(datastore)}
+ />
+ </>
+ );
+ }}
+ </For>
+ </TableBody>
+ </Table>
+ </TableCard>
+ </Show>
+ </div>
+ </Show>
+ );
+};
+
+export default VsphereDatastoresTable;
diff --git a/frontend-modern/src/features/vmware/__tests__/VsphereDatastoresTable.test.tsx b/frontend-modern/src/features/vmware/__tests__/VsphereDatastoresTable.test.tsx
new file mode 100644
index 0000000000..fd68d343d5
--- /dev/null
+++ b/frontend-modern/src/features/vmware/__tests__/VsphereDatastoresTable.test.tsx
@@ -0,0 +1,90 @@
+import { cleanup, fireEvent, render, screen, within } from '@solidjs/testing-library';
+import { afterEach, describe, expect, it } from 'vitest';
+
+import { VsphereDatastoresTable } from '@/features/vmware/VsphereDatastoresTable';
+import type { Resource } from '@/types/resource';
+
+const makeDatastore = (overrides: Partial<Resource> & Pick<Resource, 'id'>): Resource =>
+ ({
+ type: 'storage',
+ name: overrides.id,
+ displayName: overrides.id,
+ status: 'online',
+ platformType: 'vmware-vsphere',
+ platformScopes: ['vmware-vsphere'],
+ sourceType: 'api',
+ disk: { current: 50, used: 5_000_000_000_000, total: 10_000_000_000_000 },
+ storage: {
+ topology: 'datastore',
+ platform: 'vmware-vsphere',
+ type: 'vmfs',
+ nodes: ['esxi-01.lab.local', 'esxi-02.lab.local'],
+ consumerCount: 2,
+ topConsumers: [
+ { resourceType: 'vm', name: 'warehouse-api-01' },
+ { resourceType: 'vm', name: 'etl-batch-01' },
+ ],
+ },
+ vmware: {
+ entityType: 'datastore',
+ datastoreAccessible: true,
+ datastoreType: 'VMFS',
+ datacenterName: 'Primary DC',
+ datastoreUrl: 'ds:///vmfs/volumes/nvme-primary/',
+ vcenterHost: 'vcsa.lab.local',
+ },
+ ...overrides,
+ }) as Resource;
+
+afterEach(() => {
+ cleanup();
+});
+
+describe('VsphereDatastoresTable', () => {
+ it('renders vCenter datastore fields without generic storage protection columns', async () => {
+ const nvme = makeDatastore({ id: 'nvme-primary', name: 'nvme-primary' });
+ const inaccessible = makeDatastore({
+ id: 'edge-cold-iscsi',
+ name: 'edge-cold-iscsi',
+ status: 'offline',
+ vmware: {
+ entityType: 'datastore',
+ datastoreAccessible: false,
+ datastoreType: 'VMFS',
+ datacenterName: 'Edge DC',
+ datastoreUrl: 'ds:///vmfs/volumes/edge-cold-iscsi/',
+ },
+ });
+
+ render(() => (
+ <VsphereDatastoresTable
+ datastores={[nvme, inaccessible]}
+ scope={[nvme, inaccessible]}
+ emptyIcon={<span />}
+ emptyTitle="No datastores"
+ emptyDescription="No datastores"
+ showToolbar={false}
+ />
+ ));
+
+ const table = screen.getByRole('table');
+ expect(within(table).getByText('Datastore')).toBeInTheDocument();
+ expect(within(table).getByText('Type')).toBeInTheDocument();
+ expect(within(table).getByText('Capacity')).toBeInTheDocument();
+ expect(within(table).getByText('Hosts')).toBeInTheDocument();
+ expect(within(table).getByText('VMs')).toBeInTheDocument();
+ expect(within(table).queryByText('Protection')).not.toBeInTheDocument();
+ expect(within(table).queryByText('Growth (24h)')).not.toBeInTheDocument();
+ expect(screen.getAllByText('esxi-01.lab.local, esxi-02.lab.local')).toHaveLength(2);
+ expect(screen.getAllByText('warehouse-api-01, etl-batch-01')).toHaveLength(2);
+ expect(screen.getByText('Accessible')).toBeInTheDocument();
+ expect(screen.getByText('Inaccessible')).toBeInTheDocument();
+
+ const row = screen.getByText('nvme-primary').closest('tr');
+ expect(row).toHaveAttribute('aria-expanded', 'false');
+
+ await fireEvent.click(row!);
+
+ expect(row).toHaveAttribute('aria-expanded', 'true');
+ });
+});
diff --git a/frontend-modern/src/features/vmware/__tests__/vmwarePageModel.test.ts b/frontend-modern/src/features/vmware/__tests__/vmwarePageModel.test.ts
index 10547761b0..3145906175 100644
--- a/frontend-modern/src/features/vmware/__tests__/vmwarePageModel.test.ts
+++ b/frontend-modern/src/features/vmware/__tests__/vmwarePageModel.test.ts
@@ -1,6 +1,11 @@
import { describe, expect, it } from 'vitest';
import type { Resource } from '@/types/resource';
-import { VMWARE_TAB_SPECS, buildVmwarePageModel } from '../vmwarePageModel';
+import {
+ VMWARE_TAB_SPECS,
+ buildVmwarePageModel,
+ filterVmwareDatastores,
+ mapVmwareDatastoreStatus,
+} from '../vmwarePageModel';
const makeResource = (resource: Partial<Resource> & Pick<Resource, 'id' | 'type'>): Resource => ({
name: resource.id,
@@ -16,20 +21,91 @@ const makeResource = (resource: Partial<Resource> & Pick<Resource, 'id' | 'type'
describe('vmwarePageModel', () => {
it('declares the vSphere section set', () => {
expect(VMWARE_TAB_SPECS.map((tab) => tab.id)).toEqual(['overview', 'storage']);
+ expect(VMWARE_TAB_SPECS.map((tab) => tab.label)).toEqual(['Overview', 'Datastores']);
});
- it('buckets vSphere hosts and VMs and ignores non-vSphere resources', () => {
+ it('buckets canonical vSphere hosts, VMs, and datastores', () => {
const model = buildVmwarePageModel([
makeResource({ id: 'esxi-host-1', type: 'agent' }),
makeResource({ id: 'vsphere-vm-1', type: 'vm' }),
- makeResource({ id: 'datastore-1', type: 'datastore' }),
+ makeResource({
+ id: 'datastore-1',
+ type: 'storage',
+ storage: { topology: 'datastore', platform: 'vmware-vsphere' },
+ vmware: { entityType: 'datastore' },
+ }),
+ makeResource({ id: 'legacy-provider-datastore', type: 'datastore' }),
makeResource({ id: 'pve-vm', type: 'vm', platformType: 'proxmox-pve' }),
]);
expect(model.hosts.map((r) => r.id)).toEqual(['esxi-host-1']);
expect(model.vms.map((r) => r.id)).toEqual(['vsphere-vm-1']);
+ expect(model.datastores.map((r) => r.id)).toEqual(['datastore-1']);
expect(model.resources.map((r) => r.id).sort()).toEqual(
['datastore-1', 'esxi-host-1', 'vsphere-vm-1'].sort(),
);
});
+
+ it('filters vSphere datastores using vCenter datastore metadata', () => {
+ const accessible = makeResource({
+ id: 'ds-accessible',
+ type: 'storage',
+ name: 'nvme-primary',
+ storage: {
+ topology: 'datastore',
+ platform: 'vmware-vsphere',
+ type: 'vmfs',
+ nodes: ['esxi-01.lab.local'],
+ consumerCount: 2,
+ topConsumers: [{ resourceType: 'vm', name: 'warehouse-api-01' }],
+ },
+ vmware: {
+ entityType: 'datastore',
+ datastoreAccessible: true,
+ datastoreType: 'VMFS',
+ datacenterName: 'Primary DC',
+ },
+ });
+ const inaccessible = makeResource({
+ id: 'ds-inaccessible',
+ type: 'storage',
+ name: 'edge-cold-iscsi',
+ status: 'offline',
+ storage: { topology: 'datastore', platform: 'vmware-vsphere', nodes: ['esxi-06.lab.local'] },
+ vmware: {
+ entityType: 'datastore',
+ datastoreAccessible: false,
+ datastoreType: 'VMFS',
+ datacenterName: 'Edge DC',
+ },
+ });
+ const maintenance = makeResource({
+ id: 'ds-maintenance',
+ type: 'storage',
+ name: 'maintenance-nfs',
+ storage: { topology: 'datastore', platform: 'vmware-vsphere', nodes: ['esxi-07.lab.local'] },
+ vmware: {
+ entityType: 'datastore',
+ datastoreAccessible: true,
+ datastoreType: 'NFS41',
+ maintenanceMode: 'IN_MAINTENANCE',
+ },
+ });
+
+ expect(mapVmwareDatastoreStatus(accessible)).toBe('accessible');
+ expect(mapVmwareDatastoreStatus(inaccessible)).toBe('inaccessible');
+ expect(mapVmwareDatastoreStatus(maintenance)).toBe('maintenance');
+ expect(
+ filterVmwareDatastores(
+ [accessible, inaccessible, maintenance],
+ 'warehouse',
+ 'accessible',
+ ).map((resource) => resource.id),
+ ).toEqual(['ds-accessible']);
+ expect(
+ filterVmwareDatastores([accessible, inaccessible, maintenance], 'esxi-06', 'all').map(
+ (resource) => resource.id,
+ ),
+ ).toEqual(['ds-inaccessible']);
+ });
});
diff --git a/frontend-modern/src/features/vmware/vmwarePageModel.ts b/frontend-modern/src/features/vmware/vmwarePageModel.ts
index 38275b44ed..241f21e7ba 100644
--- a/frontend-modern/src/features/vmware/vmwarePageModel.ts
+++ b/frontend-modern/src/features/vmware/vmwarePageModel.ts
@@ -2,6 +2,13 @@ import { resolveResourcePlatformType } from '@/utils/sourcePlatforms';
import type { Resource, ResourceType } from '@/types/resource';
export type VmwarePageTabId = 'overview' | 'storage';
+export type VmwareDatastoreStatusFilter =
+ | 'all'
+ | 'accessible'
+ | 'attention'
+ | 'inaccessible'
+ | 'maintenance'
+ | 'unknown';
export type VmwareTabSpec = {
id: VmwarePageTabId;
@@ -15,15 +22,10 @@ export type VmwareTabSpec = {
// filter inside Overview owns search/grouping for VMs.
export const VMWARE_TAB_SPECS: readonly VmwareTabSpec[] = [
{ id: 'overview', label: 'Overview', path: '/vmware/overview' },
- { id: 'storage', label: 'Storage', path: '/vmware/storage' },
+ { id: 'storage', label: 'Datastores', path: '/vmware/storage' },
] as const;
-const VMWARE_RESOURCE_TYPES = new Set<ResourceType>([
- 'agent',
- 'vm',
- 'storage',
- 'datastore',
-]);
+const VMWARE_RESOURCE_TYPES = new Set<ResourceType>(['agent', 'vm', 'storage']);
const isVmwarePlatform = (resource: Resource): boolean =>
resolveResourcePlatformType(resource) === 'vmware-vsphere';
@@ -41,11 +43,13 @@ export function buildVmwarePageModel(resources: Resource[]): VmwarePageModel {
);
const hosts = vmwareResources.filter((resource) => resource.type === 'agent');
const vms = vmwareResources.filter((resource) => resource.type === 'vm');
- const datastores = vmwareResources.filter(
- (resource) =>
- resource.type === 'storage' &&
- (resource.storage?.topology === 'datastore' || resource.vmware?.entityType === 'datastore'),
- );
+ const datastores = vmwareResources
+ .filter(
+ (resource) =>
+ resource.type === 'storage' &&
+ (resource.storage?.topology === 'datastore' || resource.vmware?.entityType === 'datastore'),
+ )
+ .sort(compareVmwareDatastores);
return {
resources: vmwareResources,
@@ -54,3 +58,99 @@ export function buildVmwarePageModel(resources: Resource[]): VmwarePageModel {
datastores,
};
}
+
+const normalize = (value: unknown): string =>
+ typeof value === 'string' ? value.trim().toLowerCase() : '';
+
+const vmwareDatastoreDisplayName = (resource: Resource): string =>
+ resource.displayName?.trim() || resource.name?.trim() || resource.id;
+
+const vmwareDatastoreStatusRank = (resource: Resource): number => {
+ switch (mapVmwareDatastoreStatus(resource)) {
+ case 'inaccessible':
+ return 0;
+ case 'maintenance':
+ return 1;
+ case 'attention':
+ return 2;
+ case 'unknown':
+ return 3;
+ case 'accessible':
+ return 4;
+ }
+};
+
+const compareVmwareDatastores = (left: Resource, right: Resource): number => {
+ const rankDelta = vmwareDatastoreStatusRank(left) - vmwareDatastoreStatusRank(right);
+ if (rankDelta !== 0) return rankDelta;
+ return vmwareDatastoreDisplayName(left).localeCompare(vmwareDatastoreDisplayName(right));
+};
+
+export function mapVmwareDatastoreStatus(
+ resource: Resource,
+): Exclude<VmwareDatastoreStatusFilter, 'all'> {
+ const maintenanceMode = normalize(resource.vmware?.maintenanceMode);
+ const status = normalize(resource.status);
+ const overall = normalize(resource.vmware?.overallStatus);
+
+ if (
+ maintenanceMode &&
+ maintenanceMode !== 'normal' &&
+ maintenanceMode !== 'none' &&
+ maintenanceMode !== 'not_in_maintenance'
+ ) {
+ return 'maintenance';
+ }
+ if (resource.vmware?.datastoreAccessible === false || status === 'offline') {
+ return 'inaccessible';
+ }
+ if (['red', 'yellow', 'degraded', 'warning', 'critical', 'paused'].includes(overall)) {
+ return 'attention';
+ }
+ if (['degraded', 'warning', 'critical', 'paused'].includes(status)) return 'attention';
+ if (resource.vmware?.datastoreAccessible === true || ['online', 'running'].includes(status)) {
+ return 'accessible';
+ }
+ return 'unknown';
+}
+
+const vmwareDatastoreSearchHaystack = (resource: Resource): string =>
+ [
+ resource.id,
+ resource.name,
+ resource.displayName,
+ resource.parentName,
+ resource.status,
+ resource.vmware?.connectionName,
+ resource.vmware?.vcenterHost,
+ resource.vmware?.managedObjectId,
+ resource.vmware?.datacenterName,
+ resource.vmware?.folderName,
+ resource.vmware?.datastoreType,
+ resource.vmware?.datastoreUrl,
+ resource.vmware?.maintenanceMode,
+ resource.vmware?.overallStatus,
+ resource.storage?.type,
+ resource.storage?.topology,
+ resource.storage?.platform,
+ resource.storage?.nodes?.join(' '),
+ resource.storage?.consumerTypes?.join(' '),
+ resource.storage?.topConsumers?.map((consumer) => consumer.name).join(' '),
+ ...(resource.tags ?? []),
+ ]
+ .filter((value): value is string => typeof value === 'string' && value.trim().length > 0)
+ .join(' ')
+ .toLowerCase();
+
+export function filterVmwareDatastores(
+ datastores: Resource[],
+ search: string,
+ status: VmwareDatastoreStatusFilter,
+): Resource[] {
+ const needle = normalize(search);
+ return datastores.filter((datastore) => {
+ if (status !== 'all' && mapVmwareDatastoreStatus(datastore) !== status) return false;
+ if (!needle) return true;
+ return vmwareDatastoreSearchHaystack(datastore).includes(needle);
+ });
+}
diff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.go
index 1565df017c..78aecd2e19 100644
--- a/internal/unifiedresources/registry_test.go
+++ b/internal/unifiedresources/registry_test.go
@@ -603,6 +603,60 @@ func TestResourceRegistry_IngestsVMwareSourceAsCanonicalResources(t *testing.T)
}
}
+func TestResourceRegistry_PreservesVMwareSourceOwnedDatastoreConsumers(t *testing.T) {
+ rr := NewRegistry(nil)
+ now := time.Date(2026, 3, 30, 18, 45, 0, 0, time.UTC)
+
+ rr.IngestRecords(SourceVMware, []IngestRecord{
+ {
+ SourceID: "vc-1:datastore:datastore-201",
+ Resource: Resource{
+ Type: ResourceTypeStorage,
+ Name: "nvme-primary",
+ Status: StatusOnline,
+ LastSeen: now,
+ Storage: &StorageMeta{
+ Type: "vmfs",
+ Platform: "vmware-vsphere",
+ Topology: "datastore",
+ ConsumerCount: 2,
+ ConsumerTypes: []string{string(ResourceTypeVM)},
+ TopConsumers: []StorageConsumerMeta{
+ {ResourceType: ResourceTypeVM, Name: "warehouse-api-01"},
+ {ResourceType: ResourceTypeVM, Name: "etl-batch-01"},
+ },
+ },
+ VMware: &VMwareData{
+ ConnectionID: "vc-1",
+ ManagedObjectID: "datastore-201",
+ EntityType: "datastore",
+ },
+ },
+ },
+ })
+
+ datastores := rr.ListByType(ResourceTypeStorage)
+ if len(datastores) != 1 {
+ t.Fatalf("expected 1 VMware datastore, got %d", len(datastores))
+ }
+ datastore := datastores[0]
+ if datastore.Storage == nil {
+ t.Fatalf("expected VMware datastore storage metadata, got %+v", datastore)
+ }
+ if got := datastore.Storage.ConsumerCount; got != 2 {
+ t.Fatalf("consumer count = %d, want 2", got)
+ }
+ if got := datastore.Storage.ConsumerTypes; len(got) != 1 || got[0] != string(ResourceTypeVM) {
+ t.Fatalf("consumer types = %#v, want [vm]", got)
+ }
+ if len(datastore.Storage.TopConsumers) != 2 {
+ t.Fatalf("top consumers = %#v, want 2 VMware VM consumers", datastore.Storage.TopConsumers)
+ }
+ if datastore.Storage.TopConsumers[0].Name != "warehouse-api-01" {
+ t.Fatalf("first top consumer = %#v, want warehouse-api-01", datastore.Storage.TopConsumers[0])
+ }
+}
+
func TestBuildMetricsTargetForRegistryFallsBackToStoredMetricsTarget(t *testing.T) {
rr := NewRegistry(nil)
now := time.Date(2026, 3, 31, 10, 0, 0, 0, time.UTC)
diff --git a/internal/unifiedresources/storage_consumers.go b/internal/unifiedresources/storage_consumers.go
index 32a0a643f6..3623033173 100644
--- a/internal/unifiedresources/storage_consumers.go
+++ b/internal/unifiedresources/storage_consumers.go
@@ -28,6 +28,12 @@ type storageConsumerSummary struct {
DiskCount int
}
+type sourceOwnedStorageConsumers struct {
+ ConsumerCount int
+ ConsumerTypes []string
+ TopConsumers []StorageConsumerMeta
+}
+
type pbsDatastoreIndexKey struct {
instance string
name string
@@ -39,6 +45,7 @@ type pbsBackupWorkloadIndex struct {
}
func (rr *ResourceRegistry) refreshStorageConsumersLocked() {
+ sourceOwned := preserveSourceOwnedStorageConsumers(rr.resources)
for _, resource := range rr.resources {
if resource.Storage == nil {
continue
@@ -57,6 +64,40 @@ func (rr *ResourceRegistry) refreshStorageConsumersLocked() {
addPBSStorageConsumers(consumersByStorage, rr.resources, rr.pbsBackups)
applyStorageConsumers(rr.resources, consumersByStorage)
+ applySourceOwnedStorageConsumers(rr.resources, sourceOwned)
+}
+
+func preserveSourceOwnedStorageConsumers(resources map[string]*Resource) map[string]sourceOwnedStorageConsumers {
+ preserved := make(map[string]sourceOwnedStorageConsumers)
+ for id, resource := range resources {
+ if resource == nil || resource.Storage == nil || !hasDataSource(resource.Sources, SourceVMware) {
+ continue
+ }
+ if resource.Storage.ConsumerCount <= 0 && len(resource.Storage.ConsumerTypes) == 0 && len(resource.Storage.TopConsumers) == 0 {
+ continue
+ }
+ preserved[id] = sourceOwnedStorageConsumers{
+ ConsumerCount: resource.Storage.ConsumerCount,
+ ConsumerTypes: cloneStringSlice(resource.Storage.ConsumerTypes),
+ TopConsumers: cloneStorageConsumerMetaSlice(resource.Storage.TopConsumers),
+ }
+ }
+ return preserved
+}
+
+func applySourceOwnedStorageConsumers(resources map[string]*Resource, preserved map[string]sourceOwnedStorageConsumers) {
+ for id, sourceOwned := range preserved {
+ resource := resources[id]
+ if resource == nil || resource.Storage == nil {
+ continue
+ }
+ if resource.Storage.ConsumerCount > 0 || len(resource.Storage.ConsumerTypes) > 0 || len(resource.Storage.TopConsumers) > 0 {
+ continue
+ }
+ resource.Storage.ConsumerCount = sourceOwned.ConsumerCount
+ resource.Storage.ConsumerTypes = cloneStringSlice(sourceOwned.ConsumerTypes)
+ resource.Storage.TopConsumers = cloneStorageConsumerMetaSlice(sourceOwned.TopConsumers)
+ }
}
func addProxmoxStorageConsumers(consumersByStorage map[string]map[string]*storageConsumerSummary, resources map[string]*Resource, index storageConsumerIndex) {