IBM Object Storage on Bluemix

Create credential and interact with the service via Python

Jennifer Chao
2 min readAug 2, 2017

Before we start, I think we need to know what Object Storage on Bluemix is.

Object Storage on Bluemix

With Object Storage, your unstructured data is stored in a scalable, multi-tenant cloud environment. The service uses OpenStack Identity (Keystone) for authentication and can be accessed directly by using OpenStack Object Storage (Swift) API v1 calls. The service can be bound to a Bluemix application or accessed from outside a Bluemix application.

Here are some important components for understanding how Object Storage on Bluemix works.

  • Bluemix apps
  • Client apps
  • Keystone
  • Swift API
  • Storage nodes

Using Python to interact with Object Storage on Bluemix.

  1. Sign in or register a Bluemix account.
  2. Go to Service > Storage > Object Storage to create an Object Storage service.
  3. Create a Service credential for your Bluemix Object Storage by clicking “New credential +”.
  4. After creating a credential, you will have the following information for later use.
{
"auth_url": "https://identity.open.softlayer.com/v3",
"project": "object_storage_12345",
"projectId": "aaabbbccc",
"region": "dallas",
"userId": "1234567890",
"username": "admin_1234567890",
"password": "aaa1234bbb5678",
"domainId": "0987654321",
"domainName": "abcde",
"role": "admin"
}

5. Configure Swift CLI for interacting with the Object Storage service.

  • Using Python 2.7 or later
  • pip package
  • Cloud Foundry CLI (Optional for now)
  • Install the Python Swift Client by running the following commands:
$ pip install python-swiftclient
$ pip install python-keystoneclient
  • Establish connection to IBM Object Storage and print account details via Python
import swiftclient from keystoneclient 
import client
import os
import re
container_name = 'test_Container'
file_name = 'test.txt'
# use the credential info we got previouslyauth_url = "https://identity.open.softlayer.com/v3"
project = "object_storage_12345"
projectId = "aaabbbccc"
region = "dallas"
userId = "1234567890"
username = "admin_1234567890"
password = "aaa1234bbb5678"
#-----------------------------------------------------------------# # # # Establish Connection to IBM Object Storage # # And print account details # # # #-----------------------------------------------------------------#IBM_Objectstorage_Connection = swiftclient.Connection(key=password,authurl=auth_url,auth_version='3', os_options={"project_id": projectId,"user_id": userId,"region_name": region})

x = IBM_Objectstorage_Connection.get_account()[1]
print(x)#-----------------------------------------------------------------# # # # Create a new container # # # #-----------------------------------------------------------------#IBM_Objectstorage_Connection.put_container(container_name)print("nContainer %s created successfully." % container_name)#-----------------------------------------------------------------# # # # List all the containers # # # #-----------------------------------------------------------------#print("nContainer List:")

for container in IBM_Objectstorage_Connection.get_account()[1]:
print(container['name'])
# For more Swift methods,
# please take a look at the example provided by OpenStack

--

--