Find the apps you're missing.
Sign up for the Appslice BETA:

RackspaceCloud Command Line Tool


Get It!
List flavors
List backups
List servers
Show your running total bill
Show server status
Create a server
Create a server and wait for it
Resize a server and wait for it
Variables
Troubleshooting
Command line usage


Try it out:

Make sure you have the latest groovy version then download the script:

download rscloud.groovy beta 2  - updated 2009-07-09
beta 2 - 2009-07-09 - RS changed status response json slightly.
beta 1 - 2009-06-26 - initial release

type groovy rscloud.groovy -h to see a list of commands and options.

news: Initial release blog post

get a list of flavors:

$ groovy rscloud.groovy -u username -p password -c list flavors
found 7 flavors:
1 - 256 MB 10 GB 0.015/hour
2 - 512 MB 20 GB 0.03/hour
3 - 1024 MB 40 GB 0.06/hour
4 - 2048 MB 80 GB 0.12/hour
5 - 4096 MB 160 GB 0.24/hour
6 - 8192 MB 320 GB 0.48/hour
7 - 15872 MB 620 GB 0.96/hour



get a list of backups:

$ groovy rscloud.groovy -u username -p password -c list backups
found 6 backups:
9383  - base_centos_5_3     asc Mon Jun 15 22:53:53 CDT 2009
11183 - daily               asc Sat Jun 20 01:15:06 CDT 2009
11309 - base_master      master Sat Jun 20 18:19:53 CDT 2009
11640 - weekly              asc Sun Jun 21 01:15:41 CDT 2009
11680 - weekly           master Sun Jun 21 03:15:36 CDT 2009



List your servers:

$ groovy rscloud.groovy -u username -p password -c list servers
found 1 servers:
mytestserver (id: 59930) (size: 256 MB)
    IP: 174.143.233.108
    Status: Building
    action: Build
completed cloud operations in 0.1966 minutes


check the running total on your bill:

$ groovy rscloud.groovy -u username -p password -c bill 
running total bill: $36.93



check server status:

$ groovy rscloud.groovy -u username -p password -c status 59718
Building 44%



create a server:

$ groovy rscloud.groovy -u username -p password -c create mytestserver 11309 1
mytestserver (id: 59930) (size: 256 MB)
    IP: 67.23.25.173
    Status: Building
    action: Build
    root: mytestserver7P7jxb
completed cloud operations in 0.2495166667 minutes

Boom! one freshly minted server! (using backup image id #11309 and flavor #1)

Note that the root password is in that output too.. that only appears for newly created servers.



create a server and wait for it to be ready:

$ groovy rscloud.groovy -u username -p password -P 22 -c createAndWait tempserver 11309 1
created server tempserver (id: 59535) (size: 256 MB)
   IP: 67.23.24.43
   Status: Building
   action: Build
   root: tempserverZgHYXt
...waiting for it to be ready....
0% 43% 43% 43% 44% 73% 79% 82% 100% server is Active: 59924
waiting for port 22 on 67.23.24.43
port open, server is ready.
completed cloud operations in 7.2558833333 minutes

This is the same as the last example except I have changed the command to createAndWait which will cause the script to wait until Rackspace says the server is "Active".. additionally I have added a -P 22 flag, which tells the script to wait until port 22 on the new server is accepting connections after "Active" status is reached.



resize server:

$ groovy rscloud.groovy -u username -p password -c resizeAndWait -P 22 59535 3 "./doStuff.sh \$server.ip \$server.id"
queued resize for server tempserver (id: 59535) (size: 256 MB)
   IP: 174.143.233.108
   Status: Queued for Resize
   action: None
...waiting for it to be ready....
0% 0% 0% 0% 53% 53% 53% 53% 92% 94% 99% 100% server is ready for verification: 59535
waiting for port 22 on 174.143.233.108
port open, server is ready.
executing command: ./doStuffAndResize.sh 174.143.233.108 59535
verified server: 59535
completed cloud operations in 0.3571833333 minutes
appstorecrawler bin
Connection to 174.143.233.108 closed.
queued resize for server tempserver (id: 59535) (size: 1024 MB)
   IP: 174.143.233.108
   Status: Queued for Resize
   action: None
...waiting for it to be ready....
0% 0% 0% 0% 53% 53% 53% 53% 84% 92% 95% 96% 0% server is ready for verification: 59535
waiting for port 22 on 174.143.233.108
port open, server is ready.
completed cloud operations in 11.0956666667 minutes
verified server: 59535
completed cloud operations in 0.2993333333 minutes

completed cloud operations in 22.0342833333 minutes


That example resizes a server to the 1 GB flavor, waits for it to become Active, and for port 22 (-P 22) to be ready.

The quotes string at the end is a command line to be executed when the above conditions are met. It validates the resize, runs an operation, then resizes the server back down to 256 GB and validates it again... all hands off. Here is that script:

#!/bin/bash
# command line args
server_ip=$1
server_id=$2

# verify the server that was just resized
groovy rscloud.groovy -u username -p password -c verify $server_ip

# log into the server and run any command
ssh -t -o 'StrictHostKeyChecking=no' $1 "ls -l"

# remote command is complete, resize the server back down and wait for port 22 to respond
groovy rscloud.groovy -u username -p password -c resizeAndWait -P 22 $server_id 1

# verifiy the shrikage
groovy rscloud.groovy -u username -p password -c verify $server_ip



command line variables:

You may have noticed that in the above command line we see \$server.ip but in the output we see 174.143.233.108. There are several bits of info this script can pass to your command line:
     $server.id - The ID for this server
     $server.ip - The external IP address for this server
     $server.rootPass - The root password as provided by Rackspace when a server is first created. NOT always available.
     $server.name - The name you assigned this server
     $server.status - The current status of this server
     $server.ram - The size of the server

make sure you excape the $ with a \ like this: \$server.ip

Troubleshooting:

If you end up with an exception like this one:

 

Caught: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
     at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:352)
     at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:129)
     at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:326)

 

