Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/compute/cloud/hyperstack/config.tsx
Views: 687
import type {1State,2HyperstackConfiguration,3ComputeServerTemplate,4} from "@cocalc/util/db-schema/compute-servers";5import { Divider, Spin, Table } from "antd";6import {7getHyperstackPriceData,8setServerConfiguration,9} from "@cocalc/frontend/compute/api";10import { useEffect, useState } from "react";11import ShowError from "@cocalc/frontend/components/error";12import Proxy from "@cocalc/frontend/compute/proxy";13import { useImages } from "@cocalc/frontend/compute/images-hook";14import type { HyperstackPriceData } from "@cocalc/util/compute/cloud/hyperstack/pricing";15import computeCost from "@cocalc/util/compute/cloud/hyperstack/compute-cost";16import { currency } from "@cocalc/util/misc";17import CostOverview from "@cocalc/frontend/compute/cost-overview";18import { Icon } from "@cocalc/frontend/components/icon";19//import GPU from "./gpu";20import MachineType from "./machine-type";21import Specs from "./specs";22import Image from "./image";23import Disk from "./disk";24import Ephemeral from "@cocalc/frontend/compute/ephemeral";25import ExcludeFromSync from "@cocalc/frontend/compute/exclude-from-sync";26import { useTypedRedux } from "@cocalc/frontend/app-framework";27import DNS from "@cocalc/frontend/compute/cloud/common/dns";28import AllowCollaboratorControl from "@cocalc/frontend/compute/allow-collaborator-control";29import Template from "@cocalc/frontend/compute/cloud/common/template";30import { A } from "@cocalc/frontend/components/A";3132interface Props {33configuration: HyperstackConfiguration;34editable?: boolean;35// if id not set, then doesn't try to save anything to the backend36id?: number;37project_id: string;38// called whenever changes are made.39onChange?: (configuration: HyperstackConfiguration) => void;40disabled?: boolean;41state?: State;42data?;43setCloud?;44template?: ComputeServerTemplate;45}4647export default function HyperstackConfig({48configuration: configuration0,49editable,50id,51project_id,52onChange,53disabled,54state,55data,56setCloud,57template,58}: Props) {59const [priceData, setPriceData] = useState<HyperstackPriceData | null>(null);60const [IMAGES, ImagesError] = useImages();61const [loading, setLoading] = useState<boolean>(false);62const [error, setError] = useState<string>("");63const [configuration, setLocalConfiguration] =64useState<HyperstackConfiguration>(configuration0);65const [cost, setCost] = useState<number | null>(null);66state = state ?? "deprovisioned";6768useEffect(() => {69(async () => {70try {71setLoading(true);72const data = await getHyperstackPriceData();73//window.x = { priceData: data };74setPriceData(data);75} catch (err) {76setError(`${err}`);77} finally {78setLoading(false);79}80})();81}, []);8283useEffect(() => {84if (!editable || configuration == null || priceData == null) {85return;86}87try {88const cost = computeCost({ configuration, priceData });89setCost(cost);90} catch (err) {91setError(`${err}`);92setCost(null);93}94}, [configuration, priceData]);9596useEffect(() => {97if (!editable) {98setLocalConfiguration(configuration0);99}100}, [configuration0]);101102if (!editable || !project_id) {103return (104<Specs105flavor_name={configuration.flavor_name}106region_name={configuration.region_name}107priceData={priceData}108diskSizeGb={configuration.diskSizeGb}109/>110);111}112113if (ImagesError != null) {114return ImagesError;115}116117const setConfig = async (changes) => {118try {119const newConfiguration = { ...configuration, ...changes };120setLoading(true);121if (onChange != null) {122onChange(newConfiguration);123}124setLocalConfiguration(newConfiguration);125if (id != null) {126await setServerConfiguration({ id, configuration: changes });127}128} catch (err) {129setError(`${err}`);130} finally {131setLoading(false);132}133};134135const columns = [136{137dataIndex: "value",138key: "value",139},140];141142const dataSource = [143// {144// key: "gpu",145146// value: (147// <GPU148// state={state}149// disabled={150// loading || disabled || (state != "deprovisioned" && state != "off")151// }152// priceData={priceData}153// setConfig={setConfig}154// configuration={configuration}155// />156// ),157// },158{159key: "machine",160value: (161<>162<div style={{ marginBottom: "5px" }}>163<b style={{ color: "#666" }}>Machine Type</b>164<br />165</div>166<MachineType167setConfig={setConfig}168setCloud={setCloud}169configuration={configuration}170state={state}171disabled={172loading ||173disabled ||174(state != "deprovisioned" && state != "off")175}176priceData={priceData}177/>178</>179),180},181// {182// key: "provisioning",183// value: <Provisioning />,184// },185{186key: "image",187value: (188<Image189state={state}190disabled={loading || disabled}191setConfig={setConfig}192configuration={configuration}193/>194),195},196{197key: "disk",198value: (199<Disk200id={id}201disabled={loading}202setConfig={setConfig}203configuration={configuration}204data={data}205priceData={priceData}206state={state}207IMAGES={IMAGES}208/>209),210},211{212key: "exclude",213value: (214<ExcludeFromSync215id={id}216disabled={loading}217setConfig={setConfig}218configuration={configuration}219state={state}220style={{ marginTop: "10px", color: "#666" }}221/>222),223},224{225key: "dns",226value: (227<div>228<Icon name="network" /> <b style={{ color: "#666" }}>Domain Name</b>229<DNS230setConfig={setConfig}231configuration={configuration}232loading={loading}233/>234</div>235),236},237{238key: "proxy",239value: (240<Proxy241id={id}242project_id={project_id}243setConfig={setConfig}244configuration={configuration}245data={data}246state={state}247IMAGES={IMAGES}248/>249),250},251{252key: "ephemeral",253label: <></>,254value: (255<Ephemeral256setConfig={setConfig}257configuration={configuration}258loading={loading}259/>260),261},262{263key: "allow-collaborator-control",264label: <></>,265value: (266<AllowCollaboratorControl267setConfig={setConfig}268configuration={configuration}269loading={loading}270/>271),272},273{274key: "admin",275label: <></>,276value: (277<Admin id={id} configuration={configuration} template={template} />278),279},280];281282const showError = (283<ShowError284error={error}285setError={setError}286style={{ width: "100%", margin: "5px 0" }}287/>288);289290return (291<div style={{ marginBottom: "30px" }}>292<div style={{ color: "#666", marginBottom: "10px" }}>293{showError}294{loading && (295<div style={{ textAlign: "center" }}>296<Spin style={{ marginLeft: "15px" }} />297</div>298)}299{cost != null && priceData != null && (300<CostOverview301cost={cost}302description={303<>304You pay <b>{currency(cost)}/hour</b> while the server is running305for compute and storage. You only pay{" "}306<b>307{currency(308computeCost({ configuration, priceData, state: "off" }),309)}310/hour311</b>{" "}312for storage when the server is off, and there is no cost when313the server is deprovisioned. All network data transfer{" "}314<b>is free</b>, and{" "}315<A href="https://www.hyperstack.cloud/why-hyperstack">316Hyperstack's data centers are 100% Renewably Powered317</A>{" "}318via hydro-energy, housed within{" "}319<A href="https://www.hyperstack.cloud/blog/company-news/nexgen-cloud-and-aq-compute-advance-towards-net-zero-ai-supercloud">320sustainable data centers321</A>322.323</>324}325/>326)}327<Divider />328<div style={{ textAlign: "center", margin: "10px 80px" }}>329<Specs330flavor_name={configuration.flavor_name}331region_name={configuration.region_name}332priceData={priceData}333diskSizeGb={configuration.diskSizeGb}334/>335</div>336<Divider />337<Table338showHeader={false}339style={{ marginTop: "5px" }}340columns={columns}341dataSource={dataSource}342pagination={false}343/>344</div>345346{showError}347</div>348);349}350351function Admin({ id, configuration, template }) {352const isAdmin = useTypedRedux("account", "is_admin");353if (!isAdmin) {354return null;355}356return (357<div>358<div style={{ color: "#666", marginBottom: "5px" }}>359<b>360<Icon name="users" /> Admin361</b>362<br />363Settings and functionality only available to admins.364<br />365<pre>366id={id}, configuration={JSON.stringify(configuration, undefined, 2)}367</pre>368<Template id={id} template={template} />369</div>370</div>371);372}373374375