How to get SoftLayer virtual guest by tags, what's the mask for tags?

隐身守侯 提交于 2019-12-25 04:48:09

问题


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


来源:https://stackoverflow.com/questions/39881555/how-to-get-softlayer-virtual-guest-by-tags-whats-the-mask-for-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!