November 23, 2017

Classes SoftLayer_Account
Tags tag


# Search VSI by tag
# The script retrieves all the VSIs which contain an
# arbitrary list of tags
# Important manual pages:
# License:
# Author: SoftLayer Technologies, Inc. <>
require 'softlayer_api'
require 'pp'

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

# list of tags to look for
tags = %w(tag1 tag2)

client = USERNAME, api_key: API_KEY)
account_service = client['SoftLayer_Account']

# Declaring an object filter to get only the virtual servers which contains the tags that we are looking for
object_filter =
object_filter.set_criteria_for_key_path('',           'operation' => 'in',
                                                                                          'options' => [{
                                                                                            'name' => 'data',
                                                                                            'value' => tags

  # Sending the request to get the virtual guest using the filter
  result = account_service.object_filter(object_filter).getVirtualGuests
  print result
rescue StandardError => exception
  puts "Unable to retrieve the virtual guests. : #{exception}"


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue