1

我正在尝试使用以下程序将标签添加到我的 SoftLayer 机器:

hardware_service = SoftLayer::Service.new("SoftLayer_Hardware", :username => "abc", :api_key => "123", :timeout => 999)

machine =  hardware_service.object_with_id(123456).getObject
pp machine.addTags("test")

该程序失败,错误是 Function ( "addTags") 不是该服务的有效方法。非常感谢任何解决此问题的帮助。

4

1 回答 1

1

使用 SoftLayer_Hardware::setTags 尝试以下 Ruby 脚本。显然“addTags”没有按预期工作。

例子:

# Set tags for a Bar metal
#
# The script sets the tags for a Bar metal,
# it makes a single call to the SoftLayer_Hardware::setTags method
# For more information please see below.
#
# Important manual pages:
# http://sldn.softlayer.com/reference/services/SoftLayer_Hardware/setTags
#
# License: http://sldn.softlayer.com/article/License
# Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
require 'softlayer_api'
require 'pp'

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

# The Hardware Id you wish to set the tags
hardware_id = 122145
# The tags you wish to set in the server
tags = 'mytag1, mytag2'

client = SoftLayer::Client.new(username: USERNAME, api_key: API_KEY)
virtual_guest_service = client['SoftLayer_Hardware']

begin
  # Sending the request to get the tags
  result = virtual_guest_service.object_with_id(hardware_id).setTags(tags)
  pp result
rescue StandardError => exception
  pp "Unable to set the tags. : #{exception}"
end

参考:

http://sldn.softlayer.com/reference/services/SoftLayer_Hardware/setTags

注意: 如果您的服务器有以前的标签,则在执行脚本时它必须包含在标签集中。否则会被覆盖。

于 2016-01-20T23:49:33.460 回答