[Openstack] Python API for Dynamic Large Objects in Swift

Vincenzo Pii vinc.pii at gmail.com
Wed Jul 29 07:46:53 UTC 2015


2015-07-29 8:01 GMT+02:00 Clint Byrum <clint at fewbar.com>:

> Excerpts from John Dickinson's message of 2015-07-28 22:01:54 -0700:
> > You can also use swiftclient.service module. It is the wrapper on top of
> the low-level swiftclient.client that is actually what the CLI tool uses
> for some of its higher-order functions (like splitting larger local files
> and making manifest objects).
> >
> > You'd have something like:
> >
> > results = swiftclient.service.upload('target_container',
> ['path/to/local/file',], options={'segment_size': 1048576000})
> >
>
> Indeed. To build on this, since you may have more than one cloud, we've
> added some pieces to the 'shade' library that figures out what segment
> sizes to use and just lets you pass in paths. Unfortunately I just
> noticed the create_object method isn't well documented, but I submitted
> a patch so here is that documentation:
>
> https://review.openstack.org/#/c/206872/1/shade/__init__.py
>
> Basically something like
>
>
> import shade
>
> cloud = shade.openstack_cloud()
> cloud.create_object('target_container', 'call me maybe',
> 'path/to/local/file')
>
> _______________________________________________
> Mailing list:
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
> Post to     : openstack at lists.openstack.org
> Unsubscribe :
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
>


Hi Guys,

Thanks for the inputs!

I used the same flow as the CLI part of the swift client, as John
suggested. I found it strange that the CLI and the python client APIs are
not unified, I imagined that I would have found the same interfaces after
some call layers.

So this is what I did:

import swiftclient.service
from swiftclient.service import SwiftService

swiftclient.service._default_global_options['os_username'] = ''
swiftclient.service._default_global_options['os_password'] = ''
swiftclient.service._default_global_options['os_tenant_name'] = ''
swiftclient.service._default_global_options['os_auth_url'] = ''

container_name = 'newcont'
filename = ['large_object']
segment_size = '1048576'

with SwiftService() as sw:
    for r in sw.upload(container_name, filename, {'segment_size':
segment_size}):
        print r['success']


The shade approach is actually the cleanest one!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack/attachments/20150729/16ad3871/attachment.html>


More information about the Openstack mailing list