OpenStack Swift

Once an OpenStack Swift connection has been created it is possible to execute any and all calls the underlying Python library offers.

Storing data in containers

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        with self.cloud.openstack.swift.get('My Connection').conn.client() as client:

            # What to store and where
            container = 'test123'
            object_name = 'my-document.txt'
            contents = 'Hi there'

            # Now store it
            client.put_object(container, object_name, contents)

And now on Rackspace:

../../../../_images/swift-sample-object.png

Accessing the underlying library

Connections to to Swift are built using the OpenStack's swiftclient library whose swiftclient.client.Connection objects are what the client actually is.

The client offers means to access full Swift API for reading, deleting and other operations on Swift objects - consult the client's documentation for usage details.

1
2
3
4
5
6
7
8
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        with self.cloud.openstack.swift.get('My Connection').conn.client() as client:

            # The actual connection's implementation
            self.logger.info(client)
INFO - <swiftclient.client.Connection object at 0x7f1b5842bc90>