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/frontend/compute/nested-virtualization.tsx
Views: 687
1
import { Alert, Checkbox, Switch } from "antd";
2
import { useState } from "react";
3
import { A, Icon } from "@cocalc/frontend/components";
4
5
export default function NestedVirtualization({
6
setConfig,
7
configuration,
8
loading,
9
}) {
10
const [enableNestedVirtualization, setEnableNestedVirtualization] =
11
useState<boolean>(!!configuration.enableNestedVirtualization);
12
const [help, setHelp] = useState<boolean>(false);
13
14
return (
15
<div>
16
<div style={{ color: "#666", marginBottom: "5px" }}>
17
<div>
18
<b>
19
<Switch
20
size="small"
21
checkedChildren={"Help"}
22
unCheckedChildren={"Help"}
23
style={{ float: "right" }}
24
checked={help}
25
onChange={(val) => setHelp(val)}
26
/>
27
<Icon name="users" /> Enable Nested Virtualization
28
</b>
29
</div>
30
{help && (
31
<Alert
32
showIcon
33
style={{ margin: "15px 0" }}
34
type="info"
35
message={"Enable Nested Virtualization"}
36
description={
37
<div>
38
<ul>
39
<li>
40
Enable this option to run full VM's inside of this compute
41
server.
42
</li>
43
<li>
44
There is roughly{" "}
45
<A href="https://cloud.google.com/compute/docs/instances/nested-virtualization/overview">
46
a 10% performance penalty
47
</A>
48
.
49
</li>
50
<li>
51
One way to run a VM is to ssh into the compute server as
52
root, install <A href="https://multipass.run/">Multipass</A>{" "}
53
by typing <code>snap install multipass</code> then use any
54
multipass command, e.g., <code>multipass launch</code>.
55
</li>
56
<li>
57
Nested virtualization is only supported for Intel processes
58
on non-E2 general-purpose, or A3 accelerator-optimized
59
servers.{" "}
60
<b>
61
The currently selected machine type is{" "}
62
{isSupported(configuration) ? "" : " NOT "} supported.
63
</b>
64
</li>
65
<li>
66
NOTE: All compute servers fully support running Docker
67
containers without this option. This is for running full
68
virtual machines.
69
</li>
70
</ul>
71
</div>
72
}
73
/>
74
)}
75
<Checkbox
76
style={{ marginTop: "5px" }}
77
disabled={loading || !isSupported(configuration)}
78
checked={enableNestedVirtualization && isSupported(configuration)}
79
onChange={() => {
80
setConfig({
81
enableNestedVirtualization: !enableNestedVirtualization,
82
});
83
setEnableNestedVirtualization(!enableNestedVirtualization);
84
}}
85
>
86
Enable Nested Virtualization: make it possible to run full VM's inside
87
of this compute server
88
</Checkbox>
89
</div>
90
</div>
91
);
92
}
93
94
function isSupported(configuration) {
95
const { machineType } = configuration;
96
if (!machineType) {
97
return false;
98
}
99
if (machineType.startsWith("a3")) {
100
return false;
101
}
102
if (machineType.startsWith("e2")) {
103
return false;
104
}
105
const i = machineType.indexOf("-");
106
if (i == -1) {
107
return false;
108
}
109
const x = machineType[i - 1];
110
if (x == "a" || x == "d") {
111
return false;
112
}
113
return true;
114
}
115
116