2016-01-20 59 views
1

我尝试使用下面的程序标签添加到我的SoftLayer机:错误更新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") 

该程序失败,出现错误是功能("addTags")不是该服务的有效方法。任何帮助解决这个很感激。

回答

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. <[email protected]> 
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

注: 如果你的服务器有一个标签,它必须包含在执行th时的一组标签e脚本。否则它会被覆盖。