Here is a Simple Python Script to Upload Files to OpenStack Swift, for Our Case HP Cloud CDN. Very easy to use from Mac or Linux Server. This is an expected thing to our regular readers whom are following our previous guides. We wanted to work with only Python Swift Client. That is the only near Error Free Tool so far.
What You Need To Know Before Using This Python Script to Upload Files to OpenStack Swift (HP Cloud CDN)
You need to read our previous guides :
- Upload to HP Cloud CDN Using OpenStack Swift Client
- WordPress W3TC Setup to Upload Files to HP Cloud CDN Using OpenStack Swift Client
From those guides, you have to find the links to install and configure Python Swift Client. You must have that openrc.sh
file imported in your .zshrc
or .bashrc
file. In other words, swift
command must be working.
---
Python Script to Upload Files to OpenStack Swift (HP Cloud CDN)
It is a very simple file named upload.sh
. Upon running the script, it will ask for the path (or file) you want to upload things from and the container name. After the work is done, it will give you the message with time stamp.
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 Swift Container Name Below:” read container echo ” “ swift upload $container $target finish= date "+%Y-%m-%d-%H-%M-%S"echo “Upload completed at ${finish}” |
Yeah, quite basic; but that basic script was not available. As the bash is set for Python, it will not throw error, at least on OS X. To use it, run :
1 2 3 4 | git clone https://github.com/AbhishekGhosh/OpenStack–Swift–Upload–Script.git cd OpenStack–Swift–Upload–Script* chmod +x upload.sh sh upload.sh |
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, like :
1 | test |
and hit the Return / Enter Key. For me, it gave output :
1 2 3 | /Users/abhishekghosh/Desktop/cdn/.DS_Store /Users/abhishekghosh/Desktop/cdn/OpenShift WordPress Multisite.png Upload completed at 2015–01–31–02–45–13 |
You can omit No handlers could be found for logger “keystoneclient.httpclient” error. Thats not our fault.
Easy thing. But that is showing some light towards a plain web based tool, WordPress Plugin and many stuffs. Without sudo
it is running. When OS X it is running, it should work fine for Linux, there is no UNIX Wheel Group.
Next Steps
Adding Meta Data. Most important.
Adding the function to copy static files from directory A to directory B. Then upload.
Adding the Auth System within the script.
Integrating with Original Swift Client.
Adding Colors.
Porting as WordPress Plugin.
Right now, it will crudely copy all. Programmatically it is important. By usage, you might not find very very useful. We will try to execute it via PHP. That will avoid installing the Junks.
The things are reminding me of the Lady who on her off time wrote a punch card to input data to a kind of mechanical machine.
Tagged With cdn file upload python , how to upload file to openstack swift via webpage , paperuri:(b4109fe7a261bc1479953abad1ac89fa) , python script to upload file , python scripting accesing Openstack file