Create and manage scaling groups#

You can use the examples in the following sections to create scaling groups using a schedule-based configuration by using the Rackspace Auto Scale API. Before running the examples, review the Rackspace Auto Scale concepts to understand the API workflow, scaling group configurations, and use cases.

Note

These examples use the $API_ENDPOINT, $AUTH_TOKEN, and $TENANT_ID environment variables to specify the API endpoint, authentication token, and project ID values for accessing the service. Make sure you configure these variables before running the code samples.

List cloud server images#

Before you create a server through the Cloud Server API, you need to obtain a list of available images so that you can choose one for your new server.

After you choose an image, copy its image ID. You use this image ID when you create the server.

Use the Cloud Servers API to issue a List Images request to retrieve a list of options available for configuring your server. The following example shows how to request a list cloud server images.

Requesting a list of cloud server images

   curl -X GET \
   -H "Content-Type: application/json" \
   -H "X-Auth-token:{auth-token}" \
   https://ord.servers.api.rackspacecloud.com/v2/{tenant-id}/images?type=SNAPSHOT | python -mjson.tool

1. After creating your server you customize it so that it can process
   your requests. For example, if you are building a webhead
   scaling group, configure Apache to start on launch and serve
   the files that you need.

2. After you have created and customized your server, save its image
   and record the imageID value that is returned in the response body.

Create a cloud server#

After you have obtained the imageID for the server image you want to create, you need to create your cloud server. Auto Scale will use the configuration info in this server image as a blueprint for create new server images.

You can create a server using one of the following methods:

  1. Create a server through the Cloud Control Panel.

  2. Create a server through the Cloud Servers API by using a Create Server request.

Create a cloud server image#

After you have created a Cloud Server, you need to create an image, which Auto Scale will use to create new servers.

You can create a server image using one of the following methods:

  1. Create a server image through the Cloud Control Panel. Make sure to record the imageID value for the image you have created.

  2. Create a server image through the Cloud Servers API by using a Create Image request to obtain the imageID value, use a List Images request.

Create a scaling group#

Now you are ready to create your first scaling group. For this exercise, you will create a schedule-based scaling group that will trigger a scaling event at 11 P.M. daily. The following example shows how to create a schedule-based scaling group by submitting a POST request using cURL.

{
   "launchConfiguration":{
      "args":{
         "loadBalancers":[
            {
               "port":80,
               "loadBalancerId":237935
            }
         ],
         "server":{
            "name":"autoscale_server",
            "imageRef":"7cf5ffc3-7b20-46fd-98e4-fefa9908d7e8",
            "flavorRef":"performance1-2",
            "OS-DCF:diskConfig":"AUTO",
            "networks":[
               {
                  "uuid":"11111111-1111-1111-1111-111111111111"
               },
               {
                  "uuid":"00000000-0000-0000-0000-000000000000"
               }
            ]
         }
      },
      "type":"launch_server"
   },
   "groupConfiguration":{
      "maxEntities":10,
      "cooldown":360,
      "name":"testscalinggroup",
      "minEntities":0
   },
   "scalingPolicies":[
      {
         "cooldown":0,
         "name":"scale up by 1",
         "change":1,
         "type":"schedule",
         "args":{
            "cron":"23 * * * *"
         }
      }
   ]
}

If the POST request is successful, the response data will be returned in JSON format as shown in the following example:

{
   "group":{
      "groupConfiguration":{
         "cooldown":360,
         "maxEntities":10,
         "metadata":{

         },
         "minEntities":0,
         "name":"testscalinggroup"
      },
      "id":"48692442-2dbe-4311-955e-bc29f02ae311",
      "launchConfiguration":{
         "args":{
            "loadBalancers":[
               {
                  "loadBalancerId":237935,
                  "port":80
               }
            ],
            "server":{
               "OS-DCF:diskConfig":"AUTO",
               "flavorRef":"performance1-2",
               "imageRef":"7cf5ffc3-7b20-46fd-98e4-fefa9908d7e8",
               "name":"autoscale_server",
               "networks":[
                  {
                     "uuid":"11111111-1111-1111-1111-111111111111"
                  },
                  {
                     "uuid":"00000000-0000-0000-0000-000000000000"
                  }
               ]
            }
         },
         "type":"launch_server"
      },
      "links":[
         {
            "href":"https://dfw.autoscale.api.rackspacecloud.com/v1.0/829409/groups/48692442-2dbe-4311-955e-bc29f02ae311/",
            "rel":"self"
         }
      ],
      "scalingPolicies":[
         {
            "args":{
               "cron":"23 * * * *"
            },
            "change":1,
            "cooldown":0,
            "id":"9fa63149-c93d-4116-8069-74d68f48fadc",
            "links":[
               {
                  "href":"https://dfw.autoscale.api.rackspacecloud.com/v1.0/829409/groups/48692442-2dbe-4311-955e-bc29f02ae311/policies/9fa63149-c93d-4116-8069-74d68f48fadc/",
                  "rel":"self"
               }
            ],
            "name":"scale up by 1",
            "type":"schedule"
         }
      ],
      "scalingPolicies_links":[
         {
            "href":"https://dfw.autoscale.api.rackspacecloud.com/v1.0/829409/groups/48692442-2dbe-4311-955e-bc29f02ae311/policies/",
            "rel":"policies"
         }
      ],
      "state":{
         "active":[

         ],
         "activeCapacity":0,
         "desiredCapacity":0,
         "name":"testscalinggroup",
         "paused":false,
         "pendingCapacity":0
      }
   }
}

Delete a scaling group#

You can use the Auto Scale API to deactivate and delete one or more scaling groups. Your options for deleting the scaling group depend on whether your scaling group has active entities or not.

When a group contains no servers, you can eliminate the group by sending a DELETE request to its group ID.

The following two options are possible for deleting a scaling group:

  • If there are no active entities in your configuration, use the DELETE request to delete the scaling group.

  • If there are active entities, then force delete the group by submitting a DELETE request with force parameter to true.

Delete a scaling group with no active entities

To delete a scaling policy group that has no active entities, submit a DELETE request with the tenantID and groupIDparameters specified in the request URL as shown in the following example:

http -vv DELETE https://dfw.autoscale.api.rackspacecloud.com/v1.0/676873/groups/605e13f6-1452-4588-b5da-ac6bb468c5bf/ X-Auth-Token:XXXXXXXXXXXXXXXX

If the DELETE request is successful, a 204 response code with no response body will be returned. If the request fails, a 403 response code will be returned with a message stating that your group still has active entities as shown in the following example:

Group d5f5f3ad-faef-4c8f-99c4-0e931189c521 for tenant 829409 still has entities.

Delete a scaling group using FORCE DELETE

The Auto Scale API provides an option for users to force delete a scaling group that has active servers. The FORCE DELETE option will remove all servers in the configuration from the load balancer(s) and then delete the server.

Warning

Using FORCE DELETE will remove all servers that are associated with the scaling group. Users are discouraged from using the FORCE DELETE option and to manually delete servers instead.

To use the FORCE DELETE option, submit a DELETE request with the tenantId and groupIdparameters specified in the request URL, and set the force parameter to true.

DELETE /{tenantId}/groups/{groupId}?force=true

Upon successful submission of this request the minEntities and maxEntities parameters will automatically be set to 0 and the deletion of the group will begin. If the DELETE request is successful, a 204 response code with an empty response body will be returned.