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/hub/smc-manager.coffee
Views: 687
#########################################################################1# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2# License: MS-RSL – see LICENSE.md for details3#########################################################################45async = require('async')6winston = require('./logger').getLogger('smc-manager')78misc = require('@cocalc/util/misc')9{defaults, required} = misc1011smc_gcloud = require('./smc_gcloud')1213exports.smc = (opts) -> new SMC(opts)1415class SMC16constructor: ->17@_gcloud = require('./smc_gcloud').gcloud()1819dbg: (f) ->20return (m) -> winston.debug("smc.#{f}: #{m}")2122create_compute_vm: (opts) =>23opts = defaults opts,24name : required # e.g., 'compute11'25base : 'compute0-us' # name of disk to clone26type : 'n1-standard-1'27preemptible : true28cb : required29dbg = @dbg("create_compute_vm(name='#{opts.name}')")30async.series([31(cb) =>32dbg("create base disk from current live disk '#{opts.base}'")33disk = @_gcloud.disk(name:opts.base)34disk.copy35name : opts.name36cb : cb37(cb) =>38dbg("create vm")39@_gcloud.create_vm40name : opts.name41type : opts.type42preemptible : opts.preemptible43tags : ['compute']44disks : [opts.name]45cb : cb46], opts.cb)4748create_web_vm: (opts) =>49opts = defaults opts,50name : required # e.g., 'web10'51base : 'web0' # name of disk to clone52type : 'g1-small'53preemptible : true54cb : required55dbg = @dbg("create_web_vm(name='#{opts.name}')")56async.series([57(cb) =>58dbg("create base disk from current live disk '#{opts.base}'")59disk = @_gcloud.disk(name:opts.base)60disk.copy61name : opts.name62cb : cb63(cb) =>64dbg("create vm")65@_gcloud.create_vm66name : opts.name67type : opts.type68preemptible : opts.preemptible69tags : ['http-server', 'https-server', 'hub']70disks : [opts.name]71cb : cb72], opts.cb)737475