2016-06-08 85 views
0

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

查看https://github.com/softlayer/softlayer-object-storage-python/blob/master/object_storage/storage_object.py中的代码,它接受(自身,数据,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 

也试过,但它不工作。

谢谢!

回答

0

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

所以要验证TTL头存在,您可以使用此代码行:

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

的情况下,TTL值做:

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

那么你可以使用下面这行代码更新TLL不存在,并且您启用了cdn尝试使用此行代码创建标题:

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

Re GARDS

+0

我明白了。如果我想从对象存储中删除文件而不仅仅是缓存过期,我该如何指定“expires at”? – kyl

+0

我认为这个功能不存在,我在OpenStack http://developer.openstack.org/api-ref-objectstorage-v1.html中看不到任何东西,如果你知道如何使用softlayer对象存储是基于open stack的话,在开放堆栈中执行它应该在softlayer中也可以工作 –