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/hub/smc-manager.coffee
Views: 687
1
#########################################################################
2
# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
# License: MS-RSL – see LICENSE.md for details
4
#########################################################################
5
6
async = require('async')
7
winston = require('./logger').getLogger('smc-manager')
8
9
misc = require('@cocalc/util/misc')
10
{defaults, required} = misc
11
12
smc_gcloud = require('./smc_gcloud')
13
14
exports.smc = (opts) -> new SMC(opts)
15
16
class SMC
17
constructor: ->
18
@_gcloud = require('./smc_gcloud').gcloud()
19
20
dbg: (f) ->
21
return (m) -> winston.debug("smc.#{f}: #{m}")
22
23
create_compute_vm: (opts) =>
24
opts = defaults opts,
25
name : required # e.g., 'compute11'
26
base : 'compute0-us' # name of disk to clone
27
type : 'n1-standard-1'
28
preemptible : true
29
cb : required
30
dbg = @dbg("create_compute_vm(name='#{opts.name}')")
31
async.series([
32
(cb) =>
33
dbg("create base disk from current live disk '#{opts.base}'")
34
disk = @_gcloud.disk(name:opts.base)
35
disk.copy
36
name : opts.name
37
cb : cb
38
(cb) =>
39
dbg("create vm")
40
@_gcloud.create_vm
41
name : opts.name
42
type : opts.type
43
preemptible : opts.preemptible
44
tags : ['compute']
45
disks : [opts.name]
46
cb : cb
47
], opts.cb)
48
49
create_web_vm: (opts) =>
50
opts = defaults opts,
51
name : required # e.g., 'web10'
52
base : 'web0' # name of disk to clone
53
type : 'g1-small'
54
preemptible : true
55
cb : required
56
dbg = @dbg("create_web_vm(name='#{opts.name}')")
57
async.series([
58
(cb) =>
59
dbg("create base disk from current live disk '#{opts.base}'")
60
disk = @_gcloud.disk(name:opts.base)
61
disk.copy
62
name : opts.name
63
cb : cb
64
(cb) =>
65
dbg("create vm")
66
@_gcloud.create_vm
67
name : opts.name
68
type : opts.type
69
preemptible : opts.preemptible
70
tags : ['http-server', 'https-server', 'hub']
71
disks : [opts.name]
72
cb : cb
73
], opts.cb)
74
75