Send API requests to Rackspace Cloud Networks#

This Getting Started Guide shows how to send requests by using either of the following methods:

To learn about other ways to use Rackspace Cloud API services, see the following resources:

Install CLI clients and Cloud Networks Virtual Interface extension#

The nova client is an open-source Python client provides access to all public Rackspace Cloud Networks API methods. You can use the nova client to perform the following operations:

  1. Boot a server with isolated networks and ports.

  2. Attach and detach networks from servers (if the Cloud Networks extension is installed).

The neutron client is an open-source Python client provides access to all public Rackspace Cloud Networks API methods.

To send requests using either client, you have to install the client and set environment variables.

Prerequisites for both clients

  • Linux or Mac OS X

  • Python 2.6 or later

  • setuptools package, installed by default on Mac OS X

  • pip package

  • Rackspace Cloud account and access to Rackspace Cloud Networks

Prerequisite

Description

Python 2.6 or later

Currently, the nova client does not support Python 3.

setuptools package

Installed by default on Mac OS X.

Many Linux distributions provide packages to make setuptools easy to install.

Search your package manager for setuptools to find an installation package. If you cannot find one, download the setuptools package directly from http://pypi.python.org/pypi/setuptools.

pip package

To install the nova client on a Mac OS X or Linux system, use pip because it is easy and ensures that you get the latest version of the nova client from the Python Package Index at http://pypi.python.org/pypi/python-novaclient/>. Also, it lets you update the package later on.

Install pip through the package manager for your system:

  • Mac OS X

    $ sudo easy_install pip
    
  • The Ubuntu operating system

    $ aptitude install python-pip
    
  • Debian

    $ aptitude install python-pip
    
  • Fedora

    $ yum install python-pip
    
  • CentOS, or RHEL (from EPEL or another 3rd party repository)

    $ yum install python-pip
    

Install the nova client#

To install the nova client, perform the following steps.

  1. Run the following commands on a Mac OS X or Linux distribution to install the OpenStack and designate clients:

    $ sudo pip install rackspace-novaclient
    

Note

If you previously installed the rackspace-novaclient package, run the following command to upgrade it:

$ sudo pip install --upgrade rackspace-novaclient
  1. Export the following environment variables manually, or update your .bash_profile or .bashrc files with these variables:

export OS_AUTH_URL=https://identity.api.rackspacecloud.com/v2.0/
export OS_AUTH_SYSTEM=rackspace
export OS_USERNAME=yourUserName
export OS_TENANT_ID=yourTenantId
export OS_REGION_NAME=yourRegionName
export OS_PASSWORD=yourAPIKey

The following table describes the environment variables:

Environment variables#

Environment variable

Description

OS_AUTH_URL

The endpoint for the Identity service, which the nova client uses for authentication.

OS_AUTH_SYSTEM

The authentication system required to get your credentials.

OS_USERNAME

Your Rackspace Cloud user name.

OS_TENANT_ID

Your Rackspace Cloud tenant ID (account number)

OS_REGION_NAME

The regional endpoint (for example, DFW) where you want to deploy the Cloud Servers resources. For details, see Service access endpoints.

OS_PASSWORD

Your Rackspace API key.

If you upgrade the operating system of the desktop or remote machine where you installed nova, you may need to reinstall nova to ensure correct operation.

If you have trouble using pip to install the nova client, you can download a nova client installation package from the python package repository at http://pypi.python.org/pypi/rackspace-novaclient/, use python-pip or yum commands instead of pip.

Run the help command to ensure that the client has installed correctly and to review information about using the client.

$ nova help

To get help for a specific command, type the command name after the help parameter, as follows:

$ nova help <command_name>

You cannot use every command that is listed. The nova client was written for use with recent development versions of OpenStack, so it includes support for some features that are not available in the Rackspace Cloud. For a complete list of Openstack commands, see the OpenStack Compute command-line client reference.

Install the neutron client#

To install the neutron client for the Ubuntu operating system, Debian, or Mac OS X, run the following command:

$ sudo pip install rackspace-neutronclient

To install the neutron client for RHEL, CentOS, or Fedora, run the following command:

$ sudo python-pip install rackspace-neutronclient

Note

If you previously installed the rackspace-novaclient package, run the following command to upgrade it:

For the Ubuntu operating system, Debian, or Mac OS X:

$ pip install --upgrade rackspace-neutronclient

For RHEL, CentOS, or Fedora:

$ python-pip install --upgrade rackspace-neutronclient

You can specify a debug parameter on any neutron command to show the underlying API request for the command. This is a good way to become familiar with the API requests.

