IBM Cloud CDN needs Pay-as-you-go account. We have not tested the lite version of IBM Cloud Object Storage (free trial version) for the presence of features of OpenStack Swift. In this guide, we will show how to upload objects to IBM Cloud CDN or Object Storage using OpenStack Swift client and our a helper Python script. OpenStack Swift already have long known Python clients. We have a lot of articles on this website on OpenStack Swift. The keystone API is essentially a create, read, update, delete (CRUD) interface. The keystone API is essentially a create, read, update, delete (CRUD) interface. IBM Cloud Object Storage is a low-cost storage solution that can be used for various purposes. The command line is a powerful and flexible method to access object storage.
You should either a GNU/Linux computer or server or MacOS X with iTerm2 properly configured or Microsoft Windows 10 with Ubuntu Bash application with Python pip installed.
Required Configuration Files to Upload to IBM Cloud CDN Using OpenStack Swift Client
As alternative way, you can install python-swiftclient
from apt repository too :
---
1 | apt install python-swiftclient -y |
But, age old method is to install using Python pip :
1 2 3 4 5 | # keystone client pip install python-keystoneclient # swift client pip install python-swiftclient |
What in this website we do : to simplify authentication, we create an openrc file with the credentials to environment variables and load it from .zshrc
, bashrc
etc files to make it easy. IBM system needs three lines :
1 2 3 | export ST_AUTH= (https://tor01.objectstorage.softlayer.net/auth/v1.0/ ) export ST_USER= (IBMOS278685-10:######) export ST_KEY= (#############) |
You can keep the above script where your .zshrc
, bashrc
etc files are location.
IBM’s system is configured to work with API, like Rackspace. For username-password system of OpenStack Swift access, we can use this kind of openrc file :
1 2 3 4 5 6 | export OS_AUTH_URL=https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/ export OS_TENANT_ID=xxxxxxxxxxxxxx export OS_TENANT_NAME="xxxxxxxxxxx-Project" export OS_USERNAME="yourusername" export OS_PASSWORD="yourpassword" export OS_REGION_NAME="region-a.geo-1" |
As we are using Oh-My-ZSH/ZSH shell, we will simply open the file at $HOME :
1 | nano .zshrc |
and add the thing on the bottom of the file. Then load the environment :
1 | source .zshrc |
We can use wift commands such as :
1 2 | swift stat swift list |
Download and upload objects :
1 2 | wget http://docs.openstack.org/api/openstack-object-storage/1.0/os-objectstorage-devguide-1.0.pdf swift upload test os-objectstorage-devguide-1.0.pdf |
You must have that openrc.sh
file imported in your .zshrc or .bashrc file. In other words, swift command must be working.
Create this script :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/usr/bin/env bash # -*- coding: utf-8 -*- # # Author : Dr. Abhishek Ghosh # GNU GPL 3.0 # https://thecustomizewindows.com # echo "Script to copy source files/directories to OpenStack Swift Storage" echo "Supply the source file/directory below:" read target echo "Supply the container name below:" read container echo " " swift upload $container $target finish=`date "+%Y-%m-%d-%H-%M-%S"` echo "Upload completed at ${finish}" |
Make it executable :
1 2 3 | chmod +x upload.sh sh upload.sh |
Upon run, it will ask “Supply the source file/directory below:”. You will paste/type the full UNIX path like :
1 | /Users/abhishekghosh/Desktop/cdn |
and hit the Return/Enter Key. Then it will ask “Supply the container name below:”. You’ll type only the container name on IBM Cloud and hit the Return/Enter Key.
It will return the message the upload completed with a time stamp. As usually, the required scripts for this guide kept on GitHub.
Required official documentation can be found on IBM’s these web pages :
1 2 3 4 5 6 7 | ### https://console.bluemix.net/docs/infrastructure/content-deliver-network/attach-edgecast-cdn-account-sl-object-storage.html ### ### https://console.bluemix.net/docs/infrastructure/objectstorage-swift/connect-object-storage-using-command-line.html#connecting-to-object-storage-with-the-command-line ### |