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.
17 from catalog.pub.utils.toscaparser.basemodel import BaseInfoModel
18 logger = logging.getLogger(__name__)
21 class PnfdInfoModel(BaseInfoModel):
23 def __init__(self, path, params):
24 super(PnfdInfoModel, self).__init__(path, params)
26 def parseModel(self, tosca):
27 self.metadata = self.buildMetadata(tosca)
28 self.inputs = self.buildInputs(tosca)
29 nodeTemplates = map(functools.partial(self.buildNode, tosca=tosca),
31 self.basepath = self.get_base_path(tosca)
33 self.get_substitution_mappings(tosca)
34 self.get_all_cp(nodeTemplates)
36 def get_substitution_mappings(self, tosca):
37 pnf_substitution_mappings = tosca.tpl['topology_template'].get('substitution_mappings', None)
38 if pnf_substitution_mappings:
39 self.pnf['type'] = pnf_substitution_mappings['node_type']
40 self.pnf['properties'] = pnf_substitution_mappings.get('properties', {})
42 def get_all_cp(self, nodeTemplates):
43 self.pnf['ExtPorts'] = []
44 for node in nodeTemplates:
45 if self.isPnfExtPort(node):
47 cp['id'] = node['name']
48 cp['type'] = node['nodeType']
49 cp['properties'] = node['properties']
50 self.pnf['ExtPorts'].append(cp)
52 def isPnfExtPort(self, node):
53 return node['nodeType'].find('tosca.nodes.nfv.PnfExtPort') >= 0