Beispiel #1
0
    def run(self):

        # acquires mutex to have unique access to the nsi (repositories)
        mutex_slice2db_access.acquire()

        instantiation_resp = self.send_instantiation_request()
        if instantiation_resp[1] != 201:
            self.NSI['nsi-status'] = 'ERROR'
            self.NSI['errorLog'] = 'ERROR when instantiating '
        else:
            self.NSI['id'] = self.req['nsiId']
            self.NSI['nsi-status'] = 'INSTANTIATING'

        # releases mutex for any other thread to acquire it
        mutex_slice2db_access.release()

        if self.NSI['nsi-status'] != 'ERROR':
            # Waits until the NS is instantiated/ready or error
            deployment_timeout = 30 * 60  # 30 minutes

            nsi_instantiated = False
            while deployment_timeout > 0:

                if self.NSI['id'] == self.req['nsiId']:
                    uuid = sbi.get_nsi_id_from_name(self.req['nsiId'])
                    if (uuid):
                        self.NSI['id'] = uuid

                if self.NSI['id'] != self.req['nsiId']:
                    # Check ns instantiation status
                    nsi = sbi.get_saved_nsi(self.NSI['id'])
                    if "uuid" in nsi:
                        self.NSI = nsi
                        self.NSI["id"] = self.NSI["uuid"]
                        del self.NSI["uuid"]

                    if self.NSI['nsi-status'] in [
                            "INSTANTIATED", "ERROR", "READY"
                    ]:
                        nsi_instantiated = True

                    # if all services are instantiated, ready or error, break the while loop to notify the GTK
                    if nsi_instantiated:
                        LOG.info(
                            "Network Slice Instantiation request processed for Network Slice with ID: "
                            + str(self.NSI['id']))
                        break

                time.sleep(15)
                deployment_timeout -= 15

            if not nsi_instantiated:
                self.NSI['nsi-status'] = 'ERROR'
                self.NSI['errorLog'] = 'ERROR when terminating with timeout'

        # Notifies the VS that the Network Slice instantiation process is done (either complete or error)
        LOG.info(
            "Instantiation Step: Informing VS about the correct end of Network Slice with ID: "
            + str(self.NSI['id']))
        self.update_nsi_notify_instantiate()
def get_nsi(nsiName, timestamp):
    # Get the uuid from the name provided
    name = 'query'
    uuid = sbi.get_nsi_id_from_name(nsiName)
    if (uuid):
        LOG.info("Retrieving Network Slice Instance with ID: " + str(uuid))
        nsirepo_jsonresponse = sbi.get_saved_nsi(uuid)
        if (nsirepo_jsonresponse):

            fsm_name = db.get_fsm_name_slice(nsiName)
            if fsm_name is not None:
                if (fsm_name != ""):
                    if (fsm_name == "tunnel"):
                        name = "getvnfinfo"
                    elif (fsm_name == "MTD"):
                        name = "getmtdinfo"
                    nsirepo_jsonresponse['parameters'] = sbi.ws_get_info(
                        uuid, fsm_name)

            sbi.send_metrics(nsiName, 'start', name, timestamp)
            # Translate the response
            new_nsirepo_jsonresponse = translate_nsi_from_sonata_to_vs(
                nsiName, nsirepo_jsonresponse)
            return (new_nsirepo_jsonresponse, 200, name)
        else:
            sbi.send_metrics(nsiName, 'start', name, timestamp)
            return_msg = {}
            return_msg['msg'] = "There are no NSIR with this uuid in the db."
            return (return_msg, 404, name)
    else:
        sbi.send_metrics(nsiName, 'start', name, timestamp)
        return_msg = {}
        return_msg['msg'] = "There are no NSIR with this uuid in the db."
        return (return_msg, 404, name)
def terminate_nsi(nsiName, TerminOrder):
    #LOG.info("Updating the Network Slice Record for the termination procedure.")
    mutex_slice2db_access.acquire()
    try:
        # Get the uuid from the name provided
        uuid = sbi.get_nsi_id_from_name(nsiName)
        if (uuid):
            terminate_nsi = sbi.get_saved_nsi(uuid)
            if terminate_nsi:
                # if nsi is not in TERMINATING/TERMINATED
                if terminate_nsi['nsi-status'] in [
                        "INSTANTIATED", "INSTANTIATING", "READY", "ERROR"
                ]:
                    terminate_nsi['id'] = terminate_nsi['uuid']
                    del terminate_nsi['uuid']

                    terminate_nsi['terminateTime'] = str(
                        datetime.datetime.now().isoformat())
                    #terminate_nsi['sliceCallback'] = TerminOrder['callback']
                    terminate_nsi['nsi-status'] = "TERMINATING"

                    # starts the thread to terminate while sending back the response
                    LOG.info("Starting the termination procedure.")
                    thread_ns_termination = thread_ns_terminate(terminate_nsi)
                    thread_ns_termination.start()

                    if db.get_slice(nsiName) is not None:
                        db.del_slice(nsiName)

                    terminate_value = 202

                else:
                    terminate_nsi[
                        'errorLog'] = "This NSI is either terminated or being terminated."
                    terminate_value = 404
            else:
                terminate_nsi['errorLog'] = "There is no NSIR in the db."
                terminate_value = 404
        else:
            terminate_nsi = {}
            terminate_nsi['errorLog'] = "There is no NSIR in the db."
            terminate_value = 404
    finally:
        mutex_slice2db_access.release()
        return (terminate_nsi, terminate_value)
