1 # Copyright 2018 ZTE Corporation.
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.
16 from lcm.pub.database.models import PNFInstModel
17 from lcm.pub.exceptions import NSLCMException
18 from lcm.pub.msapi.sdc_run_catalog import query_pnf_descriptor
19 from lcm.ns_pnfs.biz.get_pnf import GetPnf
21 logger = logging.getLogger(__name__)
24 class CreatePnf(object):
25 def __init__(self, data):
26 self.pnfId = data.get("pnfId"),
27 self.pnfName = data.get("pnfName"),
28 self.pnfdId = data.get("pnfdId"),
29 self.pnfdInfoId = data.get("pnfdInfoId"),
30 self.pnfProfileId = data.get("pnfProfileId"),
31 self.cpInfo = data.get("cpInfo", "")
32 self.emsId = data.get("emsId", "")
33 self.nsInstances = data.get("nsInstances")
36 self.check_pnfd_valid()
39 self.create_pnf_inst()
40 logger.debug("CreatePnf::do_biz::pnfId=%s" % self.pnfId)
41 return GetPnf({"pnfId": self.pnfId}, True).do_biz()
43 def check_pnfd_valid(self):
44 pnf_package_info = query_pnf_descriptor({"pnfId": self.pnfdInfoId})
45 if not pnf_package_info:
46 raise NSLCMException("Pnfd(%s) does not exist." % self.pnfdInfoId)
48 def build_cpInfo(self):
52 def build_emsId(self):
56 def create_pnf_inst(self):
57 pnfInstances = PNFInstModel.objects.filter(pnfId=self.pnfId)
59 if not pnfInstances.filter(nsInstances__contains=self.nsInstances):
60 for pnfInstance in pnfInstances:
61 new_nsInstances = pnfInstance.nsInstances + "," + self.nsInstances
62 pnfInstance.update(nsInstances=new_nsInstances)
64 PNFInstModel(pnfId=self.pnfId,
67 pnfdInfoId=self.pnfdInfoId,
68 pnfProfileId=self.pnfProfileId,
71 nsInstances=self.nsInstances).save()