Reputation: 39
I'm having trouble getting an object_mask applied to the data I'm retrieving. Here is a snippet of what I'm doing:
client = SoftLayer::Client.new(<...hidden...>)
<BREAK>
if (item["hostName"])
machines = SoftLayer::BareMetalServer.find_servers({ :client => client, :hostname => item["hostName"], :object_mask => "[id,hostname,tagReferences]"})
machines.each do |machine|
pp machine
end
end
When I print "machine" it is still printing all the fields. Thank you in advance for any help.
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
Upvotes: 0
Views: 71
Reputation: 4386
Currently the ojectMask for the method find_servers does not limit the fields, it adds the fields of your object mask to the result.
If you need to limit the fields, you could use the use "map" to create an array with just the fields you are interested in.
Upvotes: 0
Reputation: 1532
I was not able to get specific items using masks with “BareMetalServer.find_servers”, but below is another ruby example that may help you:
require 'rubygems'
require 'softlayer_api'
# Your SoftLayer API username.
SL_API_USERNAME = 'set me'
# Your SoftLayer API key.
SL_API_KEY = 'set me'
softlayer_client = SoftLayer::Client.new(:username => SL_API_USERNAME,
:api_key => SL_API_KEY)
account_service = softlayer_client.service_named('SoftLayer_Account')
# Create an object mask to get more information than by default
mask = 'mask[id,hostname]'
begin
result = account_service.object_mask(mask).getHardware
puts 'Process finished successfully'
p result
rescue Exception => e
raise e
end
References:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware
https://softlayer.github.io/ruby/token_auth/
https://softlayer.github.io/ruby/find_my_vms/
https://softlayer.github.io/ruby/
https://www.omniref.com/ruby/gems/softlayer_api/2.1.0
https://github.com/softlayer/softlayer-ruby/blob/master/lib/softlayer/BareMetalServer.rb
Upvotes: 1