Create and manage stacks#

You can use the examples in the following sections to create and manage stacks by using Cloud Orchestration API operations.

Before running the examples, review the Cloud Orchestration concepts to understand the API workflow, messaging patterns, and use cases.

Note

These examples use the $AUTH_URL, $USERNAME, $TENANT_ID, $REGION_NAME, and $PASSWORD environment variables to specify the API endpoint, Rackspace Cloud username, tenant ID,regional endpoint, and Rackspace Cloud password values for accessing the service. Make sure you configure these variables before running the code samples.

Creating a simple stack for a cloud server#

Assume that you want to create a simple stack that defines a single cloud server. Use a text editor such as nano or vi to create the following heat orchestration template (HOT) file and then save it as single_server.template:

heat_template_version: 2014-10-16

resources:
  compute_instance:
    type: "OS::Nova::Server"
    properties:
      flavor: 1 GB General Purpose v1
      image: CentOS 6 (PV)
      name: Single Server Stack

outputs:
  public_ip:
    description: public IP address of the deployed compute instance
    value: { get_attr: [compute_instance, accessIPv4] }

Note

  • If you enter in the template example text manually, remember to use a two-space indent (not Tab) for each subsection of the template.

This template has a resources section that creates a single cloud server with a 1 GB General Purpose v1 flavor size (which identifies a particular combination of memory capacity and priority for CPU time). It has CentOS 6 installed, and is called Single Server Stack.

