_images/righteous.jpg

righteous: A Python Rightscale API/CLI

Release v0.5.0

righteous is a Python client implementation of the RightScale API for EC2 instance management.

https://secure.travis-ci.org/michaeljoseph/righteous.png

righteous provides an API and CLI to create, start/stop, delete, remove and introspect RightScale EC2 Servers. This library implements RightScale API 1.0 and has only been tested with EC2 instances using ServerTemplates and managed in a Deployment.

Configuration

Create a file called ~/.righteous with the following customised contents:

[auth]
username: username@domain.com
password: password
account_id: 123

[server-defaults]
default_deployment_id: 45623
ec2_security_groups_href: https://my.rightscale.com/api/acct/123/ec2_security_groups/789
ec2_availability_zone: us-east-1a
ec2_ssh_key_href: https://my.rightscale.com/api/acct/123/ec2_ssh_keys/998
cloud_id: 1
server_template_href: https://my.rightscale.com/api/acct/123/ec2_server_templates/74732
instance_type: m1.small
m1.small: https://my.rightscale.com/api/acct/123/ec2_server_templates/74732
m1.large: https://my.rightscale.com/api/acct/123/ec2_server_templates/117240

CLI

righteous
Interact with the RightScale Server API.

Usage:
  righteous [options] list
  righteous [options] create <environment> <instance-type> (<server-template-key>=<server-template-value>)...
  righteous [options] stop <environment>...
  righteous [options] status <environment>...
  righteous [options] delete <environment>...
  righteous --version

Options:
  -c FILE --config=FILE        Specify the configuration file location, default is ~/.righteous
  -v --verbose                 Show debug output
  -h --help                    Show this screen.

Server API

righteous.initialise(username, password, account_id, **kwargs)

Initialises righteous configuration

Parameters:
  • username – String of a Rightscale username
  • password – String of the user’s password
  • account_id – String of the Rightscale account_id
Params kwargs:

Key word arguments for additional configuration

righteous.login(username=None, password=None, account_id=None)

Logins to RightScale and stores the auth cookie for future requests

Parameters:
  • username – (optional) String representing the username to login with
  • password – (optional) String representing the password to login with
  • account_id – (optional) String of the Rightscale account_id
Returns:

Boolean indicating successful login

righteous.list_servers(deployment_id=None)

Lists servers in a deployment

Parameters:deployment_id – (optional) String representing Deployment to list servers from
Returns:dict of server deployment information: http://reference.rightscale.com/api1.0/ApiR1V0/Docs/ApiDeployments.html
righteous.find_server(nickname)

Finds a server based on nickname

Parameters:nickname – (optional) String representing the nickname of the server to lookup
Returns:dict of server information with the following keys:
[u'deployment_href', u'tags', u'created_at', u'server_type',
 u'updated_at', u'server_template_href', u'current_instance_href',
 u'state', u'href', u'nickname']
righteous.server_info(server_href, nickname=None)

Detailed server information

Parameters:
  • server_href – URL representing the server to query
  • nickname – (optional) String representing the nickname of the server
Returns:

dict of server information with the following keys:

[u'deployment_href', u'parameters', u'tags', u'created_at',
 u'server_type', u'updated_at', u'server_template_href',
 u'current_instance_href', u'state', u'href', u'nickname']
righteous.server_settings(server_href, nickname=None)

Current server settings

Parameters:
  • server_href – URL representing the server to query settings from
  • nickname – (optional) String representing the nickname of the server
Returns:

dict of server settings with the following keys:

[u'ec2-security-groups-href', u'private-ip-address',
 u'ec2-ssh-key-href', u'private-dns-name', u'locked', u'dns-name',
 u'pricing', u'cloud_id', u'ec2-availability-zone', u'aws-platform',
 u'ip-address', u'aws-product-codes', u'aws-id', u'ec2-instance-type',
 u'launched-by']
righteous.create_and_start_server(nickname, instance_type, create_server_parameters=None, server_template_parameters=None)

Creates and starts a server. Returns a tuple of operation status, href of the created, started server

Parameters:
  • nickname – String representing the nickname of the server
  • instance_type – String of the EC2 instance type
  • create_server_parameters – (optional) Dictionary of server creation parameters
  • server_template_parameters – (optional) Dictionary of ServerTemplate parameters
Returns:

tuple of operation success and server href of the new instance

righteous.stop_server(server_href, nickname=None)

Stops a server.

Parameters:
  • server_href – URL representing the server to stop
  • nickname – (optional) String representing the nickname of the server
Returns:

requests.Response

righteous.delete_server(server_href, nickname=None)

Deletes a server from RightScale

Parameters:
  • server_href – URL representing the server to delete
  • nickname – (optional) String representing the nickname of the server
Returns:

Boolean of operation success/failure

ServerTemplate API

righteous.list_server_templates()

Lists ServerTemplates

Returns:list of dicts of server information with the following keys:
[u'description', u'is_head_version', u'created_at', u'updated_at',
 u'href', u'version', u'nickname']
righteous.server_template_info(template_href)

Details ServerTemplate information

Parameters:template_href – String representing the server template href
Returns:dict of server template information, with the following keys:
[u'description', u'is_head_version', u'created_at', u'updated_at',
 u'href', u'version', u'nickname']
righteous.create_server_template(nickname, description, multi_cloud_image_href)

Create a new ServerTemplate

Returns a tuple of operation status, href of the created, started server

Parameters:
  • nickname – String of the template nickname
  • description – String describing the ServerTemplate
  • multi_cloud_image_href – String of the template image href
Returns:

tuple of operation success and new server template href

righteous.delete_server_template(server_template_href)

Deletes a ServerTemplate

Parameters:server_template_href – String of the ServerTemplate to delete
Returns:Boolean of operation success/failure

Deployment API

righteous.list_deployments()

Lists server deployment in an account

Returns:dict of server deployment information with the following keys:
[u'href', u'description', u'tags', u'default_ec2_availability_zone',
 u'default_vpc_subnet_href', u'created_at', u'nickname', u'updated_at',
 u'servers']
righteous.find_deployment(nickname)

Finds a server deployment based on nickname

Parameters:nickname – (optional) String representing the nickname of the deployment to lookup
Returns:dict of deployment information with the following keys:
[u'href', u'description', u'tags', u'default_ec2_availability_zone',
 u'default_vpc_subnet_href', u'created_at', u'nickname', u'updated_at',
 u'servers']
righteous.deployment_info(deployment_href, nickname=None)

Detailed server deployment information

Parameters:
  • deployment_href – URL representing the deployment to retrieve information about
  • nickname – (optional) String representing the nickname of the deployment
Returns:

dict of deployment information with the following keys

[u'href', u'description', u'tags', u'default_ec2_availability_zone',
 u'default_vpc_subnet_href', u'created_at', u'nickname', u'updated_at',
 u'servers']
righteous.create_deployment(nickname, description)

Creates a server deployment

Parameters:
  • nickname – Nickname of the new deployment
  • description – Description of the new deployment
righteous.delete_deployment(deployment_href, nickname=None)

Deletes a server deployment

Parameters:
  • deployment_href – URL representing the deployment to delete
  • nickname – (optional) String representing the nickname of the deployment
Returns:

Boolean of operation success/failure

righteous.duplicate_deployment(deployment_href, nickname=None)

Duplicates a server deployment

Parameters:
  • deployment_href – URL representing the deployment to duplicate
  • nickname – (optional) String repesenting the nickname of the deployment to duplicate
Returns:

tuple of operation success Boolean and deployment href of the duplicated instance