使用 Python swiftclient 模块时,我可以 POST 到带有 X-Delete-At/After 标头和纪元的对象,但是如何显示对象的到期时间?我正在做一些测试,似乎该文件总是立即过期,例如我将时间设置为未来 100 天:
>>> swift.put_object('container1','test_file01.txt','This is line 1 in the file test_file01.txt done at: %s' % datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f'))
'4b3faf0b79d97f5e478949e7d6c4c575'
>>> swift.head_object('container1','test_file01.txt')
{'content-length': '78', 'server': 'Jetty(7.6.4.v20120524)', 'last-modified': 'Wed, 23 Apr 2014 17:09:55 GMT', 'etag': '4b3faf0b79d97f5e478949e7d6c4c575', 'x-timestamp': '1398272995', 'date': 'Wed, 23 Apr 2014 17:09:59 GMT', 'content-type': 'application/octet-stream'}
>>> swift.post_object('container1','test_file01.txt',headers={'X-Delete-At':(datetime.now(pytz.timezone('GMT')) + timedelta(days=100)).strftime('%s')})
>>> swift.head_object('container1','test_file01.txt')
Traceback (most recent call last):
File "<pyshell#121>", line 1, in <module>
swift.head_object('container1','test_file01.txt')
File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 1279, in head_object
return self._retry(None, head_object, container, obj)
File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 1189, in _retry
rv = func(self.url, self.token, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 853, in head_object
http_response_content=body)
ClientException: Object HEAD failed: http://10.249.238.135:9024:9024/v1/rjm-vnx-namespace01/container1/test_file01.txt 404 Not Found
所以它似乎立即过期。我的问题是:
- 我是否正确设置了过期时间?我希望能够对现有对象执行此操作,而不是在创建对象时执行此操作,但也许我必须在创建它时执行此操作???
- 有没有办法查看过期时间?显然,如果它不能正常工作,那么就没有很好的方法来查看它,但如果是这样,head_object() 是否会返回该信息?
谢谢,
抢