1 # Copyright (C) 2019 Verizon. All Rights Reserved
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from catalog.pub.database.models import VnfPackageModel
18 from catalog.pub.exceptions import ResourceNotFoundException, ArtifactNotFoundException
19 from catalog.pub.utils import fileutil
21 logger = logging.getLogger(__name__)
24 class FetchVnfPkgArtifact(object):
25 def fetch(self, vnfPkgId, artifactPath):
26 logger.debug("FetchVnfPkgArtifact--get--single--artifact--biz::>"
27 "ID: %s path: %s" % (vnfPkgId, artifactPath))
28 vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnfPkgId)
29 if not vnf_pkg.exists():
30 err_msg = "NF Package (%s) doesn't exists." % vnfPkgId
31 raise ResourceNotFoundException(err_msg)
32 vnf_pkg = vnf_pkg.get()
33 local_path = vnf_pkg.localFilePath
34 if local_path.endswith(".csar") or local_path.endswith(".zip"):
35 vnf_extract_path = fileutil.unzip_csar_to_tmp(local_path)
36 artifact_path = fileutil.get_artifact_path(vnf_extract_path, artifactPath)
38 raise ArtifactNotFoundException("Can't find artifact %s" % artifactPath)
39 with open(artifact_path, 'rt') as f:
40 file_content = f.read()
42 raise ArtifactNotFoundException("NF Package format is not csar or zip")