I can get virtual guests by masks like "id", "hostname", "primaryIpAddress" etc. However, I need to get virtual guests with specific tags. What's the mask to use to retrieve tagged virtual guests?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
you need to use Objectfilter:
https://sldn.softlayer.com/article/object-filters
see this example using RESTFul request
URL : https://$USERNAME:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectFilter={"virtualGuests":{"tagReferences":{"tag":{"name":{"operation":"in","options":[{"name":"data","value":["$tag1","$tag2"]}]}}}}}
Method: GET
Note: replace $tag1 and $tag2 with the tags you wish
Regards
回答2:
I got some help. Here is the Ruby code to do it:
client = SoftLayer::Client.new(username: USERNAME, api_key: API_KEY)
account_service = client['SoftLayer_Account']
object_filter = SoftLayer::ObjectFilter.new
object_filter.set_criteria_for_key_path(
'virtualGuests.tagReferences.tag.name', 'operation' => 'in',
'options' => [{
'name' => 'data',
'value' => tagsToFind
}])
mask = 'mask[tagReferences[tag[name]]]'
result = account_service.object_mask(mask).
object_filter(object_filter).getVirtualGuests