Support: 1-800-961-4454
1-800-961-2888

Rackspace Cloudvent Calendar Day 4: Auto Scale API

In the spirit of the holiday season, I’m sharing some tips and features of our cloud that you may not know about. In this countdown I’ll have 24 posts for you, each covering a single topic or feature about Rackspace Cloud products. We’ll post one per day so keep checking back!

Rackspace recently announced Auto Scale, which allows you to scale your server environments up and down as needed automatically. The post from Racker J.R. Arredondo is a fantastic walkthrough of setting up Auto Scale groups in the Control Panel, but what if you wanted to do the same thing via API? Let’s dive into that!

First, you’ll need a server image to use with Auto Scale. If you’re using the rackspace-novaclient it’s a simple command:

nova image-create <SERVER_UUID> IMAGENAME

You will also need a load balancer ID for use with this group of servers. You can get a listing of your Cloud Load Balancers via the API:

curl -s -H "X-Auth-Token: $TOKEN" https://ord.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers

Now you have an image and a load balancer, and you can create an Auto Scale group with a configuration and scaling policy in one step with a JSON file:

{
 "launchConfiguration": {
 "args": {
 "loadBalancers": [
 {
 "port": 8080,
 "loadBalancerId": 9099
 }
 ],
 "server": {
 "name": "autoscale_server",
 "imageRef": "0d589460-f177-4b0f-81c1-8ab8903ac7d8",
 "flavorRef": "performance1-2",
 "OS-DCF:diskConfig": "AUTO",
 "metadata": {
 "build_config": "core",
 "meta_key_1": "meta_value_1",
 "meta_key_2": "meta_value_2"
 },
 "networks": [
 {
 "uuid": "11111111-1111-1111-1111-111111111111"
 },
 {
 "uuid": "00000000-0000-0000-0000-000000000000"
 }
 ],
 "personality": [
 {
 "path": "/root/.csivh",
 "contents": "VGhpcyBpcyBhIHRlc3QgZmlsZS4="
 }
 ]
 }
 },
 "type": "launch_server"
 },
 "groupConfiguration": {
 "maxEntities": 10,
 "cooldown": 360,
 "name": "testscalinggroup198547",
 "minEntities": 0,
 "metadata": {
 "gc_meta_key_2": "gc_meta_value_2",
 "gc_meta_key_1": "gc_meta_value_1"
 }
 },
 "scalingPolicies": [
 {
 "cooldown": 0,
 "type": "webhook",
 "name": "scale up by 1",
 "change": 1
 }
 ]
 }

Notice here that not only have we defined the load balancers and image to use, but also any special network configuration that is required and configuration and policy as well. To create this group, save the above JSON (replacing values for your account) to a file called group.json and make a POST request to the Auto Scale API:

curl –s –X POST –d group.json –H “Content-type: application/json” –H “X-Auth-Token: $TOKEN” https://ord.autoscale.api.rackspacecloud.com/v1.0/1234/groups

Congrats! You’ve created an auto scale group to your account! Keep checking back all month long for more tips and tricks to make your cloud experience awesome!

About the Author

This is a post written and contributed by Hart Hoover.

Hart Hoover is a Cloud Strategist at Rackspace Hosting. Hoover started his career as a Racker in 2007 as a Linux Systems Administrator, providing technical support for dedicated servers. He moved to the cloud in 2009 to help design the Managed Cloud Servers support model. He has presented at various technical conferences, maintains and contributes to the Rackspace DevOps Blog, and advises Rackspace customers on best practices for cloud computing.


More
Racker Powered
©2014 Rackspace, US Inc.