You hit the same problem I did on our linux server (but not on my OSX machine!)... It seems something is up with the new SSL certificate Rackspace is using since they switched from the mosso.com domain to the rackspacecloud.com domain on Wednesday night (20090624). I followed this post and was able to keep on rocking... but I don't necessarily feel that great about it.



Usage:

usage: groovy rscloud.groovy [-h] [-d] [-u user] [-p password] [-P portToWaitFor] [-c command] [arguments]*
-c,--command command
-d,--debug additional debug info
-h,--help usage info
-P,--port port to wait for
-p,--password password
-u,--user user

Commands:

list
list some Rackspace entities
type - [summary|servers|backups|flavors] (the default is 'summary')

bill
print the current running bill total

create
create a new server
name - the name of the new server (use quotes for names with spaces)
imageId - the id of the backup image
flavorId - the id of flavor to use

resize
resize a server
serverId - the id of the server to resize
flavorId - the id of new flavor to use

verify
mark a resize as verified
serverId - the id of the server to verify

rollback
rollback a server resize
serverId - the id of the server to rollback

delete
delete rackspace server
serverId - the id of the server you want to delete

waitUntil [shellCommand]
waits for the server become active then waits for the optional shellCommand to return 0
serverId - the id of the server you want to wait for
shellCommand - optional command is executed after server is ready
example: waitUntil 12345 "ssh -o StrictHostKeyChecking=no user@\$server.ip ls"
($server.ip is replaced with the IP of the server)

createAndWait [shellCommand]
create a new server and wait for it to boot, then optionally wait for shell command to return zero
name - the name of the new server (use quotes for names with spaces)
imageId - the id of the backup image
flavorId - the id of flavor to use
shellCommand - optional command is executed after server is ready
example: waitUntil 12345 "ssh -o StrictHostKeyChecking=no user@\$server.ip ls"
($server.ip is replaced with the IP of the server)

resizeAndWait [shellCommand]
resize a server and wait for it to boot, then optionally wait for shell command to return zero
serverId - the id of the server to resize
flavorId - the id of flavor to resize to
shellCommand - optional command is executed after server is ready


Command Shell Bindings:

the following variables are available to your shellCommands
$server.id - The ID for this server
$server.ip - The external IP address for this server
$server.name - The name you assigned this server
$server.rootPass - The root password as provided by Rackspace when a server is first created. NOT always available.
$server.status - The current status of this server
$server.ram - The size of the server

make sure you excape the $ with a \ like this: \$server.ip