genericparser seed code
[modeling/etsicatalog.git] / genericparser / pub / utils / toscaparsers / pnfmodel.py
1 # Copyright 2018 ZTE Corporation.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import functools
16 import logging
17 from genericparser.pub.utils.toscaparsers.basemodel import BaseInfoModel
18 logger = logging.getLogger(__name__)
19
20
21 class PnfdInfoModel(BaseInfoModel):
22
23     def __init__(self, path, params):
24         super(PnfdInfoModel, self).__init__(path, params)
25
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),
30                             tosca.nodetemplates)
31         self.basepath = self.get_base_path(tosca)
32         self.pnf = {}
33         self.get_substitution_mappings(tosca)
34         self.get_all_cp(nodeTemplates)
35
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['properties']
41
42     def get_all_cp(self, nodeTemplates):
43         self.pnf['ExtPorts'] = []
44         for node in nodeTemplates:
45             if self.isPnfExtPort(node):
46                 cp = {}
47                 cp['id'] = node['name']
48                 cp['type'] = node['nodeType']
49                 cp['properties'] = node['properties']
50                 self.pnf['ExtPorts'].append(cp)
51
52     def isPnfExtPort(self, node):
53         return node['nodeType'].find('tosca.nodes.nfv.PnfExtPort') >= 0