def check_results_and_exit(results, update_version, exit_on_success): if not _results_ok(results, _get_response_code(update_version)): raise ResourceCreationError("Failed to create the normatives types !!", 1) else: if exit_on_success: print_and_exit(0, "All normatives types created successfully!!")
def _check_and_retry(attempt, code, message): if attempt == properties.retry_attempts + 1: print_and_exit(code, message) print(colors.FAIL + '[WARRING]: ' + datetime.now().strftime('%Y/%m/%d %H:%M:%S') + ' ' + message + ", try again: #" + str(attempt) + colors.END_C) time.sleep(properties.retry_time)
def print_and_check_result(result, exit_on_success): if result is not None: print_name_and_return_code(result[0], result[1]) if result[1] is None or result[1] not in [200, 201, 409]: raise ResourceCreationError("Failed to create the normatives elements!!", 1) else: if exit_on_success is True: print_and_exit(0, "All normatives elements created successfully!!") else: raise ResourceCreationError("Results is None!", 1)
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 run(): sdc_be_proxy, update_version = parse_and_create_proxy() response = sdc_be_proxy.get_normatives() resources = [] if response == 200: resources = json.loads( sdc_be_proxy.get_response_from_buffer())["resources"] else: print_and_exit(response, "Can't get normatives!") if len(resources) < properties.resource_len: import_main(sdc_be_proxy, update_version) else: upgrade_main(sdc_be_proxy)
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 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)