问题描述
我跟随 softlayer-object-storage-python 符合特定条件的对象列表.
无论我投入什么搜索,该代码似乎都返回我的容器中的所有内容
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的开头的东西.
我也尝试使用^=icm10restapi-qa.zip,但也没有运气.
推荐答案
查看该方法,似乎无法按照您的要求过滤对象:
https://github. com/softlayer/softlayer-object-storage-python/blob/master/object_storage/client.py#l147
我为您的不便而道歉,我建议尝试在您的代码中过滤这些.
更新
此脚本将有助于用特定字符串
开始的名称过滤您的对象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)
问题描述
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.*")
I expect only to get back things that start with 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:
API Operations for Search Services
My apologizes for the inconveniences, I recommended to try filter these in your code.
Updated
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)