-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateCluster.py
98 lines (85 loc) · 3.26 KB
/
createCluster.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import time
import sys
import requests
import json
import base64
import getopt
from client import Client
#--------------------------------------------------------------------------
def prepare_headers(apikey):
encoded_bytes = base64.b64encode(apikey.encode('utf-8'))
encoded_string = encoded_bytes.decode('utf-8')
headers = {
'Authorization': 'Basic ' + encoded_string
}
return headers
#------------------------------------------------------------------
if __name__ == '__main__':
#inputs
print('PW_PLATFORM_HOST: ', os.environ.get('PW_PLATFORM_HOST'))
if os.environ.get('PW_PLATFORM_HOST') is not None:
pw_url = 'https://' + os.environ['PW_PLATFORM_HOST']
else:
pw_url = 'https://noaa.parallel.works'
print('PW_API_KEY: ', os.environ.get('PW_API_KEY'))
if os.environ.get('PW_API_KEY') is not None:
apikey = os.environ['PW_API_KEY']
else:
print('PW_API_KEY is not set in environmental variablse. Exit.')
sys.exit(-1)
jsonfile = 'clusterDef.json'
clustername = 'testfromapi1'
displayname = 'WEI EPIC AWS c7i.48xlarge'
#type must be one of ['pclusterv2', 'gclusterv2', 'azclusterv2']
clustertype = 'pclusterv2'
description = 'Wei pclusterv2 on AWS from EPIC using c7i.48xlarge'
tags = 'computer on c7i.48xlarge, process on c7i.24xlarge'
opts, args = getopt.getopt(sys.argv[1:], '', ['help=', 'jsonfile=', 'clustername=',
'displayname=', 'clustertype=',
'description=', 'tags='])
for o, a in opts:
if o in ['--help']:
print('Usage: %s [--help] [--jsonfile=filename]')
sys.exit(0)
elif o in ['--jsonfile']:
jsonfile = a
elif o in ['--clustername']:
clustername = a
elif o in ['--displayname']:
displayname = a
elif o in ['--clustertype']:
clustertype = a
elif o in ['--description']:
description = a
elif o in ['--tags']:
tags = a
else:
assert False, 'unhandled option'
#------------------------------------------------------------------
print('clustername <%s>' %(clustername))
print('clustertype <%s>' %(clustertype))
print('displayname <%s>' %(displayname))
print('description <%s>' %(description))
print('tags <%s>' %(tags))
#------------------------------------------------------------------
header = prepare_headers(apikey)
c = Client(pw_url, header, displayname)
cluster = c.create_v2_cluster(clustername, description, tags, clustertype)
cluster_id = cluster['_id']
with open(jsonfile) as cluster_defintion:
data = json.load(cluster_defintion)
try:
updated_cluster = c.update_v2_cluster(cluster_id, data)
print(updated_cluster)
except requests.exceptions.HTTPError as e:
print(e.response.text)
'''
# This section will get and display the resource list.
# get_resources gets the full list of resources,
# and get_resource will get the named resource.
resources = c.get_resources()
print(json.dumps(resources, indent=4))
namedResource = c.get_resource("testfromapi1")
print(json.dumps(namedResource, indent=4))
'''