Creating and Managing Stacks

A stack consists of Metacloud resources defined in a Heat Orchestration Template.

To build a stack from a template source:

$ openstack stack create <STACK_NAME> -t <TEMPLATE_FILEorURL>
+---------------------+---------------------------------+
| Field               | Value                           |
+---------------------+---------------------------------+
| id                  | <stack_id>                      |
| stack_name          | <stack_name>                    |
| description         | Sample Orchestration Template   |
| creation_time       | 2017-02-06T18:26:45             |
| updated_time        | None                            |
| stack_status        | CREATE_IN_PROGRESS              |
| stack_status_reason | Stack CREATE started            |
+---------------------+---------------------------------+

The --dry-run option tests the validity of the template source without building a stack. If the validation fails, the response returns parsing, property, or argument errors that can help troubleshoot your template.

Template parameters allow you to customize your deployment. You can provide additional information to the stack create command using the --parameter option. The following example uses a key_pair parameter to inject a specific key when creating the stack.

$ openstack stack create <STACK_NAME> -t <TEMPLATE_FILEorURL> --parameter "key_pair=myKey"

Although you can specify more than one parameter for the stack create command, you may need to pass in a larger set of parameters. The -e option allows you to provide an environment file containing a set of parameters that override the resource implementations of the stack.

$ openstack stack create <STACK_NAME> -t <TEMPLATE_FILEorURL> -e <ENVIRONMENT_FILE>

Managing Stacks

You can manage stacks in the CLI using the following commands:

Action Command
List of stacks $ openstack stack list
Show stack details $ openstack stack show
Delete a stack $ openstack stack delete <STACK_NAME>
List stack resources $ openstack stack resource list <STACK_NAME>
Show resource details $ openstack stack resource show <STACK_NAME> <RESOURCE_NAME>
Show resource metadata $ openstack stack resource metadata <STACK_NAME> <RESOURCE_NAME>
Show stack events $ openstack stack event list <STACK_NAME>
Show event details $ openstack stack event show <STACK_NAME> <RESOURCE_NAME> <EVENT_NAME>

To update a stack using a new parameter:

$ openstack stack update <STACK_NAME> -t sample.yaml --parameter "image=ubuntu"
+---------------------+---------------------------------+
| Field               | Value                           |
+---------------------+---------------------------------+
| id                  | <stack_id>                      |
| stack_name          | <stack_name>                    |
| description         | Sample Orchestration Template   |
| creation_time       | 2017-02-07T20:40:08             |
| updated_time        | 2017-02-07T22:07:57             |
| stack_status        | UPDATE_IN_PROGRESS              |
| stack_status_reason | Stack UPDATE started            |
+---------------------+---------------------------------+

Note
If you receive a Stack Status of CREATE_FAILED or UPDATE_FAILED, check the event list for the stack to see if the error relates to a specific resource.

Use Case: Solve the CREATE_FAILED status with stack event list

This is an example of checking the event list after the stack create fails.

  1. Check the stack list for status.

    $ openstack stack list
    +-----------------+------------------+---------------+---------------------+---------------------+
    | ID              | Stack Name       | Stack Status  | Creation Time       | Updated Time        |
    +-----------------+------------------+---------------+---------------------+---------------------+
    | <stack_id>      | anotherstacktest | CREATE_FAILED | 2017-02-08T22:15:38 | None                |
    +-----------------+------------------+---------------+---------------------+---------------------+
    
  2. View the event list to see where the create began to fail.

    $ openstack stack event list anotherstacktest
    2017-02-08 22:15:38 [anotherstacktest]: CREATE_IN_PROGRESS  Stack CREATE started
    2017-02-08 22:15:38 [anotherstacktest.test_network]: CREATE_IN_PROGRESS  state changed
    2017-02-08 22:15:38 [anotherstacktest.test_router]: CREATE_IN_PROGRESS  state changed
    2017-02-08 22:15:39 [anotherstacktest.test_router]: CREATE_COMPLETE  state changed
    2017-02-08 22:15:39 [anotherstacktest.test_network]: CREATE_COMPLETE  state changed
    2017-02-08 22:15:39 [anotherstacktest.test_subnet]: CREATE_IN_PROGRESS  state changed
    2017-02-08 22:15:41 [anotherstacktest.test_subnet]: CREATE_COMPLETE  state changed
    2017-02-08 22:15:41 [anotherstacktest.router_interface]: CREATE_IN_PROGRESS  state changed
    2017-02-08 22:15:42 [anotherstacktest.server_port]: CREATE_IN_PROGRESS  state changed
    2017-02-08 22:15:43 [anotherstacktest.server_port]: CREATE_FAILED  PhysicalResourceNotFound: resources.server_port: The Resource (dfault) could not be found.
    2017-02-08 22:15:44 [anotherstacktest.router_interface]: CREATE_COMPLETE  state changed
    2017-02-08 22:15:44 [anotherstacktest]: CREATE_FAILED  Resource CREATE failed: PhysicalResourceNotFound: resources.server_port: The Resource (dfault) could not be found.
    

    Based on the above event list, there is a resource in the server_port definition that cannot be found. In this case, the resource “dfault” is misspelled. It should be “default”.

  3. Fix the template and update the stack.

    $ openstack stack update anotherstacktest -t test.yaml 
    +-----------------+------------------+-----------------+---------------------+---------------------+
    | ID              | Stack Name       | Stack Status    | Creation Time       | Updated Time        |
    +-----------------+------------------+-----------------+---------------------+---------------------+
    | <stack_id>      | anotherstacktest | UPDATE_COMPLETE | 2017-02-08T22:15:38 | 2017-02-08T22:27:34 |
    +-----------------+------------------+-----------------+---------------------+---------------------+