【问题标题】:Error when using SoftLayer Ruby API to specify addtional disks with a virtual server使用 SoftLayer Ruby API 为虚拟服务器指定附加磁盘时出错
【发布时间】:2016-05-10 20:14:22
【问题描述】:

基于这个问题的答案:

Error when using SoftLayer Ruby API to specific additional disks with a virtual server

我已将我的脚本转换为使用 placeOrder 并让它与单个磁盘一起工作,但我仍然坚持如何指定第二个磁盘。这段代码是我尝试指定两个磁盘:

#!/usr/bin/ruby

require 'softlayer_api'

client = SoftLayer::Client.new(username: 'USER', api_key: 'APIKEY')

productOrder = {
  'virtualGuests' => [{
     'hostname' => 'test',
     'domain'   => 'mycompany.com',
     'primaryBackendNetworkComponent' => { 'networkVlan' => { 'id' => XXXXX } }
  }],
  'location' => XXXXX,
  'packageId' => 46,
  'imageTemplateId' => XXXXX,
  'useHourlyPricing' => true,
  'prices' => [
     {'id' => 26125 }, # 1 x 2.0 GHz Core
     {'id' => 32597 }, # 1 GB RAM
     {'id' => 23065 }, # 100 GB (SAN)
     {'id' => 23065 }, # 100 GB (SAN)
     {'id' => 34183 }, # 0 GB Bandwidth
     {'id' => 24713 }, # 1 Gbps Public & Private Network Uplinks
     {'id' => 34807 }, # 1 IP Address
     {'id' => 33483 }, # Unlimited SSL VPN Users & 1 PPTP VPN User per account
     {'id' => 34241 }, # Host Ping and TCP Service Monitoring
     {'id' => 32500 }, # Email and Ticket
     {'id' => 35310 }, # NESSUS_VULNERABILITY_ASSESSMENT_REPORTING
     {'id' => 23070 }, # REBOOT_REMOTE_CONSOLE
     {'id' => 32627 }  # AUTOMATED_NOTIFICATION
  ]
}
order = client['Product_Order'].verifyOrder(productOrder) here

但它会产生错误:

/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>'

如何为虚拟服务器指定订单中的第二个磁盘?

【问题讨论】:

    标签: ibm-cloud-infrastructure


    【解决方案1】:

    23065”价格分为以下几类:

    1. 第一个磁盘

    和“29237”:

    1. 第二个磁盘
    2. 第三盘
    3. 第四盘
    4. 第五盘

    表示“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
    

    参考资料:

    【讨论】:

    • 类别列表非常有用,因为其他一些磁盘大小没有在第一个和第二个磁盘之间使用不同的价格 id,所以唯一的方法是判断哪些对第二个磁盘有效使用类别。
    【解决方案2】:

    在我发布我的问题后,我意识到有两个不同的 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 磁盘组成的虚拟服务器。

    【讨论】:

      猜你喜欢
      • 2016-09-04
      • 1970-01-01
      • 1970-01-01
      • 2019-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      相关资源
      最近更新 更多