Merge "netsted template validate type error"
[parser.git] / tosca2heat / tosca-parser / toscaparser / groups.py
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
18 SECTIONS = (TYPE, METADATA, DESCRIPTION, PROPERTIES, TARGETS, INTERFACES) = \
19            ('type', 'metadata', 'description',
20             'properties', 'members', 'interfaces')
21
22
23 class Group(EntityTemplate):
24
25     def __init__(self, name, group_templates, member_nodes, custom_defs=None):
26         super(Group, self).__init__(name,
27                                     group_templates,
28                                     'group_type',
29                                     custom_defs)
30         self.name = name
31         self.tpl = group_templates
32         self.meta_data = None
33         if self.METADATA in self.tpl:
34             self.meta_data = self.tpl.get(self.METADATA)
35             validateutils.validate_map(self.meta_data)
36         self.member_nodes = member_nodes
37         self._validate_keys()
38
39     @property
40     def members(self):
41         return self.entity_tpl.get('members')
42
43     @property
44     def description(self):
45         return self.entity_tpl.get('description')
46
47     def get_member_nodes(self):
48         return self.member_nodes
49
50     def _validate_keys(self):
51         for key in self.entity_tpl.keys():
52             if key not in SECTIONS:
53                 ExceptionCollector.appendException(
54                     UnknownFieldError(what='Groups "%s"' % self.name,
55                                       field=key))