import {z} from 'zod' export type CommitmentTerm = 'COMMITMENT_TERM_NONE' | 'COMMITMENT_TERM_1_MONTH' | 'COMMITMENT_TERM_3_MONTHS' | 'COMMITMENT_TERM_6_MONTHS' | 'COMMITMENT_TERM_12_MONTHS' | 'COMMITMENT_TERM_24_MONTHS' | 'COMMITMENT_TERM_36_MONTHS' | 'COMMITMENT_TERM_60_MONTHS'; export type ClusterIPOIBConfig = {hostBits: number, networkPrefix: string, portBits: number}; export type Decimal = {value?: string | undefined}; export type MachinePowerState = 'MACHINE_POWER_STATE_UNSPECIFIED' | 'ON' | 'OFF' | 'POWERING_ON' | 'POWERING_OFF' | 'REBOOTING'; export type ClusterMachineState = 'STATE_UNSPECIFIED' | 'CREATING' | 'ACTIVE' | 'DELETING' | 'FAILED'; export type ClusterMachine = {architecture?: string | undefined, cpuCores?: number | undefined, cpuModel?: string | undefined, cpuSpeedMhz?: number | undefined, createBy?: string | undefined, createTime?: string | undefined, dataCenterId?: string | undefined, diskSizeGib?: number | undefined, disks?: number | undefined, externalIpAddress?: string | undefined, gpuModelId?: string | undefined, gpus?: number | undefined, id?: string | undefined, internalIpAddress?: string | undefined, machineTypeId?: string | undefined, memoryGib?: number | undefined, powerState?: MachinePowerState | undefined, priceHr?: Decimal | undefined, projectId?: string | undefined, state?: ClusterMachineState | undefined, volumeIds?: Array | undefined}; export type NetworkType = 'NETWORK_TYPE_UNSPECIFIED' | 'ETHERNET' | 'INFINIBAND'; export type SshKeySource = 'SSH_KEY_SOURCE_UNKNOWN' | 'SSH_KEY_SOURCE_PROJECT' | 'SSH_KEY_SOURCE_USER' | 'SSH_KEY_SOURCE_NONE'; export type ClusterState = 'STATE_UNSPECIFIED' | 'CREATING' | 'ACTIVE' | 'UPDATING' | 'DELETING' | 'FAILED'; export type PatchApiV1ProjectsProjectIdClustersIdArgs = {projectId: string, id: string, body: {architecture?: string | undefined, commitmentEndTime?: string | undefined, commitmentTerm?: CommitmentTerm | undefined, cpuModel?: string | undefined, cpuSpeedMhz?: number | undefined, createBy?: string | undefined, createTime?: string | undefined, customSshKeys?: Array | undefined, dataCenterId: string, gpuModelId?: string | undefined, ipoibConfig?: ClusterIPOIBConfig | undefined, machineCount: number, machinePriceHr?: Decimal | undefined, machineTypeId: string, machines?: Array | undefined, networkType?: NetworkType | undefined, sshKeySource?: SshKeySource | undefined, startScript?: string | undefined, state?: ClusterState | undefined, totalCpuCores?: number | undefined, totalDiskSizeGib?: number | undefined, totalGpus?: number | undefined, totalMachinePriceHr?: Decimal | undefined, totalMemoryGib?: number | undefined, totalPriceHr?: Decimal | undefined}}; export type PatchApiV1ProjectsProjectIdClustersIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const commitmentTerm = z.enum(["COMMITMENT_TERM_NONE", "COMMITMENT_TERM_1_MONTH", "COMMITMENT_TERM_3_MONTHS", "COMMITMENT_TERM_6_MONTHS", "COMMITMENT_TERM_12_MONTHS", "COMMITMENT_TERM_24_MONTHS", "COMMITMENT_TERM_36_MONTHS", "COMMITMENT_TERM_60_MONTHS"]); export const clusterIPOIBConfig = z.object({hostBits: z.number().int(), networkPrefix: z.string(), portBits: z.number().int()}); export const decimal = z.object({value: z.string().optional()}); export const machinePowerState = z.enum(["MACHINE_POWER_STATE_UNSPECIFIED", "ON", "OFF", "POWERING_ON", "POWERING_OFF", "REBOOTING"]); export const clusterMachineState = z.enum(["STATE_UNSPECIFIED", "CREATING", "ACTIVE", "DELETING", "FAILED"]); export const clusterMachine = z.object({architecture: z.string().optional(), cpuCores: z.number().int().optional(), cpuModel: z.string().optional(), cpuSpeedMhz: z.number().int().optional(), createBy: z.string().optional(), createTime: z.string().optional(), dataCenterId: z.string().optional(), diskSizeGib: z.number().int().optional(), disks: z.number().int().optional(), externalIpAddress: z.string().optional(), gpuModelId: z.string().optional(), gpus: z.number().int().optional(), id: z.string().optional(), internalIpAddress: z.string().optional(), machineTypeId: z.string().optional(), memoryGib: z.number().int().optional(), powerState: machinePowerState.optional(), priceHr: decimal.optional(), projectId: z.string().optional(), state: clusterMachineState.optional(), volumeIds: z.array(z.string()).optional()}); export const networkType = z.enum(["NETWORK_TYPE_UNSPECIFIED", "ETHERNET", "INFINIBAND"]); export const sshKeySource = z.enum(["SSH_KEY_SOURCE_UNKNOWN", "SSH_KEY_SOURCE_PROJECT", "SSH_KEY_SOURCE_USER", "SSH_KEY_SOURCE_NONE"]); export const clusterState = z.enum(["STATE_UNSPECIFIED", "CREATING", "ACTIVE", "UPDATING", "DELETING", "FAILED"]); export const cluster = z.object({architecture: z.string().optional(), commitmentEndTime: z.string().optional(), commitmentTerm: commitmentTerm.optional(), cpuModel: z.string().optional(), cpuSpeedMhz: z.number().int().optional(), createBy: z.string().optional(), createTime: z.string().optional(), customSshKeys: z.array(z.string()).optional(), dataCenterId: z.string(), gpuModelId: z.string().optional(), id: z.string(), ipoibConfig: clusterIPOIBConfig.optional(), machineCount: z.number().int(), machinePriceHr: decimal.optional(), machineTypeId: z.string(), machines: z.array(clusterMachine).optional(), networkType: networkType.optional(), projectId: z.string(), sshKeySource: sshKeySource.optional(), startScript: z.string().optional(), state: clusterState.optional(), totalCpuCores: z.number().int().optional(), totalDiskSizeGib: z.number().int().optional(), totalGpus: z.number().int().optional(), totalMachinePriceHr: decimal.optional(), totalMemoryGib: z.number().int().optional(), totalPriceHr: decimal.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update a cluster * * PATCH /v1/projects/{projectId}/clusters/{id} */ export const patchApiV1ProjectsProjectIdClustersId = async (args: PatchApiV1ProjectsProjectIdClustersIdArgs, options?: PatchApiV1ProjectsProjectIdClustersIdOptions) => { const {baseUrl = "https://rest.compute.cudo.org", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set("Authorization", bearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectId))}/clusters/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(cluster, await res.json()) };