Django Service Templates

With service templates is possible to do:

  • Store your templates in database.
  • Connect your templates with context.
  • Render templates with Jinja2

Heat example

from dbtemplates import Template
from django_service_templates.models import ServiceTemplate

class HeatTemplate(ServiceTemplate):

    def heat(self):
        return get_heat_client(**self.get_context())

    def stack_name(self):
        return slugify(self.label)

    def heat_kwargs(self):
        return {
            'stack_name': self.stack_name,
            'disable_rollback': True,
            'parameters': self.clean_kwargs(),
            'template': self.get_content(),
            'environment': {}

    def stack_create(self):

            response = self.heat.stacks.create(**self.heat_kwargs)
        except Exception as e:
            raise e

        return response
dbtemplate = Template.objects.create(name='My Jinja2 Template', content='{{ name }}')

heat_template = HeatTemplate.objects.create(template=dbtemplate, context={'name': 'My name'})


> 'My name'



Full Example with Reclass

Read More