cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
cfsp_util.py
Go to the documentation of this file.
1 # /*******************************************************************************
2 # * Copyright 2016 -- 2022 IBM Corporation
3 # *
4 # * Licensed under the Apache License, Version 2.0 (the "License");
5 # * you may not use this file except in compliance with the License.
6 # * You may obtain a copy of the License at
7 # *
8 # * http://www.apache.org/licenses/LICENSE-2.0
9 # *
10 # * Unless required by applicable law or agreed to in writing, software
11 # * distributed under the License is distributed on an "AS IS" BASIS,
12 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # * See the License for the specific language governing permissions and
14 # * limitations under the License.
15 # *******************************************************************************/
16 
17 # *
18 # * cloudFPGA
19 # * Copyright IBM Research, All Rights Reserved
20 # * =============================================
21 # * Created: Mar. 2021
22 # * Authors: FAB, WEI, NGL, DID
23 # *
24 # * Description:
25 # * A Python library with functions for accessing cFRM and create/delete images, instances, clusters etc.
26 # *
27 # *
28 
29 import os
30 import sys
31 import subprocess
32 import requests
33 import json
34 import time
35 import resource
36 import datetime
37 
38 
41 
42 
44  print( # "Openstack credentials should be stored in {}) \n".format(__credentials_file_name__) +
45  "Options available in cFSPlib.mngmt library :\n" +
46  " - Clusters: \n" +
47  " - post_cluster(user, number_of_FPGA_nodes, role_image_id, host_address)\n" +
48  " - get_cluster_data(cluster) \n" +
49  " - get_clusters_data(user) \n" +
50  " - delete_cluster_data(cluster) \n" +
51  " - restart_cluster_apps(cluster) \n" +
52  " - Instances: \n" +
53  " - restart_instance_app(instance) \n" +
54  " - delete_instance(instance) \n" +
55  " - Resources (admin users only): \n" +
56  " - get_resource_status(resource_id) \n" +
57  " - Users: \n" +
58  " - cFuser(path/to/credentials.json) \n" +
59  " - load_user_credentials(filedir) \n" +
60  " - show_user_credentials(filedir) \n\n")
61 
62 
63 def errorReqExit(msg, code):
64  print("Request " + msg + " failed with HTTP code " + str(code) + ".")
65  if code == 0:
66  print("0 error: no response from server\n")
67  elif (msg == "GET cluster") or (msg == "GET clusters") or (msg == "DELETE cluster"):
68  if code == 400:
69  print("400 Bad request (maybe login/pass with space char?)\n")
70  if code == 401:
71  print("401 Unauthenticated, bad login\n")
72  if code == 403:
73  print("403 Unauthorized\n")
74  if code == 404:
75  print("404 Cluster does not exist\n")
76  elif msg == "POST cluster":
77  if code == 401:
78  print("401 Unauthenticated, bad login\n")
79  if code == 404:
80  print("404 One of the regested images does not exist\n")
81  if code == 415:
82  print("415 Image has wrong type/breed\n")
83  if code == 422:
84  print("422 Malformed request\n")
85  if code == 424:
86  print("424 Bitfile seems to be preecarious/unstable (e.g. bad timing or could also hide an internal server error)\n")
87  if code == 429:
88  print("429 Insufficient Quota\n")
89  if code == 500:
90  print("500 Error in communication with devices (maybe try again)\n")
91  if code == 503:
92  print("503 No resources available to fullfil the request\n")
93  if code == 507:
94  print("507 Network or Memory failure on target device (maybe try again)\n")
95  if code == 508:
96  print("508 No network resources available, please contact admins\n")
97  exit(1)
98 
99 
def print_usage()
Utility Functions.
Definition: cfsp_util.py:43
def errorReqExit(msg, code)
Definition: cfsp_util.py:63