Ask Your Question

python swift client upload object with expiration

asked 2017-02-06 19:12:41 -0500

Hey, so I'm curious as to how to achieve something along the lines of what 'X-Delete-At/After' headers provide for defining a Swift object's TTL using the python-swiftclient/openstackclient.

--~(something like this would be great) e.g

swiftclient.service.SwiftService("container", ["files"], options={"ttl": 16060*24}])

This seems like a pretty standard feature and it feels like it would be provided as an API options parameter. For some reason though, I haven't been able to find a reference to what the options 'key' would be - tried 'ttl' (which is what was provided by the similar pyrax API) and various combinations of ['time', 'to', 'live', 'expir(e)'].

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-17 16:59:38 -0500

Something like the following should work.

# Set test.txt to expire at 1505943383 (9/20/2017, 21:36:23)
swift post testcontainer test.txt -H "X-Delete-At:1505943383"

# Verify the header was applied
swift stat testcontainer test.txt

# Remove the X-Delete-At header if needed
swift post testcontainer test.txt -H "X-Remove-Delete-At: "

On the code side of things, when looking under the post function I see something like this:

:param options: A dictionary containing options to override the global
                options specified during the service object creation.
                These options are applied to all post operations
                performed by this call, unless overridden on a per
                object basis. Possible options are given below::

                        'meta': [],
                        'header': [],
                        'read_acl': None,   # For containers only
                        'write_acl': None,  # For containers only
                        'sync_to': None,    # For containers only
                        'sync_key': None    # For containers only

Looks like the 'header' key with an array headers can be passed. I'm no coder though, so take that with a grain of salt.

For the format of the header values, I found this:

def split_headers(options, prefix=''):
    Splits 'Key: Value' strings and returns them as a dictionary.

    :param options: Must be one of:
        * an iterable of 'Key: Value' strings
        * an iterable of ('Key', 'Value') pairs
        * a dict of {'Key': 'Value'} pairs
    :param prefix: String to prepend to all of the keys in the dictionary.
    headers = {}
        headers = split_request_headers(options, prefix)
    except ValueError as e:
        raise SwiftError(e)

    return headers
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2017-02-06 19:12:41 -0500

Seen: 288 times

Last updated: Feb 17 '17