Home > Guides > RightScale API 1.0 > RightScale API 1.0 Examples

RightScale API 1.0 Examples

Overview

Sometimes the best way to learn is by studying some real world examples to see how things work and hopefully understand how you can apply it for your own purposes. The examples below cover some common use cases of the RightScale API and if you're savvy, you'll also be able to deconstruct them to extract specific code snippets for accomplishing more specific tasks.

The examples are written in Bourne shell or Bash. RestConnection examples are also available.

Using rs_api_examples

All the Bash/cURL examples in this section resided in rs_api_examples. Each example sources configuration from ~/.rightscale, logs into the API then performs the required API calls.

Installation

RightScript install

For RightScale Servers and Server Array instances, import the Install & configure rs_api_examples RightScript from the MultiCloud Marketplace.
Add this to your ServerTemplates or use as an Any Script. Inputs are provided for your RightScale credentials (skip the configuration section below).

RightScale/EC2 API Toolbox

You can get started within minutes by importing the RightScale/EC2 API Toolbox from the MultiCloud Marketplace, adding it to a deployment, filling in the missing inputs for your credentials, then launching the server. Once operational, you'll find that each command in the package, e.g. rs-login.sh is available in the shell's path.

Manual install

This is ideal for any unix-like desktop or virtual machine that is not attached to RightScale.

#!/bin/sh -e

install_dir="$HOME/bin"     # non-root
#install_dir=/usr/bin       # root

mkdir -p "$install_dir"
cd /tmp
git clone git://github.com/flaccid/rs_api_examples.git
cp -vR /tmp/rs_api_examples/bin/* "$install_dir"/
chmod +x "$install_dir"/rs-*.sh
rm -Rf /tmp/rs_api_examples

Configuration

Add rs_api_examples to search path

Add to user's shell profile

for f in "$HOME"/{.bash_profile,.bash_login,.profile}; do
    if [[ -f $f ]]; then
        echo "PATH+=':$install_dir'" >> "$f"; break;
    fi
done

Or, add to current shell path

PATH+=":$install_dir"
Configure credentials and API version
Interactive setup
rs-config-api.sh
# <follow the prompts>

Note, your RightScale account ID can be found after 'acct/' in URLs when browsing my.rightscale.com, e.g. https://my.rightscale.com/acct/1234/dashboard;overview

Non-interactive
#!/bin/sh -e

rs_api_version=1.0
rs_api_account_id=1234
rs_api_user=john@smith.com
rs_api_password=foobar

mkdir -p "$HOME/.rightscale"

cat <<EOF> "$HOME/.rightscale/rs_api_config.sh"
rs_api_version=$rs_api_version
rs_api_cookie="$HOME/.rightscale/rs_api_cookie.txt"
EOF
cat <<EOF> "$HOME/.rightscale/rs_api_creds.sh"
rs_api_account_id=$rs_api_account_id
rs_api_user="$rs_api_user"
rs_api_password="$rs_api_password"
EOF
Test Authentication
rs-login.sh
Switching Accounts
rs-switch-accounts.sh 1234    # where 1234 is the account ID

List of Examples

You must to post a comment.
Last Modified
21:57, 16 May 2013

Page Rating

Was this article helpful?

Tags


Announcements

None

Glossary | 用語용어 Site Map | Site Help Community Corporate Site Get Support Dashboard Login
Doc Feedback Product Feedback Resources MultiCloud Marketplace Forums

Dashboard Status


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.