forked from hughperkins/nimbix-admin
/
launch.py
74 lines (63 loc) · 2 KB
/
launch.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from __future__ import print_function
import sys
import yaml
from os.path import join
from os import path
import argparse
import requests
import argparse
api_url = 'https://api.jarvice.com/jarvice'
script_dir = path.dirname(path.realpath(__file__))
def launch(config, image, instancetype):
username = config['username']
apikey = config['apikey']
launch_data = {
"machine": {
"nodes": "1",
"type": instancetype
},
"vault": {
"readonly": False,
"force": False,
"name": "drop.jarvice.com"
},
"user": {
"username": username,
"apikey": apikey
},
"nae": {
"force": False,
"name": image,
"geometry": "1904x881",
"ephemeral": False,
"staging": True,
"interactive": True
}
}
res = requests.post('%s/submit' % api_url, json=launch_data)
return res.status_code, res.content
if __name__ == '__main__':
instancetype = None
config_path = 'nimbix.yaml'
if len(sys.argv) > 2 or (len(sys.argv) == 2 and sys.argv[1] in ['--help']):
parser = argparse.ArgumentParser()
parser.add_argument('--type', help='type, eg ng0 for bfboost, or ngd3 for dual Titan X')
parser.add_argument('--image', default='ng0', help='image name (basically, container name, more or less)')
parser.add_argument('--configfile', default=join(script_dir, 'nimbix.yaml'))
args = parser.parse_args()
instancetype = args.type
image = args.image
config_path = args.configfile
else:
image = sys.argv[1]
if not config_path.startswith('/'):
config_path = join(script_dir, config_path)
with open(config_path, 'r') as f:
config = yaml.load(f)
if instancetype is None:
instancetype = config['type_by_instance'].get(image, image)
print('instancetype: %s' % instancetype)
status_code, content = launch(config, image, instancetype)
print(status_code)
print(content)
print(status_code)