Using the swift command line for Object Storage

COS (Swift)

Install

The OpenStack command line tool can be installed using most Package managers as outlined here but the simplest install process in most cases is to use pip:


pip install python-swiftclient

Basic Authentication and Interaction

The first thing you have to do is to authenticate against the specific Object Storage cluster you want to interact with. For our examples we will be using the Dallas 05 cluster.

  1. Access the Object Storage Screen
  2. Click the View Credentials link (record your credentials).

Authentication Syntax:


swift -A <AUTH_URL> -U <USERNAME> -K <KEY> stat -v

The command will return your Auth Token and Storage URL for interacting with Object Storage.


swift -A https://dal05.objectstorage.softlayer.net/auth/v1.0/ -U <OBJECT_STORAGE_USER> \
-K <OBJECT_STORAGE_KEY> stat -v
 
                     StorageURL: https://dal05.objectstorage.softlayer.net/v1/AUTH_xxxxxxx-d99f-4ffb-9de3-xxxxxxxxxxx
                     Auth Token: AUTH_tkexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                        Account: AUTH_bfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                     Containers: 8
                        Objects: 771
                          Bytes: 109313871291
Containers in policy "standard": 8
   Objects in policy "standard": 771
     Bytes in policy "standard": 109313871291
                    Meta Cdn-Id: 22873
                    Meta Nas-Id: 4435697
                   Content-Type: text/plain; charset=utf-8
                     X-Trans-Id: tx9ed6f83a6d2044f382fd6-005679abec
                    X-Timestamp: 1424893395.37346
                  Accept-Ranges: bytes

Create a new Container


swift post CONTAINERNAME --os-auth-token [Auth-Token from Authentication step] \
--os-storage-url [Storage-Url from Authentication step]

List Containers Example


swift --os-auth-token [Auth-Token from Authentication step] --os-storage-url [Storage-Url from Authentication step] list

List Objects in a Container


swift --os-auth-token [Auth-Token from Authentication step] --os-storage-url [Storage-Url from Authentication step]/[container name] list

Delete Object in a Container


swift delete [CONTAINER NAME] [Object Name] --os-auth-token [Auth-Token from Authentication step] --os-storage-url [Storage-Url from Authentication step]

In this example we are deleting the file "l8dcmqa-2014-02-19-0239.jpg" from the 'images' container in Object Storage


swift delete images l8dcmqa-2014-02-19-0239.jpg --os-auth-token AUTH_tkexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
--os-storage-url https://dal05.objectstorage.softlayer.net/v1/AUTH_xxxxxxx-d99f-4ffb-9de3-xxxxxxxxxxx

File Upload


swift upload CONTAINERNAME FILE --os-auth-token [Auth-Token from Authentication step] --os-storage-url [Storage-Url from Authentication step]

In this example we are uploading the file 'metadata.json' to the Container 'testing'. The output will be the name of the file you uploaded


swift upload testing metadata.json --os-auth-token AUTH_tkexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
--os-storage-url https://dal05.objectstorage.softlayer.net/v1/AUTH_xxxxxxx-d99f-4ffb-9de3-xxxxxxxxxxx
 
metadata.json