Softlayer 对象存储 Python API 搜索 [英] Softlayer Object Storage Python API Search
问题描述
我跟随 softlayer-object-storage-python 以返回一个符合特定条件的对象列表.
I followed softlayer-object-storage-python in order to return a list of my objects matching a specific criteria.
无论我在搜索中输入什么,这段代码似乎都会返回我容器中的所有内容
This code seems to just return everything in my container no matter what I put into the search
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[environment['object_container']]
# get list, the search function doesn't actually work...
containers = sl_container.search("icm10restapi-qa.zip.*")
我希望只找回以 icm10restapi-qa.zip 开头的内容.
I expect only to get back things that start with icm10restapi-qa.zip.
我也尝试过使用 ^=icm10restapi-qa.zip
但也没有运气.
I also tried using ^=icm10restapi-qa.zip
but no luck either.
推荐答案
查看方法,似乎无法按照您的意愿过滤对象:
Reviewing the method, it seems that there is not possible to filter the objects as you would like:
对于给您带来的不便,我深表歉意,我建议您尝试在您的代码中过滤这些内容.
My apologizes for the inconveniences, I recommended to try filter these in your code.
更新
此脚本将帮助过滤名称以特定字符串开头的对象
This script will help to filter your objects with the name which starts as specific string
import object_storage
import pprint
# Declare username, apikey and datacenter
USERNAME = 'set me'
API_KEY = 'set me'
DATACENTER = 'https://dal05.objectstorage.softlayer.net/auth/v1.0/'
# Creating object storage connection
sl_storage = object_storage.get_httplib2_client(USERNAME, API_KEY, auth_url=DATACENTER)
# Declare name to filter
name = 'icm10restapi-qa.zip'
# Filtering
containers = sl_storage.search(name)
for container in containers['results']:
if container.__dict__['name'].startswith(name):
print(container)
这篇关于Softlayer 对象存储 Python API 搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!