Files
gpustack-ui/src/pages/gpu-service/instances/utils/instance-description.ts
T
jialin fe4dbf087f feat(gpu-service): align instance-type/flavor contract with status.detail API
- spec keeps definition fields only; observed hardware read from status.detail
- sliceable derived from slicedDetail (logical count / physical profiles)
- flat snapshot format isolated in instance-description for back-compat
- drop flavor.spec.sliceable; onceMaxRequest realigned (no ram/localStorage)
- lock compute ratio to memory ratio when coresPercentageOvercommit is false
- sliced mode submits whole cores / Gi; displayName-first type labels
2026-07-22 15:52:17 +08:00

36 lines
1.5 KiB
TypeScript

import _ from 'lodash';
import { isSliceableDetail } from '../config';
import { InstanceTypeItem, InstanceTypeSnapshotSpec } from '../config/types';
// Build the flat snapshot spec from a live (API-shaped) instance type:
// definition fields from spec, observed hardware from status.detail, plus the
// derived `sliceable`. This flat shape is the UI document format persisted in
// the instance's `description` (older instances already carry it flat) and
// doubles as the display model of the type card / metadata section.
export const buildInstanceTypeSnapshotSpec = (
instanceType: InstanceTypeItem
): InstanceTypeSnapshotSpec => {
const detail = instanceType.status?.detail;
return {
...instanceType.spec,
..._.pick(detail, ['manufacturer', 'product', 'family', 'memory']),
sliceable: isSliceableDetail(detail?.slicedDetail),
// Accelerator CPU identity only — the full CPU descriptor is too bulky to
// persist and the UI only shows who made it.
cpu: _.pick(detail?.cpu, ['manufacturer', 'product', 'family'])
};
};
// Serialize the chosen instance type into the instance's `description` field —
// a persisted spec snapshot the form reads back to render the type card and
// derive unit resources. Shared by the create/recreate flow (card selection)
// and the edit flow (change-type overlay).
export const saveInstanceDataInDescription = (
instanceType: InstanceTypeItem
): string => {
return JSON.stringify({
name: instanceType.name,
spec: buildInstanceTypeSnapshotSpec(instanceType)
});
};