Example #1
0
    def get_csar(self, csar_id):
        package_info = {}

        csar_in_catalog = query_csar_from_catalog(csar_id)
        props_of_catalog = [
            "name", "provider", "version", "operationalState", "usageState",
            "onBoardState", "processState", "deletionPending", "downloadUri",
            "createTime", "modifyTime", "format", "size"
        ]
        for prop in props_of_catalog:
            package_info[prop] = ignore_case_get(csar_in_catalog, prop)

        csars = NSDModel.objects.filter(id=csar_id)
        if csars:
            package_info["nsdId"] = csars[0].nsd_id
            package_info["nsdProvider"] = csars[0].vendor
            package_info["nsdVersion"] = csars[0].version

        nss = NSInstModel.objects.filter(nspackage_id=csar_id)
        ns_instance_info = [{
            "nsInstanceId": ns.id,
            "nsInstanceName": ns.name
        } for ns in nss]

        return [
            0, {
                "csarId": csar_id,
                "packageInfo": package_info,
                "nsInstanceInfo": ns_instance_info
            }
        ]
Example #2
0
    def delete_pending_csar(self):
        JobUtil.create_job(
            inst_type='nf',
            jobaction='delete_pending',
            inst_id=self.csar_id,
            job_id=self.job_id)
        JobUtil.add_job_status(self.job_id, 5, "Start to delete pending CSAR(%s)." % self.csar_id)

        if not NfPackageModel.objects.filter(nfpackageid=self.csar_id):
            JobUtil.add_job_status(self.job_id, 100, "Delete pending CSAR(%s) successfully." % self.csar_id)
            return

        csar_info = query_csar_from_catalog(self.csar_id)

        process_state = ignore_case_get(csar_info, "processState")
        if process_state == P_STATUS_DELETING:
            JobUtil.add_job_status(self.job_id, 100, "CSAR(%s) is deleting now." % self.csar_id)
            return

        deletion_pending = ignore_case_get(csar_info, "deletionPending")
        if deletion_pending.lower() == "false":
            JobUtil.add_job_status(self.job_id, 100, "CSAR(%s) need not to be deleted." % self.csar_id)
            return

        if NfInstModel.objects.filter(package_id=self.csar_id):
            JobUtil.add_job_status(self.job_id, 100, "CSAR(%s) is in using, cannot be deleted." % self.csar_id)
            return

        NfPackage().delete_csar(self.csar_id, self.job_id)
Example #3
0
    def set_state_csar(self, csar_id, operation):
        if not NSDModel.objects.filter(id=csar_id):
            raise NSLCMException("CSAR(%s) does not exist." % csar_id)

        csar = query_csar_from_catalog(csar_id)
        if ignore_case_get(csar, "operationalState") == operation.capitalize():
            raise NSLCMException("CSAR(%s) already %s." % (csar_id, operation))
        return set_csar_state(csar_id, 'operationState',
                              operation.capitalize())
Example #4
0
    def on_boarding(self, csar_id):
        csar = query_csar_from_catalog(csar_id)
        if ignore_case_get(csar, "onBoardState") == STATUS_ONBOARDED:
            raise NSLCMException("CSAR(%s) already onBoarded." % csar_id)

        raw_data = query_rawdata_from_catalog(csar_id)
        nsd = toscautil.convert_nsd_model(
            raw_data["rawData"])  # convert to inner json
        nsd = json.JSONDecoder().decode(nsd)
        nsd_id = nsd["metadata"]["id"]
        if NSDModel.objects.filter(nsd_id=nsd_id):
            raise NSLCMException("NSD(%s) already exists." % nsd_id)

        for vnf in nsd["vnfs"]:
            vnfd_id = vnf["properties"]["id"]
            pkg = NfPackageModel.objects.filter(vnfdid=vnfd_id)
            if not pkg:
                raise NSLCMException("VNF package(%s) is not onBoarded." %
                                     vnfd_id)
            pkg_id = pkg[0].nfpackageid
            if query_csar_from_catalog(pkg_id,
                                       "onBoardState") != STATUS_ONBOARDED:
                raise NSLCMException(
                    "VNF package(%s) is not onBoarded on catalog." % pkg_id)

        NSDModel(id=csar_id,
                 nsd_id=nsd_id,
                 name=nsd["metadata"].get("name", nsd_id),
                 vendor=nsd["metadata"].get("vendor", "undefined"),
                 description=nsd["metadata"].get("description", ""),
                 version=nsd["metadata"].get("version", "undefined"),
                 nsd_model=json.JSONEncoder().encode(nsd)).save()

        set_csar_state(csar_id, "onBoardState", STATUS_ONBOARDED)
        set_csar_state(csar_id, "operationalState", P_STATUS_ENABLED)

        return [0, "CSAR(%s) onBoarded successfully." % csar_id]