Note

  • You can find the information for resources types either by looking it up or by using the API.

  • You can look up the names for the supported attributes in the Supported resources reference`_ .

  • To find the various types of supported template resources, use the list resource types API operation (GET /resoure_types). The cURL command for this operation is as follows. Be sure to use the correct values for your X-Auth-Token and tenant_id:

    curl -i -X GET -H "X-Auth-Token: $AUTH_TOKEN" \
         -H "X-Project-Id: $TENANT_ID" \
         -H "Content-Type: application/json" \
         -H "Accept: application/json"  $API_ENDPOINT/resource_types
    

This template also has an outputs section. Outputs are used to provide important information to users, such as the IP address for the server in this example. The output in this example is named public_ip. Its value is set by calling the intrinsic function get_attr, and passing it the name of the cloud server resource (compute_instance) and the attribute whose value is needed (accessIPv4). You will see shortly how this public IP address is displayed to the user. You can find out more about intrinsic functions in the Supported resources reference .

You can send the request to create a stack by using either of the following methods:

Create a stack by using the heat client#

Issue the following command, which includes the name of the template file that you just created:

heat stack-create Single-Server-Stack --template-file single_server.template

You should get a list of your stacks, including one with a stack_name of Single-Server-Stack with a stack_status of CREATE_IN_PROGRESS. For example:

+--------------------------------------+---------------------+--------------------+----------------------+
| id                                   | stack_name          | stack_status       | creation_time        |
+--------------------------------------+---------------------+--------------------+----------------------+
| 3bd2c230-b02a-45d8-9f16-88c9a9f64d2d | Single-Server-Stack | CREATE_IN_PROGRESS | 2014-01-24T20:12:47Z |
+--------------------------------------+---------------------+--------------------+----------------------+

Create a stack by using cURL#

Use the create stack API operation (/stacks) in the cURL request, as shown in the following example:

curl -i -X POST \
-H "Accept: application/json" \
-H "Content-Type: application/json"  \
-H "X-Auth-Token: $AUTH_TOKEN" \
-H "X-Project-Id: $TENANT_ID" \
   '{
      "stack_name": "Single-Server-Stack",
      "disable_rollback": true,
      "parameters": {},
      "template": "heat_template_version: 2014-10-16\n \nresources:\n  compute_instance:  \n    type: \"OS::Nova::Server\"\n    properties:\n      flavor: 1 GB General Purpose v1\n      image: CentOS 6 (PV)\n      name: Single Server Stack\n       \noutputs:\n  public_ip:\n    description: public IP address of the deployed compute instance\n    value: { get_attr: [compute_instance, accessIPv4] }      \n\n\n",
      "timeout_mins": 60
    }' \
    $API_ENDPOINT/stacks

We recommend that you produce the value for the template attribute by executing the following heat client command:

$ heat --debug stack-create Single-Server-Stack --template-file single_server.template

Copy the value for the template attribute from the cURL command that is shown in the output from the preceding command.

Although you can manually produce the required value for the template attribute from the template file, to do so you must replace every line break with n, escape any double quotation marks (for example type: "OS::Nova::Server"), and maintain correct spacing to indicate the correct nesting level for each block in the template. So it is easier to use the template value in the generated cURL command from the –debug output.

Note that executing the stack-create heat client command actually creates the stack, so you must delete that stack before you issue the cURL command to create a stack.

As an alternative, you can also just use the entire cURL command generated by the –debug output rather than the cURL command shown in the previous example.

The following example shows the response:

HTTP/1.1 201 Created
content-length: 192
via: 1.0 Repose (Repose/2.13.0)
server: nginx/1.2.1
connection: keep-alive
location: https://ord.orchestration.api.rackspacecloud.com/v1/1234/stacks/Single-Server-Stack/3bd2c230-b02a-45d8-9f16-88c9a9f64d2d
date: Thu, 23 Jan 2014 19:38:09 GMT
content-type: application/json

{
   "stack": {
    "id": "3bd2c230-b02a-45d8-9f16-88c9a9f64d2d",
    "links": [
      {
        "href": "http://ord.orchestration.api.rackspacecloud.com/v1/1234/stacks/Single-Server-Stack/3bd2c230-b02a-45d8-9f16-88c9a9f64d2d",
        "rel": "self"
      }
    ]
  }
 }

The example shows that the stack was created and has the ID 3bd2c230-b02a-45d8-9f16-88c9a9f64d2d.

Notice that there is a self link that contains a versioned link to the stack resource. Use this link in cases where the link will be followed immediately.

Listing stacks#

Now you can list stacks and confirm that your stack was created.

You can send the request to list stack information by using either of the following methods:

List stacks by using the heat client#

Issue the following command:

heat stack-list

The command returns the id, stack_name, stack_status, and creation_time for each of your stacks, as shown in the following example:

+--------------------------------------+---------------------+-----------------+----------------------+
| id                                   | stack_name          | stack_status    | creation_time        |
+--------------------------------------+---------------------+-----------------+----------------------+
| 3bd2c230-b02a-45d8-9f16-88c9a9f64d2d | Single-Server-Stack | CREATE_COMPLETE | 2014-01-23T19:41:05Z |
+--------------------------------------+---------------------+-----------------+----------------------+

In this case, you have just the Single-Server-Stack and its stack_status is CREATE_COMPLETE.

Note

If you issue the stack-list command before the operation of creating the stack is complete, you might see the stack_status value of CREATE_IN_PROGRESS. If you wait a minute, and then reissue the command, you should see that the stack has been created.

List stacks by using cURL#

Execute the cURL request for list stacks:

curl -s \
-H "X-Auth-Token: $AUTH_TOKEN" \
-H "X-Project-Id: $TENANT_ID" \
$API_ENDPOINT/stacks | python -m json.tool

The following example shows the response:

{
  "stacks": [
    {
      "description": "No description",
      "links": [
        {
          "href": "https://ord.orchestration.api.rackspacecloud.com/v1/1234/stacks/Single-Server-Stack/bd2c230-b02a-45d8-9f16-88c9a9f64d2d",
          "rel": "self"
        }
      ],
      "stack_status_reason": "Stack CREATE completed successfully",
      "stack_name": "Single-Server-Stack",
      "creation_time": "2014-01-23T19:41:05Z",
      "updated_time": null,
      "stack_status": "CREATE_COMPLETE",
      "id": "bd2c230-b02a-45d8-9f16-88c9a9f64d2d"
    }
  ]
}

You can see that your stack named Single-Server-Stack with the id bd2c230-b02a-45d8-9f16-88c9a9f64d2d was successfully created.

Note

If you issue the stack-list command before the operation of creating the stack is complete, you might see the stack_status value of CREATE_IN_PROGRESS.` If you wait a minute, and then reissue the command, you should see that the stack has been created.

Showing stack details#

In this section, you submit an request to show the details for your stack.

You can send the request using either of the following methods:

Show stack details by using the heat client#

Show the details for your stack Single-Server-Stack by issuing the following command:

heat stack-show Single-Server-Stack

The command returns the details for the stack:

