0

我无法将 object_mask 应用于我正在检索的数据。这是我正在做的一个片段:

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

当我打印“机器”时,它仍在打印所有字段。预先感谢您的任何帮助。

$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
4

2 回答 2

1

我无法使用带有“BareMetalServer.find_servers”的掩码获取特定项目,但下面是另一个可能对您有所帮助的 ruby​​ 示例:

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

参考:

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
于 2015-12-16T00:42:24.423 回答
0

目前 find_servers 方法的 ojectMask 不限制字段,它会将对象掩码的字段添加到结果中。

如果您需要限制字段,您可以使用“map”来创建一个仅包含您感兴趣的字段的数组。

于 2015-12-16T16:37:10.293 回答