19 cfsp image (get | post | delete)
21 get <id> Get all images of a user. Either <id> of image or no argument for all.
22 post Request an image.
23 delete id Delete an image with image_id=id.
25 from __future__
import absolute_import
29 python_api_client_path = os.getcwd()+
"/cFSPlib/python_api_client/"
30 sys.path.append(python_api_client_path)
34 from swagger_client.api.images_api
import ImagesApi
35 from swagger_client.rest
import ApiException
36 from swagger_client.api_client
import ApiClient
37 from swagger_client.configuration
import Configuration
41 confirm =
input(
"[c]Confirm or [v]Void: ")
42 if confirm !=
'c' and confirm !=
'v':
43 print(
"\n Invalid Option. Please Enter a Valid Option.")
50 conf = Configuration()
51 conf.host = cfsp_globals.__cf_manager_url__
52 api_client = ApiClient(conf)
53 api_instance = ImagesApi(api_client=api_client)
55 if ((len(args[
'<args>']) < 1)
or (len(args[
'<args>']) > 2)):
56 print(
"ERROR: invalid arguments provided in 'cfsp image' command. Aborting...")
59 username = cfsp_globals.__cfsp_username__
60 password = cfsp_globals.__cfsp_password__
61 project_name = cfsp_globals.__cfsp_project__
63 if args[
'<args>'][0] ==
'get':
64 if (len(args[
'<args>']) == 2):
66 api_response = api_instance.cf_manager_rest_api_get_image_single(username, password, args[
'<args>'][1])
67 except ApiException
as e:
68 print(
"Exception when calling ImagesApi->cf_manager_rest_api_get_image_single: %s\n" % e)
70 elif (len(args[
'<args>']) == 1):
72 api_response = api_instance.cf_manager_rest_api_get_images(username, password, limit=args[
'--limit'])
73 except ApiException
as e:
74 print(
"Exception when calling ImagesApi->cf_manager_rest_api_get_images: %s\n" % e)
77 exit(print(
"ERROR: invalid arguments provided in cfsp image get. Aborting..."))
79 elif args[
'<args>'][0] ==
'post':
81 comment = args[
'--comment']
83 image_details =
'{ "breed": "SHELL", "fpga_board": "FMKU60", "shell_type": "Themisto", "comment" : "' + comment +
'"}'
85 image_file = args[
'--image_file']
86 if (image_file.find(
"pblock") != -1):
87 print(
"ERROR: the image file contains the keyword 'pblock' which is typically generated in pr flow. Do you wish to continue anyway ?")
89 exit(print(
"ERROR: Aborting upon user selection..."))
90 length_image_file = len(image_file)
91 image_file_type = image_file[length_image_file - 3 : length_image_file]
92 if (image_file_type ==
"bit"):
93 api_response = api_instance.cf_manager_rest_api_post_images(image_details, image_file, pr_verify_rpt, username, password)
94 this_id = api_response.id
96 api_response = api_instance.cf_manager_rest_api_get_image_single(username, password, this_id)
97 except ApiException
as e:
98 print(
"Exception when calling ImagesApi->cf_manager_rest_api_get_image_single: %s (nested in ImagesApi->cf_manager_rest_api_post_images)\n" % e)
101 exit(print(
"ERROR: invalid image file provided in cfsp post-app-logic. You should provide a .bit file instead. Aborting..."))
102 except ApiException
as e:
103 print(
"Exception when calling ImagesApi->cf_manager_rest_api_post_images: %s\n" % e)
105 elif args[
'<args>'][0] ==
'post-app-logic':
107 image_file = args[
'--image_file']
108 if (image_file.find(
"pblock") == -1):
109 print(
"WARNING: the image file does not contain the keyword 'pblock' which is typically generated in pr flow. Do you wish to continue anyway ?")
111 exit(print(
"ERROR: Aborting upon user selection..."))
112 image_dirname = os.path.dirname(image_file)
113 json_file = image_dirname+
"/3_topFMKU60_STATIC.json"
114 print(
"INFO: This json file will be used: " + json_file)
115 with open(json_file)
as f:
117 cl_id =
str(data[
'id'])
118 comment = args[
'--comment']
120 image_details =
'{"cl_id": "' + cl_id +
'", "fpga_board": "FMKU60", "shell_type": "Themisto", "comment" : "' + comment +
'"}'
121 length_image_file = len(image_file)
122 image_file_type = image_file[length_image_file - 3 : length_image_file]
123 image_file_name = image_file[0 : length_image_file - 4]
124 if (image_file_type ==
"bin"):
125 sig_file = args[
'--sig_file']
126 if (sig_file
is None):
127 sig_file = image_file +
".sig"
128 print(
"INFO: No --sig_file provided. Assuming " + sig_file)
129 pr_verify_rpt = args[
'--pr_verify_rpt']
130 if (pr_verify_rpt
is None):
131 pr_verify_rpt = image_file_name +
".rpt"
132 pr_verify_rpt_new = pr_verify_rpt.replace(
"4_",
"5_")
133 pr_verify_rpt = pr_verify_rpt_new
134 print(
"INFO: No --pr_verify_rpt provided. Assuming " + pr_verify_rpt)
136 api_response = api_instance.cf_manager_rest_api_post_app_logic(image_details, image_file, sig_file, pr_verify_rpt, username, password)
137 this_id = api_response.id
139 api_response = api_instance.cf_manager_rest_api_get_image_single(username, password, this_id)
140 except ApiException
as e:
141 print(
"Exception when calling ImagesApi->cf_manager_rest_api_get_image_single: %s (nested in ImagesApi->cf_manager_rest_api_post_app_logic)\n" % e)
144 exit(print(
"ERROR: invalid image file provided in cfsp post-app-logic. You should provide a .bin file instead. Aborting..."))
145 except ApiException
as e:
146 print(
"Exception when calling ImagesApi->cf_manager_rest_api_post_app_logic: %s\n" % e)
148 elif args[
'<args>'][0] ==
'delete':
149 if (len(args[
'<args>']) == 2):
152 image_id = args[
'<args>'][1]
153 api_instance.cf_manager_rest_api_delete_image(username, password, image_id)
154 except ApiException
as e:
155 print(
"Exception when calling ImagesApi->cf_manager_rest_api_delete_image: %s\n" % e)
157 exit(print(
"ERROR: invalid arguments provided in cfsp image delete. Aborting..."))
159 exit(print(
"ERROR: invalid command provided in cfsp image. Type 'cfsp help image' to get a list of supported commands. Aborting..."))
161 if __name__ ==
'__main__':