使用 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
注意:
如果您的服务器有以前的标签,则在执行脚本时它必须包含在标签集中。否则会被覆盖。