基于这个问题的答案:
Error when using SoftLayer Ruby API to specific additional disks with a virtual server
我已经将我的脚本转换为使用placeOrder并使其与单个磁盘一起工作但我仍然坚持如何指定第二个磁盘。此代码是我尝试指定两个磁盘:
/usr/lib64/ruby/2.1.0/xmlrpc/client.rb:271:in `call': No disk categories available for price with id 23065. (XMLRPC::FaultException)
from /usr/lib64/ruby/gems/2.1.0/gems/softlayer_api-3.0.0/lib/softlayer/Service.rb:281:in `call_softlayer_api_with_params'
from /usr/lib64/ruby/gems/2.1.0/gems/softlayer_api-3.0.0/lib/softlayer/Service.rb:210:in `method_missing'
from ./slt:66:in `<main>'
但它会产生错误:
{{1}}
如何按顺序为虚拟服务器指定第二个磁盘?
答案 0 :(得分:1)
“ 23065 ”价格有以下几类:
和“ 29237 ”:
这意味着“ 23065 ”商品价格只能作为第一张磁盘订购,而“ 29237 ”则可以订购:第二张,第三张,第四张或第五张磁盘。
以下脚本将有助于提供有关商品价格及其类别的信息:
# Get item prices
#
# This script will display the general information related
# to a single SoftLayer product item price
#
# See below references for more details.
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
# @License: http://sldn.softlayer.com/article/License
# @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
require 'rubygems'
require 'softlayer_api'
# Your SoftLayer username and apiKey
SL_API_USERNAME = 'set me'
SL_API_KEY = 'set me'
# Set the ID of the package to retrieve the information
package_id = 46
# Connect to SoftLayer
client = SoftLayer::Client.new(
username: SL_API_USERNAME,
api_key: SL_API_KEY
)
# Text format for our prettified output
header_format = "%s - %s:\n"
item_format = " %s:\n"
category_format = " %s -- %s\n"
# Set the object mask to retrieve categories
category_object_mask = 'mask[categories]'
# Get all itemPrices for this package
prices = client['SoftLayer_Product_Package'].object_mask(category_object_mask).object_with_id(package_id).getItemPrices
prices.each do |price|
printf(header_format, 'Product item price', price['id'])
unless price['hourlyRecurringFee'].nil?
printf(" %s - %s\n", 'Hourly price(hourlyRecurringFee)', price['hourlyRecurringFee'])
end
printf(item_format, 'Item')
printf(category_format, price['item']['id'], price['item']['description'])
unless price['categories'].nil?
categories = price['categories']
printf(item_format, 'Categories:')
categories.each do |category|
printf(category_format, category['id'], category['name'])
end
end
end
参考文献:
答案 1 :(得分:0)
在我发布问题后,我意识到有两种不同的100GB SAN价格项目。其中一个键名为GUEST_DISK_100_GB_SAN,对应于示例代码中使用的23065项。这些也是键名为GUEST_DISK_100_GB_SAN_3的项目。当我使用那个id时,事情就像例外一样。所以当我改变订单时:
{'id' => 23065 }, # 100 GB (SAN)
{'id' => 23065 }, # 100 GB (SAN)
到
{'id' => 23065 }, # 100 GB (SAN)
{'id' => 29237 }, # 100 GB (SAN)
{'id' => 29237 }, # 100 GB (SAN)
我最终得到了一个虚拟服务器,该服务器由一个带有两个额外100GB磁盘的图像模板制成。