Skip to content

Commit

Permalink
Moving translate same logic in different method
Browse files Browse the repository at this point in the history
Change-Id: I9870377fb41e6da1c7ed15d390a82216c4306109
  • Loading branch information
Sergey Kraynev committed Nov 21, 2014
1 parent 5b09e45 commit d138a7a
Showing 1 changed file with 33 additions and 47 deletions.
80 changes: 33 additions & 47 deletions heat/engine/hot/template.py
Expand Up @@ -119,68 +119,54 @@ def _translate(value, mapping, err_msg=None):
else:
raise ke

def _translate_resources(self, resources):
"""Get the resources of the template translated into CFN format."""
HOT_TO_CFN_ATTRS = {'type': 'Type',
'properties': 'Properties',
'metadata': 'Metadata',
'depends_on': 'DependsOn',
'deletion_policy': 'DeletionPolicy',
'update_policy': 'UpdatePolicy'}

cfn_resources = {}
for resource_name, attrs in six.iteritems(resources):
cfn_resource = {}
def _translate_section(self, section, sub_section, data, mapping):
cfn_objects = {}
obj_name = section[:-1]
err_msg = _('"%%s" is not a valid keyword inside a %s '
'definition') % obj_name
for name, attrs in six.iteritems(data):
cfn_object = {}

if not attrs:
message = _('Each resource must '
'contain a type key.')
args = {'object_name': obj_name, 'sub_section': sub_section}
message = _('Each %(object_name)s must contain a '
'%(sub_section)s key.') % args
raise exception.StackValidationFailed(message=message)
try:
for attr, attr_value in six.iteritems(attrs):
cfn_attr = self._translate(attr, HOT_TO_CFN_ATTRS,
_('"%s" is not a valid '
'keyword inside a resource '
'definition'))
cfn_resource[cfn_attr] = attr_value
cfn_attr = self._translate(attr, mapping, err_msg)
cfn_object[cfn_attr] = attr_value

cfn_resources[resource_name] = cfn_resource
cfn_objects[name] = cfn_object
except AttributeError:
message = _('"resources" must contain a map of resource maps. '
'Found a [%s] instead') % type(attrs)
message = _('"%(section)s" must contain a map of '
'%(obj_name)s maps. Found a [%(_type)s] '
'instead') % {'section': section,
'_type': type(attrs),
'obj_name': obj_name}
raise exception.StackValidationFailed(message=message)

return cfn_resources
return cfn_objects

def _translate_resources(self, resources):
"""Get the resources of the template translated into CFN format."""
HOT_TO_CFN_ATTRS = {'type': 'Type',
'properties': 'Properties',
'metadata': 'Metadata',
'depends_on': 'DependsOn',
'deletion_policy': 'DeletionPolicy',
'update_policy': 'UpdatePolicy'}

return self._translate_section('resources', 'type', resources,
HOT_TO_CFN_ATTRS)

def _translate_outputs(self, outputs):
"""Get the outputs of the template translated into CFN format."""
HOT_TO_CFN_ATTRS = {'description': 'Description',
'value': 'Value'}

cfn_outputs = {}

for output_name, attrs in six.iteritems(outputs):
cfn_output = {}

if not attrs:
message = _('Each output must '
'contain a value key.')
raise exception.StackValidationFailed(message=message)
try:
for attr, attr_value in six.iteritems(attrs):
cfn_attr = self._translate(attr, HOT_TO_CFN_ATTRS,
_('"%s" is not a valid '
'keyword inside an output '
'definition'))
cfn_output[cfn_attr] = attr_value

cfn_outputs[output_name] = cfn_output
except AttributeError:
message = _('"outputs" must contain a map of output maps. '
'Found a [%s] instead') % type(attrs)
raise exception.StackValidationFailed(message=message)

return cfn_outputs
return self._translate_section('outputs', 'value', outputs,
HOT_TO_CFN_ATTRS)

def param_schemata(self):
parameter_section = self.t.get(self.PARAMETERS)
Expand Down

0 comments on commit d138a7a

Please sign in to comment.