软层对象存储 Python API 搜索

Softlayer Object Storage Python API Search

我关注 softlayer-object-storage-python 以便 return 我的对象列表符合特定条件。

这段代码似乎只是return我容器中的所有东西,无论我在搜索中输入什么

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

API Operations for Search Services

对于给您带来的不便,我深表歉意,我建议尝试在您的代码中过滤这些内容。

Updated

此脚本将有助于过滤名称以特定字符串开头的对象

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)