Use the OpenStack swift Command with Rackspace Cloud Files

Thursday, December 3, 2015

Rackspace Cloud Files is, and has always been, powered by OpenStack Swift.

The easiest way to interface with Rackspace Cloud Files is through the web portal or third-party clients such as Cyberduck.

However, I am frequently logged into remote servers where I need to upload files to my Rackspace Cloud Files account. It would be a waste of time, and bandwidth, to download those files to my workstation then upload them through the web portal or a third-party client. Like any OpenStack project, the project’s shell command can be used as well.

In this post I will detail how to use the swift command to connect to Rackspace Cloud Files using Swift’s v1.0 and v2.0 APIs.

To follow along you will need to have already created a Rackspace Public Cloud account.

Using Swift’s v1.0 API

Start by creating an openrc file on the server or workstation you want to use the swift command on:

export ST_AUTH=https://identity.api.rackspacecloud.com/v1.0
export ST_USER=<USERNAME>
export ST_KEY=<API KEY>

To obtain your API key:

  1. Login to your Rackspace Public Cloud account as an administrative user
  2. Click Account: USERNAME in the upper right corner of the browser window and select User Management
  3. Click the Username for the particular user you want to use with Rackspace Cloud Files
  4. Click Show next to API Key under Login Details

Now, source the variables into your shell environment:

source openrc

Then, use the swift command.

Or, if you prefer, you can skip the creation of an openrc file and have your authentication in-line with the shell command:

swift -A https://identity.api.rackspacecloud.com/v1.0/ -U <USERNAME> -K <API KEY> list

Run swift --help to see all of the functions and additional variables available to you.

Using Swift’s v2.0 API

Be aware that using Swift’s v2.0 API requires using your account’s password instead of an API key.

Like before, start by creating an openrc file on the server or workstation you want to use the swift command on:

export OS_AUTH_URL=https://identity.api.rackspacecloud.com/v2.0
export OS_USERNAME=<USERNAME>
export OS_PASSWORD=<PASSWORD>

Now, source the variables into your shell environment:

source openrc

Then, use the swift command.

Or, if you prefer, you can skip the creation of an openrc file and have your authentication in-line with the shell command:

swift -V 2.0 --os-auth-url=https://identity.api.rackspacecloud.com/v2.0 --os-username=<USERNAME> --os-password=<PASSWORD> list

Run swift --help to see all of the functions and additional variables available to you.

If needed, you can specify a region by adding the following to the openrc file:

export OS_REGION_NAME=<IAD | ORD | HKG | DFW | SYD>

Once the environment variable is added, re-source the file.

The same can be done in-line with the shell command by adding the following command line switch:

--os-region-name=<IAD | ORD | HKG | DFW | SYD>

References

Unable to get swift client CLI to work - authentication error



comments powered by Disqus