Softlayer对象存储Python API生存时间

时间:2016-06-08 22:33:32

标签: python ibm-cloud-infrastructure

如何为对象存储上的文件设置生存时间?

查看https://github.com/softlayer/softlayer-object-storage-python/blob/master/object_storage/storage_object.py中的代码,它包含(self,data,check_md5),没有TTL选项。

sl_storage = object_storage.get_client(
    username = environment['slos_username'],
    password = environment['api_key'],
    auth_url = environment['auth_url']
)

# get container 
sl_container = sl_storage.get_container(environment['object_container'])
# create "pointer" to cointainer file fabfile.zip

sl_file = sl_container[filename]
myzip = open(foldername + filename, 'rb')
sl_file.create()

sl_file.send(myzip, TIME_TO_LIVE_PARAM=100)

我也根据https://github.com/softlayer/softlayer-object-storage-python/blob/master/object_storage/container.py

尝试过
sl_file['ttl'] = timetolive

但它不起作用。

谢谢!

2 个答案:

答案 0 :(得分:0)

您需要确保标题中有“ttl”,当容器启用CDN时,“TTL”标题可用。

因此要验证ttl标头是否存在,您可以使用此代码行:

sl_storage['myContainserName']['MyFileName'].headers

然后你可以使用这个行代码更新tll:

sl_storage['myContainserName']['MyFileName'].update({'x-cdn-ttl':'3600'})

如果ttl值不存在且您启用了cdn,请尝试使用此行代码创建标题:

  sl_storage['myContainserName']['MyFileName'].create({'x-cdn-ttl':'3600'})

此致

答案 1 :(得分:0)

您需要设置标题“X-Delete-At:1417341600”,其中1417341600是Unix时间戳,请在此处查看更多信息http://docs.openstack.org/developer/swift/overview_expiring_objects.html

使用Python客户端,您可以使用更新方法: https://github.com/softlayer/softlayer-object-storage-python/blob/master/object_storage/storage_object.py#L210-L216

sl_storage['myContainserName']['MyFileName'].update({'X-Delete-At':1417341600})

此致