54 conf = Configuration()
55 conf.host = cfsp_globals.__cf_manager_url__
56 api_client = ApiClient(conf)
57 api_instance = ClustersApi(api_client=api_client)
59 if ((len(args[
'<args>']) < 1)
or (len(args[
'<args>']) > 2)):
60 print(
"ERROR: invalid arguments provided in 'cfsp cluster' command. Aborting...")
63 username = cfsp_globals.__cfsp_username__
64 password = cfsp_globals.__cfsp_password__
65 project_name = cfsp_globals.__cfsp_project__
67 if args[
'<args>'][0] ==
'get':
68 if (len(args[
'<args>']) == 2):
70 api_response = api_instance.cf_manager_rest_api_get_cluster_single(username, password, args[
'<args>'][1])
71 except ApiException
as e:
72 print(
"Exception when calling ClustersApi->cf_manager_rest_api_get_cluster_single: %s\n" % e)
74 elif (len(args[
'<args>']) == 1):
76 api_response = api_instance.cf_manager_rest_api_get_clusters(username, password, limit=args[
'--limit'])
77 except ApiException
as e:
78 print(
"Exception when calling ClustersApi->cf_manager_rest_api_get_clusters: %s\n" % e)
81 exit(print(
"ERROR: invalid arguments provided in cfsp cluster get. Aborting..."))
83 elif (args[
'<args>'][0] ==
'post')
or (args[
'<args>'][0] ==
'extend'):
86 cpu_num = len(args[
'--node_ip'])
87 fpga_num = len(args[
'--image_id'])
88 node_id_num = len(args[
'--node_id'])
91 print(
"WARNING: No --node_id argument was provided. Incremental ids will be used for fpga(s) and cpu(s) in this cluster.")
92 for i
in range(fpga_num):
93 args[
'--node_id'].append(i)
94 for j
in range(cpu_num):
95 args[
'--node_id'].append(fpga_num+j)
97 if (node_id_num != cpu_num + fpga_num):
98 exit(print(
"ERROR: The provided argument(s) of --node_id ("+
str(node_id_num)+
") is not the same with the sum of --node_ip ("+
str(cpu_num)+
") and --image_id ("+
str(fpga_num)+
") ones. Please note that for each of --node_ip and --image_id, a --node_id argument is required. Aborting..."))
101 args[
'--node_id'] = list(map(int, args[
'--node_id']))
103 print(
"INFO: Please review the assignment of image_id(s), node_ip(s) and node_id(s)")
104 print(
"[image_id, node_id]")
105 for i
in range(fpga_num):
106 fpga_body = {
"image_id": args[
'--image_id'][i],
"node_id": args[
'--node_id'][i] }
107 print(
"["+args[
'--image_id'][i] +
", " +
str(args[
'--node_id'][i]) +
"]")
108 body.append(fpga_body)
109 print(
"[node_ip, node_id]")
110 for j
in range(cpu_num):
111 cpu_body = {
"image_id": cfsp_globals.__NON_FPGA_IDENTIFIER__,
"node_ip": args[
'--node_ip'][j],
"node_id": args[
'--node_id'][fpga_num+j] }
112 print(
"["+args[
'--node_ip'][j] +
", " +
str(args[
'--node_id'][fpga_num+j]) +
"]")
113 body.append(cpu_body)
115 if (args[
'<args>'][0] ==
'post'):
118 api_response = api_instance.cf_manager_rest_api_post_clusters(body, username, password, project_name=project_name, dont_verify_memory=args[
'--dont_verify_memory'])
120 except ApiException
as e:
121 print(
"Exception when calling ClustersApi->cf_manager_rest_api_post_clusters: %s\n" % e)
123 elif args[
'<args>'][0] ==
'extend':
126 api_response = api_instance.cf_manager_rest_api_extend_cluster(body, username, password, cluster_id=args[
'--cluster_id'], dont_verify_memory=args[
'--dont_verify_memory'])
128 except ApiException
as e:
129 print(
"Exception when calling ClustersApi->cf_manager_rest_api_extend_cluster: %s\n" % e)
131 elif (args[
'<args>'][0] ==
'reduce'):
132 node_id_num = len(args[
'--node_id'])
136 args[
'--node_id'] = list(map(int, args[
'--node_id']))
138 for i
in range(node_id_num):
139 node_id_body = args[
'--node_id'][i]
140 body.append(node_id_body)
143 api_response = api_instance.cf_manager_rest_api_reduce_cluster(body, username, password, cluster_id=args[
'--cluster_id'])
145 except ApiException
as e:
146 print(
"Exception when calling ClustersApi->cf_manager_rest_api_reduce_cluster: %s\n" % e)
148 elif (args[
'<args>'][0] ==
'update'):
149 node_id_num = len(args[
'--node_id'])
150 cpu_num = len(args[
'--node_ip'])
151 fpga_num = len(args[
'--image_id'])
153 cluster_id_num = len(args[
'--cluster_id'])
155 exit(print(
"ERROR: The argument --cluster_id must be provided once. Aborting..."))
160 exit(print(
"ERROR: The argument --image_id cannot be provided together with --node_ip in cluster update (i.e. cannot simultanously update CPU and FPGA nodes). Aborting..."))
162 if (node_id_num == 0):
163 print(
"WARNING: No argument --node_id was provided. Will try to locate CPU node_id's in cluster "+
str(args[
'--cluster_id'])+
" ...")
165 api_response = api_instance.cf_manager_rest_api_get_cluster_single(username, password, args[
'--cluster_id'])
166 except ApiException
as e:
167 print(
"Exception when calling ClustersApi->cf_manager_rest_api_get_cluster_single: %s\n" % e)
170 nodes_in_cluster_len = len(api_response.nodes)
171 for i
in range(nodes_in_cluster_len):
173 if (api_response.nodes[i].get(
'image_id') ==
'NON_FPGA'):
174 print(
"INFO: Found CPU node at id : " +
str(api_response.nodes[i].get(
'node_id')) +
", with ip : " +
str(api_response.nodes[i].get(
'node_ip')))
175 args[
'--node_id'].append(api_response.nodes[i].get(
'node_id'))
178 args[
'--node_id'] = list(map(int, args[
'--node_id']))
180 node_id_num = len(args[
'--node_id'])
181 if (node_id_num != cpu_num):
182 exit(print(
"ERROR: The list of CPU nodes provided or found on the cluster " +
str(args[
'--cluster_id']) +
" ("+
str(node_id_num) +
") is not equal to the number of new IPs for CPUs provided (" +
str(cpu_num) +
") in cluster update. Aborting..."))
184 print(
"Reducing cluster...")
187 api_response = api_instance.cf_manager_rest_api_reduce_cluster(args[
'--node_id'], username, password, cluster_id=args[
'--cluster_id'])
188 except ApiException
as e:
189 print(
"Exception when calling ClustersApi->cf_manager_rest_api_reduce_cluster: %s\n" % e)
194 for j
in range(cpu_num):
195 cpu_body = {
"image_id": cfsp_globals.__NON_FPGA_IDENTIFIER__,
"node_ip": args[
'--node_ip'][j],
"node_id": args[
'--node_id'][j] }
196 print(
"["+args[
'--node_ip'][j] +
", " +
str(args[
'--node_id'][j]) +
"]")
197 body.append(cpu_body)
199 print(
"Extending cluster...")
202 api_response = api_instance.cf_manager_rest_api_extend_cluster(body, username, password, cluster_id=args[
'--cluster_id'], dont_verify_memory=args[
'--dont_verify_memory'])
204 except ApiException
as e:
205 print(
"Exception when calling ClustersApi->cf_manager_rest_api_extend_cluster: %s\n" % e)
213 elif (fpga_num != 0):
216 exit(print(
"ERROR: The argument --image_id must be provided once. Aborting..."))
218 exit(print(
"ERROR: The argument --node_ip cannot be provided together with ----image_id in cluster update (i.e. cannot simultanously update FPGA and CPU nodes). Aborting..."))
219 if (node_id_num == 0):
220 print(
"WARNING: No argument --node_id was provided. Will try to locate FPGA node_id's in cluster "+
str(args[
'--cluster_id'])+
" ...")
222 api_response = api_instance.cf_manager_rest_api_get_cluster_single(username, password, args[
'--cluster_id'])
223 except ApiException
as e:
224 print(
"Exception when calling ClustersApi->cf_manager_rest_api_get_cluster_single: %s\n" % e)
227 nodes_in_cluster_len = len(api_response.nodes)
228 for i
in range(nodes_in_cluster_len):
230 if (api_response.nodes[i].get(
'image_id') !=
'NON_FPGA'):
231 print(
"INFO: Found FPGA node at id : " +
str(api_response.nodes[i].get(
'node_id')) +
", with ip : " +
str(api_response.nodes[i].get(
'node_ip')))
232 args[
'--node_id'].append(api_response.nodes[i].get(
'node_id'))
235 args[
'--node_id'] = list(map(int, args[
'--node_id']))
237 node_id_num = len(args[
'--node_id'])
239 for i
in range(node_id_num):
242 api_response = api_instance.cf_manager_rest_api_update_node_of_cluster(args[
'--image_id'][0], username, password, cluster_id=args[
'--cluster_id'], node_id=args[
'--node_id'][i], dont_verify_memory=args[
'--dont_verify_memory'])
243 except ApiException
as e:
244 print(
"Exception when calling ClustersApi->cf_manager_rest_api_update_node_of_cluster: %s\n" % e)
249 exit(print(
"ERROR: No arguments --image_id or --node_id is provided. Aborting..."))
250 elif args[
'<args>'][0] ==
'restart':
251 if (len(args[
'<args>']) == 1):
252 cluster_id = args[
'--cluster_id']
253 elif (len(args[
'<args>']) == 2):
254 cluster_id = args[
'<args>'][1]
256 exit(print(
"ERROR: invalid arguments provided in cfsp cluster restart. Aborting..."))
258 print(
"INFO: Restarting cluster " +
str(cluster_id) +
" ... ")
260 api_response = api_instance.cf_manager_rest_api_restart_cluster(username, password, cluster_id)
262 except ApiException
as e:
263 print(
"Exception when calling ClustersApi->cf_manager_rest_api_restart_cluster: %s\n" % e)
265 elif args[
'<args>'][0] ==
'delete':
266 if (len(args[
'<args>']) == 1):
267 print(
"INFO: Trying deleting all clusters.")
269 api_response_get_in_delete = api_instance.cf_manager_rest_api_get_clusters(username, password)
270 if(len(api_response_get_in_delete) > 0):
271 if(len(api_response_get_in_delete) == 1):
272 print(
"INFO: Really deleting cluster " +
str(api_response_get_in_delete[0].cluster_id) +
" ?")
274 print(
"INFO: Really deleting all " +
str(len(api_response_get_in_delete)) +
" clusters ?")
276 print(
"INFO: Confirmed deleting all clusters.")
277 for this_cluster
in tqdm(api_response_get_in_delete):
279 print(
"INFO: Deleting cluster " +
str(this_cluster.cluster_id) +
" ... ")
281 api_instance.cf_manager_rest_api_delete_cluster(username, password, this_cluster.cluster_id)
282 except ApiException
as e_in_delete:
283 print(
"Exception when calling ClustersApi->cf_manager_rest_api_delete_cluster: %s\n" % e_in_delete)
285 print (
"INFO: Canceling deleting clsuter(s).")
287 print(
"INFO: No clusters to delete.")
288 except ApiException
as e_in_get:
289 print(
"Exception when calling ClustersApi->cf_manager_rest_api_get_clusters: %s\n" % e_in_get)
291 elif (len(args[
'<args>']) == 2):
292 cluster_id = args[
'<args>'][1]
294 print(
"INFO: Deleting cluster " +
str(cluster_id) +
" ... ")
296 api_response = api_instance.cf_manager_rest_api_delete_cluster(username, password, cluster_id)
298 except ApiException
as e:
299 print(
"Exception when calling ClustersApi->cf_manager_rest_api_delete_cluster: %s\n" % e)
302 exit(print(
"ERROR: invalid arguments provided in cfsp cluster delete. Aborting..."))
304 exit(print(
"ERROR: invalid command provided in cfsp cluster. Type 'cfsp help cluster' to get a list of supported commands. Aborting..."))