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')
26 class InterfacesDef(StatefulEntityType):
27 '''TOSCA built-in interfaces type.'''
29 def __init__(self, node_type, interfacetype,
30 node_template=None, name=None, value=None):
31 self.ntype = node_type
32 self.node_template = node_template
33 self.type = interfacetype
36 self.implementation = None
39 if interfacetype == LIFECYCLE_SHORTNAME:
40 interfacetype = LIFECYCLE
41 if interfacetype == CONFIGURE_SHORTNAME:
42 interfacetype = CONFIGURE
44 self.defs = self.TOSCA_DEF[interfacetype]
46 if isinstance(self.value, dict):
47 for i, j in self.value.items():
48 if i == IMPLEMENTATION:
49 self.implementation = j
53 what = ('"interfaces" of template "%s"' %
54 self.node_template.name)
55 ExceptionCollector.appendException(
56 UnknownFieldError(what=what, field=i))
58 self.implementation = value
61 def lifecycle_ops(self):
63 if self.type == LIFECYCLE:
67 def configure_ops(self):
69 if self.type == CONFIGURE:
74 for name in list(self.defs.keys()):