+----------------------+---------------------------------------------------+
| capabilities         | []                                                |
| creation_time        | 2014-01-24T20:12:47Z                              |
| description          | No description                                    |
| disable_rollback     | True                                              |
| id                   | 3bd2c230-b02a-45d8-9f16-88c9a9f64d2d              |
| links                | http://ord.orchestration.api.rackspacecloud.com/  |
|                      | v1/1234/stacks/Single-Server-Stack/3bd...d2d      |
| notification_topics  | []                                                |
|                      |                                                   |
| outputs              | [                                                 |
|                      |   {                                               |
|                      |     "output_value": "23.253.88.131",              |
|                      |     "description": "public IP address of the      |
|                      |   deployed compute instance",                     |
|                      |     "output_key": "public_ip"                     |
|                      |   }                                               |
|                      | ]                                                 |
|                      |                                                   |
| parameters           | {                                                 |
|                      |   "OS::stack_name": "Single-Server-Stack",        |
|                      |   "OS::stack_id": "3bd2c230-...f64d2d"            |
|                      | }                                                 |
|                      |                                                   |
| stack_name           | Single-Server-Stack                               |
| stack_status         | CREATE_COMPLETE                                   |
| stack_status_reason  | Stack CREATE completed successfully               |
| template_description | No description                                    |
| timeout_mins         | 60                                                |
| updated_time         | None                                              |
+----------------------+---------------------------------------------------+

Notice this is where you can see the information created by the output parameter that you created in the following section of your template file in Creating a simple stack for a cloud server.

Outputs section for template single_server.template

outputs:
  public_ip:
    description: public IP address of the deployed compute instance
    value: { get_attr: [compute_instance, accessIPv4] }

Locate the outputs property in the table of information returned by the stack-show heat client command and look at the output value for the output_key public_ip. The output_value in the preceding example is 23.253.88.131. That value is the public IP address for the server that was created by the stack Single-Server-Stack. If the output parameter public_ip had not been provided in the template, there would be no easy way to access the new server (other than by using the Cloud Control Panel). Using output parameters provides a method for returning important information to API users.

Show stack details by using cURL#

Show stack details by executing the following request. This operation does not require a request body.

cURL show stack details: JSON request

curl -s \
-H "X-Auth-Token: $AUTH_TOKEN" \
-H "X-Project-Id: $TENANT_ID" \
-H "Content-Type: application/json" \
$API_ENDPOINT/stacks/Single-Server-Stack/stack_id | python -m json.tool

Remember to replace the following example values with their actual values:

  • Single-Server-Stack - If you used a different name for your stack, specify it.

  • stack_id - Specify the ID returned in your create stack response.

The following example shows the response:

Show stack details: JSON response

{
   "stack": {
   "disable_rollback": true,
   "description": "No description",
   "parameters": {
   "OS::stack_name": "Single-Server-Stack",
   "OS::stack_id": "3bd2c230-b02a-45d8-9f16-88c9a9f64d2d"
     },
     "stack_status_reason": "Stack CREATE completed successfully",
     "stack_name": "Single-Server-Stack",
     "outputs": [
       {
         "output_value": "23.253.88.131",
         "description": "public IP address of the deployed compute instance",
         "output_key": "public_ip"
       }
     ],
     "creation_time": "2014-01-24T20:12:47Z",
     "links": [
       {
         "href": "http://ord.orchestration.api.rackspacecloud.com/v1/1234/stacks/Single-Server-Stack/3bd2c230-b02a-45d8-9f16-88c9a9f64d2d",
         "rel": "self"
       }
     ],
     "capabilities": [

     ],
     "notification_topics": [

     ],
     "timeout_mins": 60,
     "stack_status": "CREATE_COMPLETE",
     "updated_time": null,
     "id": "3bd2c230-b02a-45d8-9f16-88c9a9f64d2d",
     "template_description": "No description"
   }
 }

The response shows the information created by the output parameter that you created in the outputs section of your template file in Creating a simple stack for a cloud server.

outputs section for template single_server.template

outputs:
  public_ip:
    description: public IP address of the deployed compute instance
    value: { get_attr: [compute_instance, accessIPv4] }

Locate the outputs property in the response information and look at the output value for the output_key public_ip. The output_value in the preceding example is 23.253.88.131. That value is the public IP address for the server that was created by the stack Single-Server-Stack. If the output parameter public_ip had not been provided in the template, there would be no easy way to access the new server (other than by using the Cloud Control Panel). Using output parameters provides a method for returning important information to API users.

Deleting a stack#

