SoftLayer SLCLI 对象过滤器语法 - 日期和布尔比较

SoftLayer SLCLI Object Filter Syntax - Date and Boolean Comparisons

命令#1

slcli call-api Account getUsers --mask=username,secondaryLoginRequiredFlag --filter 'users.secondaryLoginRequiredFlag!=True'

命令#2

slcli call-api Account getUsers --mask=username,successfulLogins.createDate,successfulLogins.ipAddres --filter 'users.successfulLogins.createDate>=2017-01-01T00:00:00-06:00'

目前不完全支持使用 SCLI 的对象过滤器,它仅适用于某些情况,例如:

slcli call-api Account getUsers --mask=username,secondaryLoginRequiredFlag --filter "users.username=sl307608-rcabero"

另一件事是它只适用于相等的情况,你可以在代码中验证:

https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/CLI/call_api.py#L17-L19

因此,如果您确实需要 objectFilters,最好的选择是为此使用 python 脚本,而不是使用 scli:

有关详细信息,请参阅本文:

https://sldn.softlayer.com/article/object-filters

也可以在SoftlayerPython客户端提交此issue:

https://github.com/softlayer/softlayer-python/issues

但我不确定他们会很快修复它。

这里是一个使用 Python 脚本的例子

import SoftLayer

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
accountService = client['SoftLayer_Account']

# Filter the users whose secondaryLoginRequiredFlag = false
filterLoginFalse = {"users":{"secondaryLoginRequiredFlag":{"operation":  "!= 1"}}}
# Filter the users whose secondaryLoginRequiredFlag = null
filterLoginNull = {"users":{"secondaryLoginRequiredFlag":{"operation":  "is null"}}}

userLoginFalse = accountService.getUsers(filter=filterLoginFalse)
userLoginNull = accountService.getUsers(filter=filterLoginNull)

users = userLoginFalse + userLoginNull

print (users)

# Filter the users created betwern a derteminated date the date must have the following format mm/dd/YY
filterDate = {"users":{"createDate":{"operation":"betweenDate","options":[{"name":"startDate","value":["2/4/2014 00:00:00"]},{"name":"endDate","value":["2/4/2014 10:40:00"]}]}}}
users = accountService.getUsers(filter=filterDate)

print (users)

此致