The project I am currently working on requires me to upload and download files to and from swift object storage on an Openstack cloud instance. I have all of the API information required to login to the Openstack instance, but I can't figure out how to use the swiftclient from inside python.
I am specifically trying to use the swiftclient from inside python, not the swift command line interface. I need to be able to respond to exceptions that occur during swift operations.
My current attempt at connecting and posting a container looks like this:
try:
opts = dict(tenant_id=<tenant id value>, region_name=<region name>)
swift_conn = swiftclient.client.Connection(authurl=<auth url>, user=<username>, key=<password>, tenant_name=<tenant name>, os_options=opts)
swift_conn.post_container(cont)
swift_conn.close()
except swiftclient.exceptions.ClientException:
print(traceback.format_exc())
This fails because the post_container method requires at least one header value. I haven't been able to find out what constitutes a valid header for a swift request.
More importantly, I'm not certain this is even the correct way to go about executing a swift operation. I have read through the documentation (http://docs.openstack.org/developer/python-swiftclient/swiftclient.html#module-swiftclient.exceptions) and the source code (https://github.com/openstack/python-swiftclient/blob/master/swiftclient/client.py) but have found both to be somewhat obtuse. While there is some direction for what methods there are and what arguments they require, there is no clear order of operations for executing a generic swift operation.
If anyone could provide some advice or guidance on the general process for this, that would be greatly appreciated. I can likely extrude the solution to a post_container request to solve my own problems with the rest of the operations.