def removeNSIinNST(nstId): # ------ OLD VERSION --------- #nstParameter2update = "NSI_list_ref.pop="+str(nsiId) #updatedNST_jsonresponse = nst_catalogue.update_nst(nstParameter2update, nstId) # if there are no more NSI assigned to the NST, updates usageState parameter # catalogue_response = nst_catalogue.get_saved_nst(nstId) # nst_json = catalogue_response['nstd'] # if not nst_json['NSI_list_ref']: # if (nst_json['usageState'] == "IN_USE"): # nstParameter2update = "usageState=NOT_IN_USE" # updatedNST_jsonresponse = nst_catalogue.update_nst(nstParameter2update, nstId) # ---------------------------- nsis_list = nsi_repo.getAll_saved_nsi() all_nsis_terminated = True for nsis_item in nsis_list: if (nsis_item['nst-ref'] == nstd_id and nsis_item['nsi-status'] == "INSTANTIATED" or nsis_item['nsi-status'] == "INSTANTIATING" or nsis_item['nsi-status'] == "READY"): all_nsis_terminated = False break if (all_nsis_terminated): nst_descriptor = nst_catalogue.get_saved_nst(nstId) nst_json = nst_descriptor['nstd'] if (nst_json['usageState'] == "IN_USE"): nstParameter2update = "usageState=NOT_IN_USE" updatedNST_jsonresponse = nst_catalogue.update_nst( nstParameter2update, nstId)
def createNSI(nsi_json): LOG.info("NSI_MNGR: Creates and Instantiates a new NSI.") time.sleep(0.1) nstId = nsi_json['nstId'] catalogue_response = nst_catalogue.get_saved_nst(nstId) nst_json = catalogue_response['nstd'] # creates NSI with the received information LOG.info("NSI_MNGR: Creating Basic NSI structure") time.sleep(0.1) new_nsir = createBasicNSI(nst_json, nsi_json) LOG.info("NSI_MNGR: Adding subnets infromationg into the basic structure") time.sleep(0.1) new_nsir = addSubnets2NSi(new_nsir, nst_json["slice_ns_subnets"]) # new_nsir = addVLD2NSi(new_nsir, nst_json["slice_ns_subnets"]) #TODO: function to add VLD information into the NSI # saving the NSI into the repositories LOG.info("NSI_MNGR: Saving NSI into repositories") time.sleep(0.1) nsirepo_jsonresponse = nsi_repo.safe_nsi(new_nsir) # starts the thread to instantiate while sending back the response LOG.info("NSI_MNGR: Calling the instantiation thread.") time.sleep(0.1) thread_instantiation = thread_instantiate(new_nsir) thread_instantiation.start() return nsirepo_jsonresponse, 201
def deleteNST(nstId): logging.info("NST_MNGR: Delete NST with id: " + str(nstId)) nstcatalogue_jsonresponse = nst_catalogue.get_saved_nst(nstId) if (nstcatalogue_jsonresponse['nstd']["usageState"] == "NOT_IN_USE"): nstcatalogue_jsonresponse = nst_catalogue.delete_nst(nstId) return nstcatalogue_jsonresponse else: return 403
def get_nst(nstId): logging.info("NST_MNGR: Retrieving NST with id: " + str(nstId)) nstcatalogue_jsonresponse = nst_catalogue.get_saved_nst(nstId) if (nstcatalogue_jsonresponse): return (nstcatalogue_jsonresponse, 200) else: return ('{"msg":"There is no NSTD with this uuid in the db."}', 200)
def get_nst(nstId): LOG.info("Retrieving Network Slice Template with ID: " + str(nstId)) nstcatalogue_jsonresponse = nst_catalogue.get_saved_nst(nstId) if (nstcatalogue_jsonresponse): return (nstcatalogue_jsonresponse, 200) else: return ('{"msg":"There is no NSTD with this uuid in the db."}', 200)
def remove_nst(nstId): LOG.info("Delete Network Slice Template with ID: " + str(nstId)) nstcatalogue_jsonresponse = nst_catalogue.get_saved_nst(nstId) if (nstcatalogue_jsonresponse['nstd']["usageState"] == "NOT_IN_USE"): nstcatalogue_jsonresponse = nst_catalogue.delete_nst(nstId) return nstcatalogue_jsonresponse else: return 403
def run(self): mutex.acquire() try: LOG.info( "NSI_MNGR_Notify: Slice instantitaion Notification to GTK.") jsonNSI = nsi_repo.get_saved_nsi(self.nsiId) #TODO: improve the next 2 lines to not use this delete. jsonNSI["id"] = jsonNSI["uuid"] del jsonNSI["uuid"] # checks if all services are READY/ERROR to update the slice_status all_services_ready = True for service_item in jsonNSI['nsr-list']: if (service_item['working-status'] == "INSTANTIATING"): all_services_ready = False break if (all_services_ready == True): jsonNSI['nsi-status'] = "INSTANTIATED" # validates if any service has error status to apply it to the slice status for service_item in jsonNSI['nsr-list']: if (service_item['working-status'] == "ERROR"): jsonNSI['nsi-status'] = "ERROR" break # sends the updated NetSlice instance to the repositories jsonNSI['updateTime'] = str( datetime.datetime.now().isoformat()) repo_responseStatus = nsi_repo.update_nsi(jsonNSI, self.nsiId) # updates NetSlice template usageState if (jsonNSI['nsi-status'] == "INSTANTIATED"): nst_descriptor = nst_catalogue.get_saved_nst( jsonNSI['nst-ref']) if (nst_descriptor['nstd'].get('usageState') == "NOT_IN_USE"): #updateNST_jsonresponse = nstd_usagesstatus_update(jsonNSI['nst-ref'], nst_descriptor['nstd']) nstParameter2update = "usageState=IN_USE" updatedNST_jsonresponse = nst_catalogue.update_nst( nstParameter2update, jsonNSI['nst-ref']) finally: mutex.release() #INFO: leave here & don't join with the same previous IF, as the multiple return(s) depend on this order if (all_services_ready == True): # creates a thread with the callback URL to advise the GK this slice is READY slice_callback = jsonNSI['sliceCallback'] json_slice_info = {} json_slice_info['status'] = jsonNSI['nsi-status'] json_slice_info['updateTime'] = jsonNSI['updateTime'] thread_response = mapper.sliceUpdated(slice_callback, json_slice_info)
def getNST(nstId): logging.info("NST_MNGR: Retrieving NST with id: " + str(nstId)) nstcatalogue_jsonresponse = nst_catalogue.get_saved_nst(nstId) return nstcatalogue_jsonresponse