November 23, 2017


get_items_from_device_list_by_location.rb
get_items_from_device_list_by_location.rb

# Get all items from Device according to an specific location
#
# Important manual pages:
# see http://sldn.softlayer.com/reference/services/SoftLayer_Search/advancedSearch
#
# license <http://sldn.softlayer.com/article/License>
# author SoftLayer Technologies, Inc. <sldn@softlayer.com>

require 'rubygems'
require 'softlayer_api'

# Your SoftLayer API username.
SL_API_USERNAME = 'set me'

# Your SoftLayer API key.
SL_API_KEY = 'set me'

# Softlayer API public endpoint
API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/xmlrpc/v3.1/'

location = 'Dallas 5'

softlayer_client = SoftLayer::Client.new(username: SL_API_USERNAME,
                                         api_key: SL_API_KEY,
                                         endpoint_url: API_PUBLIC_ENDPOINT)

search_service = softlayer_client.service_named('SoftLayer_Search')

# The items with the following Device types should be displayed
# using the below filter:
# Bare Metal Server, Virtual Server, Firewall, Gateway Member, Netscaler,KVM/IP
filter_data = "datacenter.longName:\"#{location}\" _objectType:SoftLayer_Hardware,"\
              'SoftLayer_Virtual_Guest,'\
              'SoftLayer_Network_Vlan_Firewall,'\
              'SoftLayer_Network_Application_Delivery_Controller'

begin
  # Display all items same as Portal > Device List
  result = search_service.advancedSearch(filter_data)
  puts 'Process finished successfully'
  p result
rescue StandardError => e
  raise e
end

Feedback?

We would love to hear it
Open an issue