-
Notifications
You must be signed in to change notification settings - Fork 9
/
jupyterServerStart.py
executable file
·59 lines (47 loc) · 1.62 KB
/
jupyterServerStart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python3
import psycopg2 as psg
import subprocess
import json
import os
import sys
import jupyterConfig as cf
def enclose(s):
return "'" + s + "'"
configFileName=os.path.dirname(os.path.abspath(__file__)) + '/configuration.json'
configFile=open(configFileName,'r')
config=json.load(configFile)
configFile.close()
db=config['database']
host=db['host']
dbuser=db['username']
passwd=db['password']
dbname=db['database']
namespace=config['namespaces']['jupyter']
domain=config['jupyter']['domain']
platform=config['platform']
serverConfigFileName=sys.argv[1]
sConfigFile=open(serverConfigFileName,'r')
sconfig=json.load(sConfigFile)
sConfigFile.close()
sid=sconfig['id']
image_id=sconfig['image_id']
gpu=sconfig['gpu']
folder=sconfig['folder']
cpu=sconfig['resources']['cpu']
mem=sconfig['resources']['mem']
image=sconfig['image']
password=sconfig['password']
project=sconfig['project']
mount=sconfig['mountFolder']
nfs=sconfig['nfs']
user=sconfig['user']
expires=sconfig['expires']
manifest,url=cf.createServerConfig(sid,cpu,mem,password,folder,image,mount,nfs,namespace,domain,platform,gpu)
subprocess.call(['kubectl', 'apply', '-f', manifest])
values=[enclose(manifest), enclose(project), enclose(sid), enclose(image), 'NOW()', enclose(user), enclose('https://' + url),"'t'", enclose(expires), enclose(image_id), enclose('spawning')]
sql='INSERT INTO jupyter_server(manifest,project,server_id,image,created_at,created_by,url,active, expires_on, image_id, state) VALUES (' + ','.join(values) + ')'
conn=psg.connect(host=host, user=dbuser, password=passwd, dbname=dbname)
cur=conn.cursor()
cur.execute(sql)
conn.commit()
conn.close()