Installation
You can use pip to install the python-swift API and the swfit command line API.
Follow the instructions to install python-pip relevant to your operating system, then enter the command:
MacOSX/Linux
sudo pip install python-swiftclient
Windows
pip install python-swiftclient
Configuration
Before you can use the python swift client and command line API you need to be authenticated to the NeCTAR cloud. The below shows the instructions of how to get username/password and get authenticated.
- Login to NeCTAR Cloud Dashboard
- Click 'Access & Security'
- On the 'Access & Security' page, click tab 'API Access'
- Click button "Download OpenStack RC File"
- Save the file into a directory
- Click the drop down list with your email on the right top of page, then click 'Settings'
- Click 'Reset Password' and save the password appeared on the screen
API normally requires 4 environment variables to be set for authentication:
- auth URL
- username
- project id or name (most clients can handle either)
- password
When using the script file you downloaded from NeCTAR Dashboard, these varilabels are set by the script file and you can see these variables if you open the file. Example:
OS_AUTH_URL: https://keystone.rc.nectar.org.au:5000/v2.0/
OS_TENANT_NAME=my_science_project
OS_TENANT_ID=sdfsdfsfwrwewer
OS_USERNAME=clouduser@example.edu.au
OS_PASSWORD=XXXXXX
Authentication for Command Line API
The following instruction assume you use Linux operating system.
Once you have obtained the authentication script and password, you can execute the script suing source file-name.sh
. and type in the password you
obtained from Dashboard.
Authentication for python swift API
You can use the below sample code to get authenticated.
from swiftclient import client swift = client.Connection(authurl=url, user=username, key=password, tenant_name=project_name, auth_version='2')
You can get authurl, user, key and tenant_name from the above .sh file obtained from the NeCTAR Dashboard.
How to use
Once the client is authenticated, you can start to use them. See below for how to get started.
Command Line API
You can use swift command to manage your objects storage, you can type:
swift --help
to find out all the available options.
Python Swift API
You can also use Python Swift API in your python code to access object storage.
See below for a sample code:
from swiftclient import client swift = client.Connection(authurl=url, user=username, key=password, tenant_name=project_name, auth_version='2') container_name="" swift.get_container(container_name)
You can find more information in the Object Storage API section.