import {z} from 'zod' export type GetApiV1ProjectsProjectIdClustersIdArgs = {projectId: string, id: string}; export type GetApiV1ProjectsProjectIdClustersIdOptions = {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 }; /** * Get a cluster * * GET /v1/projects/{projectId}/clusters/{id} */ export const getApiV1ProjectsProjectIdClustersId = async (args: GetApiV1ProjectsProjectIdClustersIdArgs, options?: GetApiV1ProjectsProjectIdClustersIdOptions) => { const {baseUrl = "https://rest.compute.cudo.org", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "GET", headers}) 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()) };