cb9c20d15a4b6295f7621aadac1ae795536445bb
[sdc/sdc-distribution-client.git] /
1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
2 #    not use this file except in compliance with the License. You may obtain
3 #    a copy of the License at
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #    Unless required by applicable law or agreed to in writing, software
8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 #    License for the specific language governing permissions and limitations
11 #    under the License.
12
13 from toscaparser.common.exception import ExceptionCollector
14 from toscaparser.common.exception import UnknownFieldError
15 from toscaparser.entity_template import EntityTemplate
16 from toscaparser.utils import validateutils
17 from org.openecomp.sdc.toscaparser.jython import JyGroup
18
19 SECTIONS = (TYPE, METADATA, DESCRIPTION, PROPERTIES, MEMBERS, INTERFACES) = \
20            ('type', 'metadata', 'description',
21             'properties', 'members', 'interfaces')
22
23
24 class Group(EntityTemplate, JyGroup):
25
26     def __init__(self, name, group_templates, member_nodes, custom_defs=None):
27         super(Group, self).__init__(name,
28                                     group_templates,
29                                     'group_type',
30                                     custom_defs)
31         self.name = name
32         self.tpl = group_templates
33         self.meta_data = None
34         if self.METADATA in self.tpl:
35             self.meta_data = self.tpl.get(self.METADATA)
36             validateutils.validate_map(self.meta_data)
37         self.member_nodes = member_nodes
38         self._validate_keys()
39
40     def getJyMembers(self):
41         return self.members
42
43     def getJyMetadata(self):
44         return self.meta_data
45
46     @property
47     def members(self):
48         return self.entity_tpl.get('members')
49
50     @property
51     def description(self):
52         return self.entity_tpl.get('description')
53
54     def get_member_nodes(self):
55         return self.member_nodes
56
57     def _validate_keys(self):
58         for key in self.entity_tpl.keys():
59             if key not in SECTIONS:
60                 ExceptionCollector.appendException(
61                     UnknownFieldError(what='Groups "%s"' % self.name,
62                                       field=key))