After you have finished using the stack, use the delete stack operation to delete it.

You can send the request using either of the following methods:

Delete a stack by using the heat client#

Delete your stack Single-Server-Stack by issuing the following command:

heat stack-delete Single-Server-Stack

The command returns the following information for the stack:

+--------------------------------------+---------------------+----------------===-+----------------------+
| id                                   | stack_name          | stack_status       | creation_time        |
+--------------------------------------+---------------------+--------------------+----------------------+
| 3bd2c230-b02a-45d8-9f16-88c9a9f64d2d | Single-Server-Stack | DELETE_IN_PROGRESS | 2014-01-23T19:41:05Z |
+--------------------------------------+---------------------+--------------------+----------------------+

The stack_status value shows that the stack is in the process of being deleted. After a minute or so, you can execute the list stacks operation (Listing stacks) and observe that the Single-Server`Stack is not listed.

Delete a stack by using cURL#

Delete your Single-Server-Stack by executing the following request.

This operation does not require a request body. This operation does not return a response body.

cURL delete stack: JSON request*

curl  -i -X DELETE \
-H "X-Auth-Token: $OS_AUTH_TOKEN" \
-H "Content-Type: application/json" \
https://ord.orchestration.api.rackspacecloud.com/v1/$OS_TENANT_ID/stacks/Single-Server-Stack/stack_id

Remember to replace the following example values with their actual respective values:

  • Single-Server-Stack - If you used a different name for a stack, specify it.

  • stack_id - Specify the ID returned in your create stack response.

The following example shows the response:

Delete stack: JSON response

HTTP/1.1 204 No Content
Server: nginx/1.2.1
Date: Fri, 31 Jan 2014 16:36:24 GMT
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Connection: keep-alive
Via: 1.0 Repose (Repose/2.13.0)

After a minute or so, you can execute the list stacks operation (Listing stacks) and observe that the Single-Server-Stack is not listed.

Creating a stack by using a resource group#

Assume that you would like to create a cloud load balancer to use with some cloud servers. You begin working on this task by creating a resource group to hold the servers. The advantage of this technique is that you can create the entire set of servers by creating one resource group, rather than specifying each server resource separately.

First, use your text editor to create the following template and save it in a file named servers-with-lb.template:

heat_template_version: 2014-10-16

description: |
  Heat Orchestration Template that spins up a
  resource group with 2 cloud servers.

resources:
  web_nodes:
    type: OS::Heat::ResourceGroup
    properties:
      count: 2
      resource_def:
        type: OS::Nova::Server
        properties:
          flavor: 1 GB General Purpose v1
          image: CentOS 6 (PV)
          name: LB-Compute Web Nodes

In the preceding example, a description is provided for the template. It is good practice to always provide a brief description for what a template does in order to inform potential future users about the template.

The resources section contains a resource group named web_nodes of type OS::Heat::ResourceGroup. In the properties section for the group, the attribute count is set to 2, which means that two resources of the type OS::Nova::Server (as defined in the resource definition resource_def) will be created in the group. The properties section for the resource definition for each resource in the group specifies the following values:

  • 1 GB General Purpose v1 flvor

  • CentOS 6 (PV) image

  • the name LB-Compute Web Nodes

Note

The advantage of using a resource group to define your servers is the fact that you can set the desired number of servers to create by simply setting the value of count in the template. For example, to create three Cloud Servers instead of two, you could modify the value of count as follows:

count: 3

You can send the request to create the stack by using either of the following methods:

Create a stack by using a resource group with the heat client#

Issue the following command, which includes the name of the template file that you just created:

heat stack-create Servers-With-LB-Stack --template-file servers-with-lb.template

The command returns the information about the stack, including its status CREATE_IN_PROGRESS:

+--------------------------------------+-----------------------+--------------------+----------------------+
| id                                   | stack_name            | stack_status       | creation_time        |
+--------------------------------------+-----------------------+--------------------+----------------------+
| e7b67698-3929-43af-8e59-9652d00b7250 | Servers-With-LB-Stack | CREATE_IN_PROGRESS | 2014-01-28T18:00:27Z |
+--------------------------------------+-----------------------+--------------------+----------------------+

After a couple of minutes, you can issue the list stacks (Listing stacks) to confirm that your stack is now created:

+--------------------------------------+-----------------------+-----------------+----------------------+
| id                                   | stack_name            | stack_status    | creation_time        |
+--------------------------------------+-----------------------+-----------------+----------------------+
| e7b67698-3929-43af-8e59-9652d00b7250 | Servers-With-LB-Stack | CREATE_COMPLETE | 2014-01-28T18:00:27Z |
+--------------------------------------+-----------------------+-----------------+----------------------+

Create a stack by using a resource group with cURL#

Issue the following command:

curl -i -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "X-Auth-Token: $AUTH_TOKEN" -H "X-Project-Id: $TENANT_ID" -d \
'{
  "stack_name": "Servers-With-LB-Stack",
  "disable_rollback": true,
  "parameters": {},
  "template": "heat_template_version: 2014-10-16\n\ndescription: |   \n  Heat Orchestration Template that spins up a\n  resource group with 2 cloud servers.\n\nresources:\n  web_nodes:\n    type: OS::Heat::ResourceGroup\n    properties:\n      count: 2\n      resource_def:\n        type: OS::Nova::Server\n        properties:\n          flavor: 1 GB General Purpose v1\n          image: CentOS 6 (PV)\n          name: LB-Compute Web Nodes  \n\n\n",
  "timeout_mins": 60
  }' \
  $API_ENDPOINT/stacks

The following example shows the response:

HTTP/1.1 201 Created
Server: nginx/1.2.1
Date: Fri, 31 Jan 2014 17:09:37 GMT
Content-Type: application/json
Content-Length: 192
Location: https://ord.orchestration.api.rackspacecloud.com/v1/1234/stacks/Servers-With-LB-Stack/e7b67698-3929-43af-8e59-9652d00b7250
Connection: keep-alive
Via: 1.0 Repose (Repose/2.13.0)

{"stack": {"id": "e7b67698-3929-43af-8e59-9652d00b7250", "links": [{"href": "http://ord.orchestration.api.rackspacecloud.com/v1/1234/stacks/Servers-With-LB-Stack/e7b67698-3929-43af-8e59-9652d00b7250", "rel": "self"}]}}

The stack Servers-With-LB-Stack was successfully created and has the id e7b67698-3929-43af-8e59-9652d00b7250.

Updating a stack with a load balancer#

In this section you send a request to update your stack by adding a load balancer to use with the two servers.

  1. Make a copy of the servers-with-lb.template file from the previous section, and name the copy servers-with-lb-add.template.

  2. Add the load balancer to the servers-with-lb-add.template file by adding the highlighted text in the following example.

heat_template_version: 2014-10-16

description: |
  Heat Orchestration Template that spins up a
  resource group with 2 cloud servers
  and a cloud load balancer.

resources:
  web_nodes:
    type: OS::Heat::ResourceGroup
    properties:
      count: 2
      resource_def:
        type: OS::Nova::Server
        properties:
          flavor: 1 GB General Purpose v1
          image: CentOS 6 (PV)
          name: LB-Compute Web Nodes

  lb:
    type: Rackspace::Cloud::LoadBalancer
    properties:
      name: LB-Compute load balancer
      nodes:
      - addresses: { get_attr: [web_nodes, accessIPv4]} # This is where
                                                        # wiring magic
                                                        # happens
        port: 80
        condition: ENABLED
      healthMonitor:
        attemptsBeforeDeactivation: 3
        delay: 10
        timeout: 120
        type: HTTP
        path: "/"
        statusRegex: "."
        bodyRegex: "."
      protocol: HTTP
      port: 80
      virtualIps:
      - type: PUBLIC
        ipVersion: IPV4

outputs:
  lb_public_ip:
    description: The public IP address of the load balancer
    value: { get_attr: [lb, PublicIp]}

In the description section, you added the information that the template now also creates a load balancer.

For the lb resource (in the resources section), you added the information to create the load balancer. The resource type is Rackspace::Cloud::LoadBalancer. The load balancer has the following properties:

  • It is named LB-Compute load balancer.

  • It defines a list of addresses for the back-end nodes by calling the get_attr intrinsic function, passing it the name of the resource group (web_nodes) and the IP address for each server resource (accessIPv4), as defined in the resource group. These back-end nodes are the servers that you created in Creating a stack by using a resource group. Each node uses port 80, and all nodes are enabled.

  • The load balancer protocol is HTTP and the service is defined on port 80.

  • One public IPV4 virtual IP address should be added for the load balancer.

Note

To create a ServiceNet address for the load balancer instead of a public virtual IP address, use the following value for type instead:

- type: SERVICENET

You will also need to change the outputs as follows:

outputs:
  lb_servicenet_ip:
    description: The Servicenet IP address of the load balancer
    value: { get_attr: [lb, virtualIps, 0, address ]}

Since virtualIps is an array, you need to request the address in the first element of the array (array subscript 0) to get the Servicenet address.

  • A health monitor is defined with the following attributes set:

    • attemptsBeforeDeactivation - Number of attempts made before the node is removed from the rotation

    • delay - Number of seconds to wait before executing the health monitor

    • timeout - Number of seconds to wait for a connection to be made before timing out

    • type - Type of the health monitor

    • path - HTTP path used in the monitor request

    • statusRegex - Regular expression used to evaluate the HTTP status code returned in the response

    • bodyRegex - Regular expression used to evaluate the contents of the body of the response

The outputs section defines a single output lb_public_ip, which is the public IP address for the load balancer. Its value is assigned to the result of calling the get_attr intrinsic function with the name of the resource (lb) and its attribute (PublicIp).

You can send the update request using either of the following methods:

Update a stack with a load balancer by using the heat client#

Issue the following command:

heat stack-update Servers-With-LB-Stack --template-file servers-with-lb-add.template

The command returns the information about the stack, including its status UPDATE_IN_PROGRESS:

+--------------------------------------+-----------------------+--------------------+----------------------+
| id                                   | stack_name            | stack_status       | creation_time        |
+--------------------------------------+-----------------------+--------------------+----------------------+
| e7b67698-3929-43af-8e59-9652d00b7250 | Servers-With-LB-Stack | UPDATE_IN_PROGRESS | 2014-01-28T18:00:27Z |
+--------------------------------------+-----------------------+--------------------+----------------------+

Wait a couple of minutes and then issue the following command:

heat stack-show Servers-With-LB-Stack

The command returns the details about the stack, including its status UPDATE_COMPLETE:

+---------------------+----------------------------------------------------+
| Property             | Value                                             |
+---------------------+----------------------------------------------------+
| capabilities         | []                                                |
| creation_time        | 2014-01-28T18:00:27Z                              |
| description          | Heat Orchestration Template that spins up a       |
|                      | resource group with 2 cloud servers and a Cloud   |
|                      | Load Balancer                                     |
| disable_rollback     | True                                              |
| id                   | e7b67698-3929-43af-8e59-9652d00b7250              |
| links                | http://ord.orchestration.api.rackspacecloud.com/  |
|                      | v1/1234/stacks/Single-Server-Stack/3bd...d2d      |
| notification_topics  | []                                                |
|                      |                                                   |
| outputs              | [                                                 |
|                      |   {                                               |
|                      |     "output_value": "162.242.141.48",             |
|                      |     "description": "The public IP address of the  |
|                      |                     load balancer",               |
|                      |     "output_key": "lb_public_ip"                  |
|                      |   }                                               |
|                      | ]                                                 |
|                      |                                                   |
| parameters           | {                                                 |
|                      |   "OS::stack_name": "Servers-With-LB-Stack",      |
|                      |   "OS::stack_id": "e7b67698-...8e59-9652d00b7250" |
|                      | }                                                 |
|                      |                                                   |
| stack_name           | Servers-With-LB-Stack                             |
| stack_status         | UPDATE_COMPLETE                                   |
| stack_status_reason  | Stack successfully updated                        |
| template_description | Heat Orchestration Template that spins up a       |
|                      | resource group with 2 cloud servers and a Cloud   |
|                      | Load Balancer                                     |
| timeout_mins         | 60                                                |
| updated_time         | 2014-01-28T21:34:47Z                              |
+---------------------+----------------------------------------------------+

The outputs property (set in the outputs section of the template), shows that the public IP address of the new load balancer is 162.242.141.48.

Update a stack with a load balancer by using cURL#

Update the stack by executing the following request:

Remember to replace the names in the example preceding with their actual respective values:

  • Server-With-LB-Stack - The name of the stack, if you changed it.

  • stack_id - The ID of the stack, as returned in your create stack operation.

cURL update stack with load balancer: JSON request

curl -i -X PUT -H  "Accept: application/json" -H  "Content-Type: application/json" -H  "X-Auth-Token: $AUTH_TOKEN" -H "X-Project-Id: $TENANT_ID" -d \
'{
  "stack_name": "Servers-With-LB-Stack",
  "disable_rollback": true,
  "parameters": {},
  "template": "heat_template_version: 2014-10-16\n\ndescription: |   \n  Heat Orchestration Template that spins up a\n  resource group with 2 cloud servers\n  and a cloud load balancer.\n\nresources:\n  web_nodes:\n    type: OS::Heat::ResourceGroup\n    properties:\n      count: 2\n      resource_def:\n        type: OS::Nova::Server\n        properties:\n          flavor: 1 GB General Purpose v1\n          image: CentOS 6 (PV)\n          name: LB-Compute Web Nodes  \n\n  lb:\n    type: Rackspace::Cloud::LoadBalancer\n    properties:\n      name: LB-Compute load balancer\n      nodes:\n      - addresses: { get_attr: [web_nodes, accessIPv4]} # This is where the\n                                                       # wiring magic happens\n        port: 80\n        condition: ENABLED\n      healthMonitor:\n        attemptsBeforeDeactivation: 3\n        delay: 10\n        timeout: 120\n        type: HTTP\n        path: \"/\"\n        statusRegex: \".\"\n        bodyRegex: \".\"\n      protocol: HTTP\n      port: 80\n      virtualIps:\n      - type: PUBLIC\n        ipVersion: IPV4\n\noutputs:\n  lb_public_ip:\n    description: The public IP address of the load balancer\n    value: { get_attr: [lb, PublicIp]}  \n\n",
  "timeout_mins": 60
}' \
$API_ENDPOINT/stacks/Servers-With-LB-Stack/stack_id

The following example shows the response for update stack with load balancer:

HTTP/1.1 100 Continue

HTTP/1.1 202 Accepted
Server: nginx/1.2.1
Date: Fri, 31 Jan 2014 22:06:57 GMT
Content-Type: text/plain;charset=UTF-8
Content-Length: 58
Connection: keep-alive
Via: 1.0 Repose (Repose/2.13.0)

202 Accepted

The request is accepted for processing.

After a few minutes, you can execute the show stack details operation to ensure that the update completed successfully:

Remember to replace the following variable names in the example with the values you want to use.

  • Servers-With-LB-Stack

  • stack_id

cURL show stack details: JSON request

curl -s \
-H "X-Auth-Token: $AUTH_TOKEN" \
-H "X-Project-Id: $TENANT_ID" \
-H "Content-Type: application/json" \
$API_ENDPOINT/stacks/Servers-With-LB-Stack/stack_id | python -m json.tool

The following example shows the response:

{
  "stack": {
  "capabilities": [],
  "creation_time": "2014-01-31T22:02:46Z",
  "description": "Heat Orchestration Template that spins up a\nresource group with 2 cloud servers\nand a cloud load balancer.\n",
  "disable_rollback": true,
  "id": "6574e1b1-4c22-49f5-a06d-6d99eb8d87c6",
  "links": [
      {
        "href": "http://ord.orchestration.api.rackspacecloud.com/v1/1234/stacks/Servers-With-LB-Stack/6574e1b1-4c22-49f5-a06d-6d99eb8d87c6",
        "rel": "self"
      }
  ],
  "notification_topics": [],
  "outputs": [
      {
        "description": "The public IP address of the load balancer",
        "output_key": "lb_public_ip",
        "output_value": "184.106.100.140"
      }
  ],
  "parameters": {
  "OS::stack_name": "Servers-With-LB-Stack",
  "OS::stack_id": "6574e1b1-4c22-49f5-a06d-6d99eb8d87c6"
      },
  "stack_name": "Servers-With-LB-Stack",
  "stack_status": "UPDATE_COMPLETE",
  "stack_status_reason": "Stack successfully updated",
  "template_description": "Heat Orchestration Template that spins up a\nresource group with 2 cloud servers\nand a cloud load balancer.\n",
  "timeout_mins": 60,
  "updated_time": "2014-01-31T22:08:01Z"
      }
}

Deleting a stack with a load balancer#

When you are finished using your stack, delete it by using the commands shown in Deleting a stack. Be sure to adjust the stack name (and for cURL, the stack_id) as necessary to reflect the new Servers-With-LB-Stack that you are deleting.

This concludes the Getting Started exercises.

For more tutorials on using Cloud Orchestration, see the Heat Tutorial.