Example #5
0
    def delete_pending_csar(self, csar_id):
        if not NSDModel.objects.filter(id=csar_id):
            return [0, "Delete pending CSAR(%s) successfully." % csar_id]

        pending = query_csar_from_catalog(csar_id, "deletionPending")

        if pending.lower() == "false":
            return [1, "CSAR(%s) need not to be deleted." % csar_id]

        if NSInstModel.objects.filter(nspackage_id=csar_id):
            return [1, "CSAR(%s) is in using, cannot be deleted." % csar_id]

        ret = delete_csar_from_catalog(csar_id)
        if ret[0] == 0:
            NSDModel.objects.filter(id=csar_id).delete()
        return ret
Example #6
0
    def delete_csar(self):
        JobUtil.create_job(
            inst_type='nf',
            jobaction='delete',
            inst_id=self.csar_id,
            job_id=self.job_id)
        JobUtil.add_job_status(self.job_id, 5, "Start to delete CSAR(%s)." % self.csar_id)
        if query_csar_from_catalog(self.csar_id, "processState") == P_STATUS_DELETING:
            JobUtil.add_job_status(self.job_id, 100, "CSAR(%s) is deleting now." % self.csar_id)
            return

        if NfInstModel.objects.filter(package_id=self.csar_id):
            ret = set_csar_state(self.csar_id, "deletionPending", True)
            JobUtil.add_job_status(self.job_id, 100, ret[1])
            return

        NfPackage().delete_csar(self.csar_id, self.job_id)
Example #7
0
    def on_boarding_pre_deal(self):
        JobUtil.add_job_status(self.job_id, 10, "Check status of CSAR(%s) from catalog." % self.csar_id)

        self.csar_info = query_csar_from_catalog(self.csar_id)

        on_board_state = ignore_case_get(self.csar_info, "onBoardState")
        if on_board_state == STATUS_ONBOARDED:
            raise NSLCMException("CSAR(%s) already onBoarded." % self.csar_id)

        process_state = ignore_case_get(self.csar_info, "processState")
        if process_state == P_STATUS_ONBOARDING:
            raise NSLCMException("CSAR(%s) is onBoarding now." % self.csar_id)

        JobUtil.add_job_status(self.job_id, 20, "Get model of CSAR(%s) from catalog." % self.csar_id)

        raw_data = query_rawdata_from_catalog(self.csar_id)
        self.nfd = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json
        self.nfd = json.JSONDecoder().decode(self.nfd)
        self.nfd_id = self.nfd["metadata"]["id"]
        if NfPackageModel.objects.filter(vnfdid=self.nfd_id):
            raise NSLCMException("NFD(%s) already exists." % self.nfd_id)
Example #8
0
    def get_csar(self, csar_id):
        pkg_info = {}
        nf_pkg = NfPackageModel.objects.filter(nfpackageid=csar_id)
        if nf_pkg:
            pkg_info["vnfdId"] = nf_pkg[0].vnfdid
            pkg_info["vnfdProvider"] = nf_pkg[0].vendor
            pkg_info["vnfdVersion"] = nf_pkg[0].vnfdversion
            pkg_info["vnfVersion"] = nf_pkg[0].vnfversion

        casrinfo = query_csar_from_catalog(csar_id)
        props_of_catalog = [
            "name", "provider", "version", "operationalState", "usageState",
            "onBoardState", "processState", "deletionPending", "downloadUri",
            "createTime", "modifyTime", "format", "size"]
        for prop in props_of_catalog:
            pkg_info[prop] = ignore_case_get(casrinfo, prop)

        nf_pkg_files = VnfPackageFileModel.objects.filter(vnfpid=csar_id)
        img_info = [{
            "index": str(i),
            "fileName": nf_pkg_files[i].filename,
            "imageId": nf_pkg_files[i].imageid,
            "vimId": nf_pkg_files[i].vimid,
            "vimUser": nf_pkg_files[i].vimuser,
            "tenant": nf_pkg_files[i].tenant,
            "status": nf_pkg_files[i].status}
            for i in range(len(nf_pkg_files))]

        vnf_insts = NfInstModel.objects.filter(package_id=csar_id)
        vnf_inst_info = [{"vnfInstanceId": vnf_inst.nfinstid,
                          "vnfInstanceName": vnf_inst.nf_name} for vnf_inst in vnf_insts]

        return [0, {"csarId": csar_id,
                    "packageInfo": pkg_info,
                    "imageInfo": img_info,
                    "vnfInstanceInfo": vnf_inst_info}]