haunm haunm - 3 months ago 28
Ruby Question

SoftLayer API retrieve total network devices from Hardware

I'm using a ruby application along with the 'softlayer' gem to retrieve all the hardware (getHardware) and virtual machines (getVirtualGuests) associated to our accounts. A question has come up about differentiating between network devices and machines. I understand there are separate calls for getting certain network info and devices. However, I'm wondering if network device information falls under the getHardware/getVirtualGuests results. The "getHardware" call is returning several devices with a "Vyatta" operating system so can I assume "getHardware" retrieves all our network devices as well? If this is true, is there a way I can reliably determine if a device is a network device other than the operating system value? Example program:

require 'rubygems'
require 'softlayer_api'
require 'pp'

client = SoftLayer::Client.new(:username => user, :api_key => api_key, :endpoint_url => endpoint_url, :timeout => 99999999)

account = client['Account'].object_mask("mask[virtualGuestCount,hardwareCount]").getObject()

bare_metal_machines_count = account["hardwareCount"]

for i in 0..(bare_metal_machines_count/30.0).ceil - 1
list_of_baremetal_machines = client['Account'].result_limit(i*30,30).object_mask("mask[id, hostname, backendNetworkComponents[primarySubnet[podName]], hourlyBillingFlag, fullyQualifiedDomainName, provisionDate, datacenter[name], billingItem[recurringFee, associatedChildren[recurringFee], orderItem[description, order[userRecord[username], id]]], operatingSystem[id, softwareLicense[id, softwareDescription[longDescription]]], tagReferences[tagId, tag[name]], primaryIpAddress, primaryBackendIpAddress]").getHardware
for x in 0..list_of_baremetal_machines.length - 1
pp list_of_baremetal_machines[x]
end
end


Thank you.

Answer

when you call the getHardware method returns all bare metal servers, the reason why you are seeing several "Vyatta" servers is because they are bare metal servers as well,but with a "Vyatta" operating system.

you can use the http://sldn.softlayer.com/reference/services/SoftLayer_Search/advancedSearch method to get and filter your data, that is the method that the portal uses.

here some examples:

List hardwares:

# Get Hardware list using SoftLayer_Search::advancedSearch
#
# 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/'

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')

filter_data = 'networkGatewayMemberFlag:0 _objectType:SoftLayer_Hardware'

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

List gateway members:

# Get Gateway Member list using SoftLayer_Search::advancedSearch
#
# 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/'

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')

filter_data = 'networkGatewayMemberFlag:1 _objectType:SoftLayer_Hardware'

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

List netscalers:

# Get Netscaler list using SoftLayer_Search::advancedSearch
#
# 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/'

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')

filter_data = '_objectType:SoftLayer_Network_Application_Delivery_Controller'

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

List Firewalls:

# Get Firewall list using SoftLayer_Search::advancedSearch
#
# 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/'

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')

filter_data = '_objectType:SoftLayer_Network_Vlan_Firewall'

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

List all devices:

# Get all items from Device list.
#
# 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/'

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 = '_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