CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/api/schema/compute/common.ts
Views: 688
1
import { z } from "../../framework";
2
3
export const ComputeServerIdSchema = z
4
.number()
5
.int()
6
.min(0)
7
.describe("Compute server id (or 0 for your home base)");
8
9
export const ComputeServerStateSchema = z
10
.enum([
11
"deprovisioned",
12
"off",
13
"running",
14
"starting",
15
"stopping",
16
"suspended",
17
"suspending",
18
"unknown",
19
])
20
.describe("The state of the compute server.");
21
22
export const ComputeServerColorSchema = z.string().describe(
23
`Compute server color in \`rgb(#,#,#)\` format. Used for color-coding compute servers in
24
the CoCalc UI.`,
25
);
26
27
export const ComputeServerTitleSchema = z.string().describe(
28
`Title of this compute server. Used purely to make it easier for the user to keep
29
track of it.`,
30
);
31
32
export const ComputeServerCloudSchema = z
33
.enum(["google-cloud", "hyperstack", "onprem"])
34
.describe("The cloud provider used to run this compute server");
35
36
export const ComputeServerImageProxySchema = z.object({
37
path: z.string(),
38
target: z.string(),
39
ws: z.boolean().optional(),
40
app: z.string().optional(),
41
name: z.string().optional(),
42
});
43
44
export const GoogleCloudServerConfigurationSchema = z.object({}).passthrough();
45
46
export const HyperstackServerConfigurationSchema = z.object({}).passthrough();
47
48
export const ServerConfigurationSchema = z.union([
49
GoogleCloudServerConfigurationSchema,
50
HyperstackServerConfigurationSchema,
51
]);
52
53
export const BaseServerConfigurationSchema = z.object({
54
cloud: ComputeServerCloudSchema,
55
dns: z.string().describe("DNS name"),
56
spot: z.boolean().describe("If true, provision a spot instance."),
57
zone: z
58
.string()
59
.describe("Cloud provider zone to which this template defaults."),
60
image: z.string().describe("Compute server template image name."),
61
region: z.string().describe("Compute server template region name."),
62
ephemeral: z
63
.boolean()
64
.describe("Indicates whether the compute server is ephemeral.")
65
.optional(),
66
diskType: z.string().describe("Compute server template disk type."),
67
diskSizeGb: z
68
.number()
69
.min(0)
70
.describe("Compute server template disk image size in GB."),
71
externalIp: z
72
.boolean()
73
.describe(
74
`When true, the compute server is configured with an external IP address.`,
75
),
76
tag_cocalc: z.string().describe("CoCalc tag"),
77
machineType: z
78
.string()
79
.describe(
80
"Cloud-specific machine type for this template (e.g., `t2d-standard-1`).",
81
),
82
excludeFromSync: z
83
.array(z.string())
84
.describe("Array of top level directories to exclude from sync."),
85
acceleratorType: z
86
.string()
87
.describe(
88
"Number of hardware accelerators to be provisioned to this server.",
89
)
90
.optional(),
91
acceleratorCount: z
92
.number()
93
.int()
94
.min(0)
95
.describe(
96
"Number of hardware accelerators to be provisioned with this server.",
97
)
98
.optional(),
99
proxy: ComputeServerImageProxySchema.optional(),
100
});
101
102
export type BaseServerConfiguration = z.infer<
103
typeof BaseServerConfigurationSchema
104
>;
105
export type ComputeServerBodyId = z.infer<typeof ComputeServerIdSchema>;
106
export type ComputeServerCloud = z.infer<typeof ComputeServerCloudSchema>;
107
export type ComputeServerColor = z.infer<typeof ComputeServerColorSchema>;
108
export type ComputeServerImageProxy = z.infer<
109
typeof ComputeServerImageProxySchema
110
>;
111
export type ComputeServerState = z.infer<typeof ComputeServerStateSchema>;
112
export type ComputeServerTitle = z.infer<typeof ComputeServerTitleSchema>;
113
export type GoogleCloudServerConfiguration = z.infer<
114
typeof GoogleCloudServerConfigurationSchema
115
>;
116
export type HyperstackServerConfiguration = z.infer<
117
typeof HyperstackServerConfigurationSchema
118
>;
119
export type ServerConfiguration = z.infer<typeof ServerConfigurationSchema>;
120
121