def run(self): mutex.acquire() try: LOG.info("NSI_MNGR_Update: Updating NSI Termination") time.sleep(0.1) 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"] # looks for the right service within the slice and updates it with the new data for service_item in jsonNSI['nsr-list']: if (service_item['nsrId'] == self.request_json['instance_uuid'] ): service_item['requestId'] = self.request_json['id'] if (self.request_json['status'] == "READY"): service_item['working-status'] = "TERMINATED" else: service_item['working-status'] = self.request_json[ 'status'] break jsonNSI['updateTime'] = str(datetime.datetime.now().isoformat()) repo_responseStatus = nsi_repo.update_nsi(jsonNSI, self.nsiId) finally: mutex.release()
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 run(self): LOG.info("NSI_MNGR_Terminate: Terminating Services") jsonNSI = nsi_repo.get_saved_nsi(self.nsiId) for nsr_item in jsonNSI['nsr-list']: if (nsr_item['working-status'] != "ERROR"): data = {} data["instance_uuid"] = str(nsr_item["nsrId"]) data["request_type"] = "TERMINATE_SERVICE" data[ 'callback'] = "http://tng-slice-mngr:5998/api/nsilcm/v1/nsi/" + str( self.nsiId) + "/terminate-change" termination_response = mapper.net_serv_terminate(data)
def terminateNSI(nsiId, TerminOrder): LOG.info("NSI_MNGR: Terminates a NSI.") jsonNSI = nsi_repo.get_saved_nsi(nsiId) #TODO: improve the next 2 lines to not use this delete. jsonNSI["id"] = jsonNSI["uuid"] del jsonNSI["uuid"] # prepares time values to check if termination is done in the future if (TerminOrder['terminateTime'] == "0" or TerminOrder['terminateTime'] == 0): termin_time = 0 else: termin_time = dateutil.parser.parse(TerminOrder['terminateTime']) instan_time = dateutil.parser.parse(jsonNSI['instantiateTime']) # depending on the termin_time executes one action or another if termin_time == 0 and jsonNSI['nsi-status'] == "INSTANTIATED": jsonNSI['terminateTime'] = str(datetime.datetime.now().isoformat()) jsonNSI['sliceCallback'] = TerminOrder['callback'] jsonNSI['nsi-status'] = "TERMINATING" for terminate_nsr_item in jsonNSI['nsr-list']: if (terminate_nsr_item['working-status'] != "ERROR"): terminate_nsr_item['working-status'] = "TERMINATING" LOG.info("NSI_MNGR: Updating initial nsi with this dict:" + str(jsonNSI)) repo_responseStatus = nsi_repo.update_nsi(jsonNSI, nsiId) # starts the thread to terminate while sending back the response thread_termination = thread_terminate(nsiId) thread_termination.start() value = 200 # TODO: manage future termination orders elif (instan_time < termin_time): jsonNSI['terminateTime'] = str(termin_time) repo_responseStatus = nsi_repo.update_nsi(jsonNSI, nsiId) value = 200 else: repo_responseStatus = { "error": "Wrong value: 0 for instant termination or date time later than " + NSI.instantiateTime + ", to terminate in the future." } value = 400 return (repo_responseStatus, value)
def run(self): mutex.acquire() try: LOG.info( "NSI_MNGR_Notify: Slice terminationg 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'] == "TERMINATING"): all_services_ready = False break if (all_services_ready == True): jsonNSI['nsi-status'] = "TERMINATED" # 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['terminateTime'] = str( datetime.datetime.now().isoformat()) jsonNSI['updateTime'] = jsonNSI['terminateTime'] repo_responseStatus = nsi_repo.update_nsi(jsonNSI, self.nsiId) # updates NetSlice template list of slice_instances based on that template removeNSIinNST(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): # sends the request to notify the GTK the 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 updateTerminatingNSI(nsiId, request_json): LOG.info( "NSI_MNGR: get the specific NSI to update the right service information." ) jsonNSI = nsi_repo.get_saved_nsi(nsiId) if (jsonNSI): # starts the thread to update termination info within the services thread_update_termination = update_service_termination( nsiId, request_json) thread_update_termination.start() # starts the thread to notify the GTK if the slice is ready thread_notify_termination = notify_slice_terminated(nsiId) thread_notify_termination.start() return (jsonNSI, 200) else: return ('{"error":"There is no NSIR in the db."}', 500)
def updateInstantiatingNSI(nsiId, request_json): LOG.info("NSI_MNGR: Updates the NSI with the latest incoming information.") jsonNSI = nsi_repo.get_saved_nsi(nsiId) if (jsonNSI): LOG.info("NSI_MNGR: Calling thread to update nsi.") time.sleep(0.1) # starts the thread to update instantiation info within the services thread_update_instance = update_service_instantiation( nsiId, request_json) thread_update_instance.start() LOG.info("NSI_MNGR: Calling thread to notify slice ready.") time.sleep(0.1) # starts the thread to notify the GTK if the slice is ready thread_notify_instantiation = notify_slice_instantiated(nsiId) thread_notify_instantiation.start() return (jsonNSI, 200) else: return ('{"error":"There is no NSIR in the db."}', 500)
def run(self): mutex.acquire() try: LOG.info("NSI_MNGR_Update: Updating NSI instantiation") 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"] serviceInstance = {} # if list is empty, full it with the first element # if not jsonNSI['netServInstance_Uuid']: # serviceInstance['servId'] = self.request_json['service_uuid'] # serviceInstance['servName'] = self.request_json['name'] # serviceInstance['workingStatus'] = self.request_json['status'] # serviceInstance['requestID'] = self.request_json['id'] # if(self.request_json['instance_uuid'] == None): # serviceInstance['servInstanceId'] = " " # else: # serviceInstance['servInstanceId'] = self.request_json['instance_uuid'] # # adds the service instance into the NSI json # jsonNSI['netServInstance_Uuid'].append(serviceInstance) # list has at least one element #else: # service_added = False # looks all the already added services and updates the right for service_item in jsonNSI['nsr-list']: # if the current request already exists, update it. if (service_item['nsrName'] == self.request_json['name']): service_item['requestId'] = self.request_json['id'] if (self.request_json['status'] == "READY"): service_item['working-status'] = "INSTANTIATED" else: service_item['working-status'] = self.request_json[ 'status'] if (self.request_json['instance_uuid'] != None): service_item['nsrId'] = self.request_json[ 'instance_uuid'] # used to avoid a for-else loop with the next if break # # the current request doesn't exist in the list, adds it. # if (service_added == False): # serviceInstance['servId'] = self.request_json['service_uuid'] # serviceInstance['servName'] = self.request_json['name'] # serviceInstance['workingStatus'] = self.request_json['status'] # serviceInstance['requestID'] = self.request_json['id'] # if(self.request_json['instance_uuid'] == None): # serviceInstance['servInstanceId'] = " " # else: # serviceInstance['servInstanceId'] = self.request_json['instance_uuid'] # # adds the service instance into the NSI json # jsonNSI['netServInstance_Uuid'].append(serviceInstance) jsonNSI['updateTime'] = str(datetime.datetime.now().isoformat()) repo_responseStatus = nsi_repo.update_nsi(jsonNSI, self.nsiId) finally: mutex.release()
def getNSI(nsiId): LOG.info("NSI_MNGR: Retrieving NSI with id: " + str(nsiId)) nsirepo_jsonresponse = nsi_repo.get_saved_nsi(nsiId) return nsirepo_jsonresponse