def create_model(self, model_payload_dict, model_imports_zip_path): model_name = model_payload_dict['name'] logger.debug("Starting to create model '{}', zip path '{}'".format(model_name, model_imports_zip_path)) multi_part_form_data = [] model_zip_param = ('modelImportsZip', (pycurl.FORM_FILE, str(model_imports_zip_path))) multi_part_form_data.append(model_zip_param) json_payload = self.__parse_to_json_str(model_payload_dict) model_param = ('model', ( pycurl.FORM_CONTENTS, json_payload, pycurl.FORM_CONTENTTYPE, 'application/json' )) multi_part_form_data.append(model_param) response_buffer = BytesIO() response_code = self.__sdc_be_proxy.post_file(str(self.__base_path), multi_part_form_data, response_buffer) logger.debug("Create model response code '{}'".format(response_code)) if response_code != 201: error_msg = "Failed to create model '{}'".format(model_name) logger.log(error_msg, response_buffer.getvalue()) raise Exception(error_msg) logger.log("Created model", model_name)
def import_model_elements(self, model_payload_dict, tosca_elements_import_path, with_metadata): model_name = model_payload_dict['name'] logger.debug("Starting import of normative elements for model '{}'".format(model_name)) if with_metadata: process_element_list(get_normative_element_with_metadata_list(tosca_elements_import_path), self.__sdc_be_proxy, model=model_name) else: process_element_list(get_normative_element_candidate_list(tosca_elements_import_path), self.__sdc_be_proxy, model=model_name) logger.log("Finished importing normative elements for model", model_name)
def main(sdc_be_proxy, update_version): # use to run script form this dir (not like the command) # base_file_location = os.getcwd() + "/../../../import/tosca/" base_file_location = os.getcwd() + os.path.sep logger.debug("working directory =" + base_file_location) process_element_list( get_normative_element_candidate_list(base_file_location), sdc_be_proxy) process_type_list(get_normative_type_candidate_list(base_file_location), sdc_be_proxy, update_version) process_element_list( get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy) logger.log("Script end ->", "All normatives imported successfully!") logger.print_and_exit(0, None)
def update_model_imports(self, model_payload_dict, model_imports_zip_path): model_name = model_payload_dict['name'] logger.debug("Starting to update model '{}', zip path '{}'".format(model_name, model_imports_zip_path)) multi_part_form_data = [] model_zip_post = ('modelImportsZip', (pycurl.FORM_FILE, str(model_imports_zip_path))) multi_part_form_data.append(('modelName', model_name)) multi_part_form_data.append(model_zip_post) response_buffer = BytesIO() response_code = self.__sdc_be_proxy.put_file(str(self.__imports_path), multi_part_form_data, response_buffer) logger.debug("Update model response code '{}'".format(response_code)) if response_code != 204: error_msg = "Failed to update model '{}'".format(model_name) logger.log(error_msg, response_buffer.getvalue()) raise Exception(error_msg) logger.log("Updated model", model_name)
def main(sdc_be_proxy): update_version = True update_onap_version = False update_nfv_version = True # use to run script form this dir (not like the command) # base_file_location = os.getcwd() + "/../../../../import/tosca/" base_file_location = os.getcwd() + "/" logger.debug("working directory =" + base_file_location) model_import_manager = ModelImportManager( Path(base_file_location) / 'models', ModelClient(sdc_be_proxy), NodeTypeClient(sdc_be_proxy)) try: model_import_manager.deploy_models() except Exception as ex: logger.log("An error has occurred while uploading the models: ", str(ex)) raise ex process_element_list( get_normative_element_candidate_list(base_file_location), sdc_be_proxy) all_types = get_all_types() heat_and_normative_list = get_heat_and_normative_to_update_list( all_types, base_file_location) process_type_list(heat_and_normative_list, sdc_be_proxy, update_version) onap_sol_list = get_onap_sol_to_update_list(all_types, base_file_location) process_type_list(onap_sol_list, sdc_be_proxy, update_onap_version) nfv_list = get_nfv_to_update_list(all_types, base_file_location) process_type_list(nfv_list, sdc_be_proxy, update_nfv_version) process_element_list( get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy) logger.log("Updating end ->", "All normatives updated successfully!") print_and_exit(0, None)
def main(sdc_be_proxy): update_version = True update_onap_version = False # use to run script form this dir (not like the command) # base_file_location = os.getcwd() + "/../../../../import/tosca/" base_file_location = os.getcwd() + "/" logger.debug("working directory =" + base_file_location) process_element_list(get_normative_element_candidate_list(base_file_location), sdc_be_proxy) process_element_list(get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy) all_types = get_all_types() heat_and_normative_list = get_heat_and_normative_to_update_list(all_types, base_file_location) process_type_list(heat_and_normative_list, sdc_be_proxy, update_version) nfv_onap_sol_list = get_nfv_onap_sol_to_update_list(all_types, base_file_location) process_type_list(nfv_onap_sol_list, sdc_be_proxy, update_onap_version) logger.log("Updating end ->", "All normatives updated successfully!") print_and_exit(0, None)
def import_all(self, node_type_yaml_path, node_type_metadata_json_str, is_update=False): logger.debug( "Starting to import node types '{}'".format(node_type_yaml_path)) multi_part_form_data = [] node_type_yaml_param = ('nodeTypesYaml', (pycurl.FORM_FILE, str(node_type_yaml_path))) multi_part_form_data.append(node_type_yaml_param) node_type_metadata_json_param = ('nodeTypeMetadataJson', (pycurl.FORM_CONTENTS, node_type_metadata_json_str, pycurl.FORM_CONTENTTYPE, 'application/json')) multi_part_form_data.append(node_type_metadata_json_param) if is_update is not None: create_new_version_param = ('createNewVersion', (pycurl.FORM_CONTENTS, str(is_update).lower(), pycurl.FORM_CONTENTTYPE, 'text/plain')) multi_part_form_data.append(create_new_version_param) response_buffer = BytesIO() response_code = self.__sdc_be_proxy.post_file( str(self.__import_all_path), multi_part_form_data, response_buffer) logger.debug( "Import all node types response code '{}'".format(response_code)) if response_code != 201: error_msg = "Failed to import node types '{}'".format( node_type_yaml_path) logger.log(error_msg, response_buffer.getvalue()) raise Exception(error_msg) logger.log( "Failed to import node types '{}'".format(node_type_yaml_path))
def _send_request(sdc_be_proxy, file_dir, url_suffix, element_name, element_form_name, model, with_metadata=False): try: log("create normative element ", element_name) type_file_name = file_dir + element_name multi_part_form_data = _create_multipart_form_data(element_form_name, type_file_name, with_metadata, element_name, model) debug("http request url =", url_suffix) http_res = sdc_be_proxy.post_file(url_suffix, multi_part_form_data) if http_res is not None: debug("http response =", http_res) response = sdc_be_proxy.get_response_from_buffer() debug("response buffer", response) # c.close() return element_name, http_res, response except Exception as inst: print("ERROR=" + str(inst)) return element_name, None, None
def main(sdc_be_proxy, update_version): # use to run script form this dir (not like the command) # base_file_location = os.getcwd() + "/../../../import/tosca/" base_file_location = os.getcwd() + os.path.sep logger.debug("working directory =" + base_file_location) if sdc_be_proxy.disable_locking("true") != 200: raise RuntimeError("Failed to disable locking") try: process_element_list(normativeElementsList.get_normative_element_candidate_list(base_file_location), sdc_be_proxy) process_type_list(normativeTypesList.get_normative_type_candidate_list(base_file_location), sdc_be_proxy, update_version) process_element_list(normativeElementsList.get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy) # Add model based normatives model_import_manager = ModelImportManager(Path(base_file_location) / 'models', ModelClient(sdc_be_proxy), NodeTypeClient(sdc_be_proxy)) model_import_manager.deploy_models() except Exception as ex: logger.log("An error has occurred while uploading elements and types: ", str(ex)) raise ex finally: if sdc_be_proxy.disable_locking("false") != 200: raise RuntimeError("Failed to enable locking") logger.log("Script end ->", "All normatives imported successfully!") logger.print_and_exit(0, None)
def _send_request(sdc_be_proxy, file_dir, element_name, update_version): try: log("create normative type ", element_name) debug("userId", sdc_be_proxy.con.user_header) debug("fileDir", file_dir) url = '/sdc2/rest/v1/catalog/upload/multipart' if update_version is not None: url += '?createNewVersion=' + _boolean_to_string(update_version) send = _create_send_body(file_dir, element_name) debug(send) http_res = sdc_be_proxy.post_file(url, send) if http_res is not None: debug("http response=", http_res) response = sdc_be_proxy.get_response_from_buffer() debug(response) return element_name, http_res, response except Exception as inst: print("ERROR=" + str(inst)) return element_name, None, None
def import_model_types(self, model_name, types_list, upgrade): logger.debug("Starting import of normative types for model '{}'".format(model_name)) process_type_list(types_list, self.__sdc_be_proxy, upgrade) logger.log("Finished importing normative types for model", model_name)