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
5 # http://www.apache.org/licenses/LICENSE-2.0
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
13 from toscaparser.common.exception import ExceptionCollector
14 from toscaparser.common.exception import UnknownFieldError
15 from toscaparser.elements.statefulentitytype import StatefulEntityType
17 SECTIONS = (LIFECYCLE, CONFIGURE, LIFECYCLE_SHORTNAME,
18 CONFIGURE_SHORTNAME) = \
19 ('tosca.interfaces.node.lifecycle.Standard',
20 'tosca.interfaces.relationship.Configure',
21 'Standard', 'Configure')
23 INTERFACEVALUE = (IMPLEMENTATION, INPUTS) = ('implementation', 'inputs')
25 INTERFACE_DEF_RESERVED_WORDS = ['type', 'inputs', 'derived_from', 'version',
29 class InterfacesDef(StatefulEntityType):
30 '''TOSCA built-in interfaces type.'''
32 def __init__(self, node_type, interfacetype,
33 node_template=None, name=None, value=None):
34 self.ntype = node_type
35 self.node_template = node_template
36 self.type = interfacetype
39 self.implementation = None
42 if interfacetype == LIFECYCLE_SHORTNAME:
43 interfacetype = LIFECYCLE
44 if interfacetype == CONFIGURE_SHORTNAME:
45 interfacetype = CONFIGURE
46 if hasattr(self.ntype, 'interfaces') \
47 and self.ntype.interfaces \
48 and interfacetype in self.ntype.interfaces:
49 interfacetype = self.ntype.interfaces[interfacetype]['type']
51 if self.node_template and self.node_template.custom_def \
52 and interfacetype in self.node_template.custom_def:
53 self.defs = self.node_template.custom_def[interfacetype]
55 self.defs = self.TOSCA_DEF[interfacetype]
57 if isinstance(self.value, dict):
58 for i, j in self.value.items():
59 if i == IMPLEMENTATION:
60 self.implementation = j
64 what = ('"interfaces" of template "%s"' %
65 self.node_template.name)
66 ExceptionCollector.appendException(
67 UnknownFieldError(what=what, field=i))
69 self.implementation = value
72 def lifecycle_ops(self):
74 if self.type == LIFECYCLE:
78 def configure_ops(self):
80 if self.type == CONFIGURE:
85 for name in list(self.defs.keys()):