Beispiel #4
0
def get_nsi(nsiName):
    # Get the uuid form the name provided
    uuid = sbi.get_nsi_id_from_name(nsiName)
    if (uuid):
        LOG.info("Retrieving Network Slice Instance with ID: " + str(uuid))
        nsirepo_jsonresponse = sbi.get_saved_nsi(uuid)
        if (nsirepo_jsonresponse):
            # Translate the response
            new_nsirepo_jsonresponse = translate_nsi_from_sonata_to_vs(
                nsirepo_jsonresponse)
            return (new_nsirepo_jsonresponse, 200)
        else:
            return_msg = {}
            return_msg['msg'] = "There are no NSIR with this uuid in the db."
            return (return_msg, 404)
    else:
        return_msg = {}
        return_msg['msg'] = "There are no NSIR with this uuid in the db."
        return (return_msg, 404)
def configure_nsi(nsiName, nsi_json):
    #LOG.info("Updating the Network Slice Record for the configuration procedure.")
    #mutex_slice2db_access.acquire()
    try:
        # Get the uuid from the name provided
        uuid = sbi.get_nsi_id_from_name(nsiName)
        if (uuid):
            configure_nsi = sbi.get_saved_nsi(uuid)
            if configure_nsi:
                # if nsi is in INSTANTIATED
                if configure_nsi['nsi-status'] in ["INSTANTIATED"]:

                    #If the config is for receive information, only update the db
                    fsm_name = ""
                    if (nsi_json['parameters']['ruleName'] == "getvnfinfo"):
                        fsm_name = "tunnel"
                        db.update_status_slice("CONFIGURING", nsiName)
                        db.update_fsm_name_slice(fsm_name, nsiName)
                        configure_value = 201
                    elif (nsi_json['parameters']['ruleName'] == "getmtdinfo"):
                        fsm_name = "MTD"
                        db.update_status_slice("CONFIGURING", nsiName)
                        db.update_fsm_name_slice(fsm_name, nsiName)
                        configure_value = 201

                        #If the config is for configure the fsm start the thread
                    else:
                        if (nsi_json['parameters']['ruleName'] == "addpeer"):
                            fsm_name = "tunnel"
                        elif (nsi_json['parameters']['ruleName'] == "routemgmt"
                              ):
                            fsm_name = "tunnel"
                        elif (nsi_json['parameters']['ruleName'] ==
                              "activatemtd"):
                            fsm_name = "MTD"
                        elif (nsi_json['parameters']['ruleName'] == "modifymtd"
                              ):
                            fsm_name = "MTD"
                        configure_nsi['fsm_name'] = fsm_name

                        configure_nsi['id'] = configure_nsi['uuid']
                        del configure_nsi['uuid']

                        configure_nsi['configureTime'] = str(
                            datetime.datetime.now().isoformat())
                        #configure_nsi['sliceCallback'] = nsiName['callback']
                        configure_nsi['nsi-status'] = "CONFIGURING"

                        # Add parameters information from json request
                        configure_nsi['parameters'] = nsi_json['parameters']

                        # starts the thread to configure while sending back the response
                        LOG.info("Starting the configuration procedure.")
                        thread_ns_configuration = thread_ns_configure(
                            configure_nsi)
                        thread_ns_configuration.start()
                        thread_ns_configuration.join()
                        configure_value = 202

                        db.update_status_slice("CONFIGURED", nsiName)
                        db.update_fsm_name_slice("", nsiName)
                else:
                    configure_nsi[
                        'errorLog'] = "This NSI is not in instantiated or configurated status."
                    configure_value = 404
            else:
                configure_nsi['errorLog'] = "There is no NSIR in the db."
                configure_value = 404
        else:
            configure_nsi = {}
            configure_nsi['errorLog'] = "There is no NSIR in the db."
            configure_value = 404
    finally:
        #mutex_slice2db_access.release()
        return ({}, configure_value)