软件层对象存储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)
这篇关于软件层对象存储Python API搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!