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/cost.ts
Views: 687
/*1Compute cost per hour of a configuration in a given state.2*/34import type {5State,6Configuration,7} from "@cocalc/util/db-schema/compute-servers";8import { getGoogleCloudPriceData, getHyperstackPriceData } from "./api";9import computeGoogleCloudCost from "@cocalc/util/compute/cloud/google-cloud/compute-cost";10import computeHyperstackCost from "@cocalc/util/compute/cloud/hyperstack/compute-cost";1112export default async function costPerHour({13configuration,14state,15}: {16configuration: Configuration;17state: State;18}): Promise<number> {19if (state == "deprovisioned") {20// always a cost of 0 in this state21return 0;22}23if (configuration.cloud == "onprem") {24// free for now -- but we will charge, e.g., for bandwidth and management when25// this has a management layer26return 0;27}28if (state != "running" && state != "off" && state != "suspended") {29throw Error("state must be stable");30}31if (configuration.cloud == "google-cloud") {32const priceData = await getGoogleCloudPriceData();33return computeGoogleCloudCost({ configuration, priceData, state });34} else if (configuration.cloud == "hyperstack") {35const priceData = await getHyperstackPriceData();36return computeHyperstackCost({ configuration, priceData, state });37} else {38throw Error(39`cost computation not yet implemented for '${configuration.cloud}'`,40);41}42}434445