Using Contrail Resources in Heat Templates

Using the Contrail Heat Template

Heat is the orchestration engine of the OpenStack program. Heat enables launching multiple cloud applications based on templates that are comprised of text files.

Introduction to Heat

A Heat template describes the infrastructure for a cloud application, such as networks, servers, floating IP addresses, and the like, and can be used to manage the entire life cycle of that application.

When the application infrastructure changes, the Heat templates can be modified to automatically reflect those changes. Heat can also delete all application resources if the system is finished with an application.

Heat templates can record the relationships between resources, for example, which networks are connected by means of policy enforcements, and consequently call OpenStack REST APIs that create the necessary infrastructure, in the correct order, needed to launch the application managed by the Heat template.

Heat Architecture

Heat is implemented by means of Python applications, including the following:

Support for Heat Version 2 Resources

Starting with Contrail Release 3.0.2, Contrail Heat resources and templates are autogenerated from the Contrail schema, using Heat Version 2 resources. Contrail Release 3.0.2 is the minimum required version for using Heat with Contrail in 3.x releases. The Contrail Heat Version 2 resources are of the following hierarchy: OS::ContrailV2::<ResourceName>.

The generated resources and templates are part of the Contrail Python package, and are located in the following directory in the target installation:


The heat/ directory has the following subdirectories:

The following contains a list of all the generated plug-in resources that are supported by contrail-heat :

Deprecation of Heat Version 1 Resources

Heat Version 1 resources within the hierarchy OS::Contrail::<ResourceName> are being deprecated, and you should not create new service templates using the Heat Version 1 templates.

Heat Version 2 with Service Templates and Port Tuple Sample Workflow

With Contrail service templates Version 2, the user can create ports and bind them to a virtual machine (VM)-based service instance, by means of a port-tuple object. All objects created with the Version 2 service template are directly visible to the Contrail Heat engine, and are directly managed by Heat.


The following shows the basic workflow steps for creating a port tuple and service instance that will be managed by Heat:

  1. Create a service template. Select 2 in the Version field.
  2. Create a service instance for the service template just created.
  3. Create a port-tuple object.
  4. Create ports, using Nova VM launch or without a VM launch.
  5. Label each port as left, right, mgmt, and so on, and add the ports to the port-tuple object.

    Use a unique label for each of the ports in a single port tuple. The labels named left and right are used for forwarding.

  6. Link the port tuple to a service instance.
  7. Launch the service instance.

Example: Creating a Service Template Using Heat

The following is an example of how to create a service template using Heat.


  1. Define a template to create the service template.
    heat_template_version:  2013-‐05-‐23
    description: >
       HOT template to create a service template
          type: string
          description: Name of service template     
          type: string
          description: service mode
          type: string   
          description: service type
          type: string
          description: Name of the image
          type: string     
          description: Flavor
          type: string
          description: List of interface types
          type: string
          description: List of shared ip enabled-‐disabled
          type: string
          description: List of static routes enabled-‐disabled
          type: OS::ContrailV2::ServiceTemplate
             name: { get_param: name }
             service_mode: { get_param: mode }
             service_type: { get_param: type }
             image_name: { get_param: image }  
             flavor: { get_param: flavor }
             service_interface_type_list: { "Fn::Split" : [ ",", Ref: service_interface_type_list ] }
             shared_ip_list: { "Fn::Split" : [ ",", Ref: shared_ip_list ] }
             static_routes_list: { "Fn::Split" : [ ",", Ref: static_routes_list ] }
             description: FQ name of the service template
             value: { get_attr: [ service_template, fq_name] }
  2. Create an environment file to define the values to put in the variables in the template file.
       name: contrail_svc_temp
       mode: transparent
       type: firewall
       image: cirros
       flavor: m1.tiny
       service_interface_type_list: management,left,right,other
       shared_ip_list: True,True,False,False     
       static_routes_list: False,True,False,False
  3. Create the Heat stack by launching the template and the environment file, using the following command:

    heat stack create stack1 –f service_template.yaml –e service_template.env

    OR use this command for recent versions of OpenStack

    openstack stack create -e <env-file-name> -t <template-file-name> <stack-name>