Install the Cloud Networks Virtual Interface extension#

To attach networks to existing servers, rather than just at boot time, you need to install the Virtual Interface extension by using the following command:

$ sudo pip install os_virtual_interfacesv2_python_novaclient_ext

Note

If you previously installed this package, run the following command to upgrade it:

$ sudo pip install os_virtual_interfacesv2_python_novaclient_ext --upgrade

cURL is a command-line tool that you can use to interact with REST interfaces. cURL lets you transmit and receive HTTP requests and responses from the command line or a shell script, which enables you to work with the API directly. cURL is available for Linux distributions, Mac OS® X, and Microsoft Windows®. For information about cURL, see http://curl.haxx.se/.

To run the cURL request examples shown in this guide on Mac OS® X or another Linux-based operating system, copy each example directly to the command line or a script.

Note

If you are using Microsoft Windows, you need to adjust the cURL examples to run them. See Convert cURL examples to run on Windows .

Important

The cURL examples in this guide are provided for reference only. Because the use of cURL has environmental dependencies, copying and pasting the examples might not work in your environment.

The following example shows a cURL command for sending an authentication request to the Identity service.

Example: cURL command for sending a JSON request

$ curl https://identity.api.rackspacecloud.com/v2.0/tokens  \
 -X POST \
 -d '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"yourUserName","apiKey":"$apiKey"}}}' \
 -H "Content-type: application/json" \
 | python -m json.tool

In this example, $apiKey is an environment variable that stores your API key value. Environment variables make it easier to reference account information in API requests, to reuse the same cURL commands with different credentials, and to keep sensitive information like your API key from being exposed when you send requests to Rackspace Cloud API services. For details about creating environment variables, see Configure environment variables.

Note

The cURL request examples use a backslash (\) as a line-continuation symbol, which allows the command to continue across multiple lines.

The cURL examples in this guide use the following command-line options.

Option

Description

-d

Sends the specified data in a POST request to the HTTP server. Use this option to send a JSON request body to the server.

-H

Specifies an extra HTTP header in the request. You can specify any number of extra headers. Precede each header with the -H option.

Common headers in Rackspace API requests are as follows:

  • Content-Type: Required for operations with a request body.

    Specifies the format of the request body. Following is the syntax for the header where format is json:

    Content-Type: application/json
    
  • X-Auth-Token: Required. Specifies the authentication token.

  • X-Auth-Project-Id: Optional. Specifies the project ID, which can be your account number or another value.

  • Accept: Optional. Specifies the format of the response body.

    Following is the syntax for the header where the format is json, which is the default:

    Accept: application/json
    

-i

Includes the HTTP header in the output.

-s

Specifies silent or quiet mode, which makes cURL mute. No progress or error messages are shown.

If your cURL command is not generating any output, try replacing the -s option with -i.

-T

Transfers the specified local file to the remote URL.

-X

Specifies the request method to use when communicating with the HTTP server. The specified method is used instead of the default method, which is GET.

For commands that return a response, you can use json.tool to pretty-print the output. Append the following command to the cURL call:

| python -m json.tool

To use json.tool, import the JSON module. For information about json.tool, see JSON encoder and decoder.

If you run a Python version earlier than 2.6, import the simplejson module and use simplejson.tool. For information about simplejson.tool, see simplejson encoder and decoder.

If you do not want to pretty-print JSON output, omit this code.

Note

If your request includes the -i option to show header output, do not try to pretty-print the output. Header information is not in JSON format, and the API service returns an error if you specify json.tool.

Convert cURL examples to run on Windows#

The cURL examples in the Rackspace API documentation use syntax supported on Mac OS® X, Linux, and UNIX systems. Microsoft Windows does not support the same format. However, you can run the examples on Windows after making the following changes:

  • Replace all the line-continuation backslash characters (\) with a caret (^), and remove any trailing spaces after the ^.

  • If an example includes JSON data, export the data to a text file. When you run the cURL command, use the @filename syntax to import the JSON data. Save the JSON data files in a directory, and run cURL commands from that directory.

The following example shows the cURL format for Linux and UNIX systems:

$ curl https://identity.api.rackspacecloud.com/v2.0/tokens  \
      -X POST \
      -d '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"yourUserName","apiKey":"$apiKey"}}}' \
      -H "Content-type: application/json"

The following example shows the same request with the changes made for Windows systems:

$ curl https://identity.api.rackspacecloud.com/v2.0/tokens  ^
       -X POST ^
       -d @credentials.txt  ^
       -H "Content-type: application/json"