Creating an Orchestration Template

Templates are used to define an infrastructure, such as resources and relationships between resources, and apply it to a cloud application.

Prerequisites—see Implementing Orchestration for information on preparing your environment to access the Orchestration service from the CLI.

Minimally, a template includes the template version, template description, and at least one resource definition:

  • heat_template_version—the version of the template determines the validation of formatting and features
  • description—useful for describing the purpose of the template
  • resources—declaration of resources for the stack to deploy
  • properties—a sub-section of a resource that identifies details about the resource, such as name:

The following example template is in a YAML format and launches a small-sized, ubuntu instance on an existing sample network:

heat_template_version: 2015-04-30

description: Template to launch an instance

resources:
# instances
  sample_instance:
    type: OS::Nova::Server
    properties:
      flavor: m1.small
      image: ubuntu-16.04.1-server-amd64
      name: sampleStackInstance
      key_name: my_key
      networks: 
         - network: sampleStackNetwork

In addition to version, description, and resources, templates can contain the following definition sections:

  • parameter_groups—allows you to group the input parameters and control the order of input
  • parameters—input parameters required for deployment
  • outputs—output parameters provided after deployment
  • conditions—statements used to restrict when a resource is created or when a property is defined

Use Case: Use a basic template to launch an instance:

  1. Create a stack from the template. You can select Launch Stack in the Dashboard under Project > Orchestration or you can use the CLI.

    $ openstack stack create sampleStackInstance -t sampleTemplate.yaml
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | id                  | <stack_id>                           |
    | stack_name          | sampleStackInstance                  |
    | description         | Template to launch an instance       |
    | creation_time       | 2017-06-06T17:11:25                  |
    | updated_time        | None                                 |
    | stack_status        | CREATE_IN_PROGRESS                   |
    | stack_status_reason | Stack CREATE started                 |
    +---------------------+--------------------------------------+
    
  2. Check the stack_status and stack_status_reason fields for stack progress. You can also find this information in the Dashboard on the Stacks tab under Project > Orchestration.

    $ openstack stack show sampleStackInstance
    +-----------------------+------------------------------------+
    | Field                 | Value                              |
    +-----------------------+------------------------------------+
    | id                    | <stack_id>                         |
    | stack_name            | sampleStackInstance                |
    | description           | Template to launch an instance     |
    | creation_time         | 2017-06-06T17:11:25                |
    | updated_time          | None                               |
    | stack_status          | CREATE_COMPLETE                    |
    | stack_status_reason   | Stack CREATE completed successfully| 
    ...
    
  3. Check the status of the instance created by the template.

    $ openstack server show sampleStackInstance
    +-----------------------------+------------------------------------------+
    | Field                       | Value                                    |
    +-----------------------------+------------------------------------------+
    | OS-DCF:diskConfig           | MANUAL                                   |
    | OS-EXT-AZ:availability_zone | <AZ>                                     |
    | OS-EXT-STS:power_state      | Running                                  |
    | OS-EXT-STS:task_state       | None                                     |
    | OS-EXT-STS:vm_state         | active                                   |
    | OS-SRV-USG:launched_at      | 2017-06-06T17:11:32.000000               |
    | OS-SRV-USG:terminated_at    | None                                     |
    | accessIPv4                  |                                          |
    | accessIPv6                  |                                          |
    | addresses                   | sampleStackNetwork =10.0.7.6             |
    | config_drive                |                                          |
    | created                     | 2017-06-06T17:11:27Z                     |
    | flavor                      | m1.small (2)                             |
    | hostId                      | <host_id>                                |
    | id                          | <instance_id>                            |
    | image                       | ubuntu-16.04.1-server-amd64 (<image_id>) |
    | key_name                    | my_key                                   |
    | name                        | sampleStackInstance                      |
    | progress                    | 0                                        |
    | project_id                  | <project_id>                             |
    | properties                  |                                          |
    | security_groups             | name='default'                           |
    | status                      | ACTIVE                                   |
    | updated                     | 2017-06-06T17:11:32Z                     |
    | user_id                     | <user_id>                                |
    | volumes_attached            |                                          |
    +-----------------------------+------------------------------------------+
    

Note
To learn how to create robust templates for Metacloud, see the following topics: