def fetch(self, vnfPkgId, artifactPath):
     """
     Fetch artifact by given vnf package id and the path of artifact
     :param vnfPkgId:
     :param artifactPath:
     :return:
     """
     logger.debug("FetchVnfPkgArtifact--get--single--artifact--biz::>"
                  "ID: %s path: %s" % (vnfPkgId, artifactPath))
     vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnfPkgId)
     if not vnf_pkg.exists():
         err_msg = "NF Package (%s) doesn't exists." % vnfPkgId
         raise ResourceNotFoundException(err_msg)
     vnf_pkg = vnf_pkg.get()
     local_path = vnf_pkg.localFilePath
     if local_path.endswith(".csar") or local_path.endswith(".zip"):
         vnf_extract_path = fileutil.unzip_csar_to_tmp(local_path)
         artifact_path = fileutil.get_artifact_path(vnf_extract_path,
                                                    artifactPath)
         if not artifact_path:
             raise ArtifactNotFoundException("Can't find artifact %s" %
                                             artifactPath)
         with open(artifact_path, 'rt') as f:
             file_content = f.read()
     else:
         raise ArtifactNotFoundException(
             "NF Package format is not csar or zip")
     return file_content
Exemplo n.º 2
0
 def query_single(self, pnfd_info_id):
     """
     Query PNF package by id
     :param pnfd_info_id:
     :return:
     """
     pnf_pkgs = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id)
     if not pnf_pkgs.exists():
         logger.error('PNFD(%s) does not exist.' % pnfd_info_id)
         raise ResourceNotFoundException('PNFD(%s) does not exist.' % pnfd_info_id)
     return self.fill_response_data(pnf_pkgs[0])
Exemplo n.º 3
0
 def query_single(self, vnf_pkg_id):
     """
     Query a single VNF package by given id
     :param vnf_pkg_id: The id of VNF package
     :return: VNF pckage info
     """
     nf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id)
     if not nf_pkg.exists():
         logger.error('VNF package(%s) does not exist.' % vnf_pkg_id)
         raise ResourceNotFoundException('VNF package(%s) does not exist.' %
                                         vnf_pkg_id)
     return fill_response_data(nf_pkg[0])
Exemplo n.º 4
0
 def query_single(self, nsd_info_id):
     """
     Query NS package by id
     :param nsd_info_id:
     :return:
     """
     ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id)
     if not ns_pkgs.exists():
         logger.error('NSD(%s) does not exist.' % nsd_info_id)
         raise ResourceNotFoundException('NSD(%s) does not exist.' %
                                         nsd_info_id)
     return self.fill_resp_data(ns_pkgs[0])
Exemplo n.º 5
0
    def download(self, vnf_pkg_id, file_range):
        logger.info('Start to download VNF package(%s)...' % vnf_pkg_id)
        nf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id)
        if not nf_pkg.exists():
            logger.error('VNF package(%s) does not exist.' % vnf_pkg_id)
            raise ResourceNotFoundException('VNF package(%s) does not exist.' %
                                            vnf_pkg_id)
        if nf_pkg[0].onboardingState != const.PKG_STATUS.ONBOARDED:
            raise CatalogException("VNF package (%s) is not on-boarded" %
                                   vnf_pkg_id)

        local_file_path = nf_pkg[0].localFilePath
        start, end = parse_file_range(local_file_path, file_range)
        logger.info('VNF package (%s) has been downloaded.' % vnf_pkg_id)
        return read(local_file_path, start, end)
Exemplo n.º 6
0
    def download(self, pnfd_info_id):
        """
        Download PNF package file by id
        :param pnfd_info_id:
        :return:
        """
        logger.info('Start to download PNFD(%s)...' % pnfd_info_id)
        pnf_pkgs = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id)
        if not pnf_pkgs.exists():
            logger.error('PNFD(%s) does not exist.' % pnfd_info_id)
            raise ResourceNotFoundException('PNFD(%s) does not exist.' % pnfd_info_id)
        if pnf_pkgs[0].onboardingState != PKG_STATUS.ONBOARDED:
            logger.error('PNFD(%s) is not ONBOARDED.' % pnfd_info_id)
            raise CatalogException('PNFD(%s) is not ONBOARDED.' % pnfd_info_id)

        local_file_path = pnf_pkgs[0].localFilePath
        start, end = 0, os.path.getsize(local_file_path)
        logger.info('PNFD(%s) has been downloaded.' % pnfd_info_id)
        return read(local_file_path, start, end)
Exemplo n.º 7
0
    def download_vnfd(self, vnf_pkg_id):
        """
        Download VNFD for given id
        :param vnf_pkg_id: The id of VNF package
        :return: VNFD
        """
        logger.info('Start to download VNFD of VNF package(%s)...' %
                    vnf_pkg_id)
        nf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id)
        if not nf_pkg.exists():
            logger.error('VNF package(%s) does not exist.' % vnf_pkg_id)
            raise ResourceNotFoundException('VNF package(%s) does not exist.' %
                                            vnf_pkg_id)
        if nf_pkg[0].onboardingState != const.PKG_STATUS.ONBOARDED:
            raise CatalogException("VNF package (%s) is not on-boarded" %
                                   vnf_pkg_id)

        vnfd_zip_file = self.creat_vnfd(vnf_pkg_id, nf_pkg[0].localFilePath)
        logger.info('VNFD of VNF package (%s) has been downloaded.' %
                    vnf_pkg_id)
        return read(vnfd_zip_file, 0, os.path.getsize(vnfd_zip_file))
Exemplo n.º 8
0
    def download(self, nsd_info_id, file_range):
        """
        Download NS package file
        :param nsd_info_id:
        :param file_range:
        :return:
        """
        logger.info('Start to download NSD(%s)...' % nsd_info_id)
        ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id)
        if not ns_pkgs.exists():
            logger.error('NSD(%s) does not exist.' % nsd_info_id)
            raise ResourceNotFoundException('NSD(%s) does not exist.' %
                                            nsd_info_id)
        if ns_pkgs[0].onboardingState != const.PKG_STATUS.ONBOARDED:
            logger.error('NSD(%s) is not ONBOARDED.' % nsd_info_id)
            raise CatalogException('NSD(%s) is not ONBOARDED.' % nsd_info_id)

        local_file_path = ns_pkgs[0].localFilePath
        start, end = parse_file_range(local_file_path, file_range)
        logger.info('NSD(%s) has been downloaded.' % nsd_info_id)
        return read(local_file_path, start, end)