31 __cfp_json_path__ =
"/../cFp.json"
32 __shell_type_key__ =
'cFpSRAtype'
33 __mod_type_key__ =
'cFpMOD'
34 __dcps_folder_name__ =
'/dcps/'
36 __credentials_file_name__ =
"user.json"
38 __openstack_user_template__ = {
'credentials': {
'username':
"your user name",
'password':
"your user password"},
41 __cf_manager_url__ =
"10.12.0.132:8080"
45 json_file = filedir +
"/" + __credentials_file_name__
46 global __openstack_user__
47 global __openstack_pw__
48 global __openstack_project__
51 with open(json_file,
'r')
as infile:
52 data = json.load(infile)
53 __openstack_user__ = data[
'credentials'][
'username']
54 __openstack_pw__ = data[
'credentials'][
'password']
56 __openstack_project__ = data[
'project']
58 except Exception
as e:
60 print(
"Writing credentials template to {}\n".format(json_file))
62 with open(json_file,
'w')
as outfile:
63 json.dump(__openstack_user_template__, outfile)
68 me_abs = os.path.dirname(os.path.realpath(__file__))
69 cfp_json_file = me_abs + __cfp_json_path__
70 debugging_flow = os.environ.get(
'CFP_DEBUGGING')
71 if debugging_flow
is not None:
72 cfp_json_file = me_abs + debugging_flow +
'/cFp.json'
73 with open(cfp_json_file,
'r')
as json_file:
74 cFp_data = json.load(json_file)
77 root_abs = os.path.realpath(me_abs+
"/../")
78 if debugging_flow
is not None:
79 root_abs = os.path.realpath(me_abs + debugging_flow +
"/env/" +
"/../")
80 cFp_data[
'abs_path'] = root_abs
81 dcps_folder = root_abs + __dcps_folder_name__
82 os.system(
"mkdir -p {}".format(dcps_folder))
83 dcp_file_name =
"3_top{}_STATIC.dcp".format(cFp_data[__mod_type_key__])
84 target_file_name = os.path.abspath(dcps_folder +
"/" + dcp_file_name)
85 meta_file_name =
"3_top{}_STATIC.json".format(cFp_data[__mod_type_key__])
86 target_meta_name = os.path.abspath(dcps_folder +
"/" + meta_file_name)
88 shell_type = cFp_data[__shell_type_key__]
92 print(
"Please save your (escaped) OpenStack credentials in {}/{}".format(root_abs, __credentials_file_name__))
95 cfrm_url = __cf_manager_url__
96 if debugging_flow
is not None:
97 cfrm_url =
"localhost:8080"
103 if os.path.isfile(target_meta_name)
and os.path.isfile(target_file_name):
104 with open(target_meta_name,
'r')
as meta_file:
105 cur_meta = json.load(meta_file)
106 current_cert = cur_meta[
'cert']
107 current_id = cur_meta[
'id']
109 if 'pl_id' in cur_meta:
110 current_id = cur_meta[
'pl_id']
112 requests_error =
False
114 r1 = requests.get(
"http://"+cfrm_url+
"/composablelogic/by_shell/"+
str(shell_type)
115 +
"?username={0}&password={1}".format(__openstack_user__, __openstack_pw__))
116 except Exception
as e:
118 requests_error =
True
119 if requests_error
or r1.status_code != 200:
120 print(
"ERROR: Failed to connect to CFRM ({}). STOP.".format(r1.status_code))
123 r1_list = json.loads(r1.text)
124 latest_shell_id = r1_list[-1][
'id']
128 r3 = requests.get(
"http://"+cfrm_url+
"/composablelogic/"+
str(latest_shell_id)
129 +
"/meta?username={0}&password={1}".format(__openstack_user__, __openstack_pw__))
130 except Exception
as e:
132 requests_error =
True
133 if requests_error
or r3.status_code != 200:
134 print(
"ERROR: Failed to connect to CFRM ({}). STOP.".format(r1.status_code))
137 dcp_meta = json.loads(r3.text)
139 if latest_shell_id == current_id:
141 if dcp_meta[
'cert'] == current_cert:
142 print(
'[cFBuild] Current dcp (path: {}; id: {}) is up to date. DONE.'
143 .format(target_file_name, latest_shell_id))
146 print(
'[cFBuild] Update detected, downloading newest version... (can take some minutes)\n')
148 download_url =
"http://"+cfrm_url+
"/composablelogic/"+
str(latest_shell_id)+
"/dcp" + \
149 "?username={0}&password={1}".format(__openstack_user__, __openstack_pw__)
151 with requests.get(download_url, stream=
True)
as r2:
152 r2.raise_for_status()
153 if r2.status_code != 200:
154 requests_error =
True
155 err_msg =
"{}".format(r2.status_code)
156 with open(target_file_name,
'wb')
as f:
157 for chunk
in r2.iter_content(chunk_size=8192):
160 print(
"ERROR: Failed to download latest dcp ({}). STOP.".format(err_msg))
163 with open(target_meta_name,
'w')
as outfile:
164 json.dump(dcp_meta, outfile)
166 print(
"[cFBuild] Updated dcp of Shell '{}' to latest version ({}) successfully. DONE.\n\t(downloaded dcp to {})"
167 .format(shell_type, latest_shell_id, target_file_name))
171 if __name__ ==
'__main__':
def load_user_credentials(filedir)