【问题标题】:Error when using the SoftLayer Ruby API to specify a flavor使用 SoftLayer Ruby API 指定风味时出错
【发布时间】:2018-01-04 00:40:27
【问题描述】:

我有一个工作的 ruby​​ 脚本,我们已经使用了很长一段时间来从 SoftLayer 订购 VSI。该脚本为 CPU 指定一个价格项目,一个用于内存,另一个用于磁盘。我正在尝试修改脚本以使用各种口味,但我一直无法弄清楚我做错了什么。基本上我已经从产品订单中删除了 CPU、内存和磁盘价格项目,并在supplementalCreateObjectOptions 中添加了一个flavorKeyName,如下所示:

#!/usr/bin/ruby

require 'softlayer_api'

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

 productOrder = {
  'virtualGuests' => [{
     'hostname' => 'test',
     'domain'   => 'mycompany.com',
     'primaryNetworkComponent' => { 'networkVlan' => { 'id' => XXXXXX } },
     'primaryBackendNetworkComponent' => { 'networkVlan' => { 'id' => XXXXXX },
     'supplementalCreateObjectOptions' => { 'flavorKeyName' => 'B1_1X2X100' } }
  }],
  'location' => XXXXXX,
  'packageId' => 46,
  'imageTemplateId' => XXXXX,
  'useHourlyPricing' => true,
  'prices' => [
     {'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)

但这失败了:

/usr/lib64/ruby/2.1.0/xmlrpc/client.rb:271:in `call': Internal Error (XMLRPC::FaultException)
    from /usr/lib64/ruby/gems/2.1.0/gems/softlayer_api-3.2.2/lib/softlayer/Service.rb:269:in `call_softlayer_api_with_params'
    from /usr/lib64/ruby/gems/2.1.0/gems/softlayer_api-3.2.2/lib/softlayer/Service.rb:198:in `method_missing'
    from /tmp/yy2:34:in `<main>'

该错误对我可能指定不正确或可能丢失的内容没有太大帮助。

有人对我可能做错的地方有什么建议吗?

【问题讨论】:

    标签: ibm-cloud ibm-cloud-infrastructure


    【解决方案1】:

    使用Softlayer_Product_Order::verifyOrderSoftlayer_Product_Order::placeOrder时需要使用包835,并设置presetId参数指定你要订购的风味配置。

    supplementalCreateObjectOptions参数是在使用SoftLayer_Virtual_Guest::createObject方法时指定的。

    以下是订购具有风味配置的虚拟访客设备的两种方法。

    下单

    要获取包 835 的可用预设 ID 列表,您需要使用方法 SoftLayer_Product_Package::getActivePresets

    https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/835/getActivePresets
    

    检查 keyName 值以了解哪些是 Balanced、Memory 等,它们应该以:

    B1 代表“平衡”

    BL1 用于“平衡本地存储”

    BL2 用于“平衡本地存储 - SSD”

    C1 用于“计算”

    M1代表“记忆”

    这些字符后面是 VSI 配置的简短描述,如下所示:

    C1_2X2X100,用于具有“2 个 2.0 GHz 内核、2 GB RAM、100 GB 磁盘”的计算 VSI

    B1_8X16X25 用于具有“8 个 2.0 GHz 内核、16 GB RAM、25 GB 磁盘”的平衡 VSI

    如果我没记错的话,presetId 333 适用于 B1_1X2X100,这是您想要的风味配置。

    require 'rubygems'
    require 'softlayer_api'
    require 'json'
    
    # Your SoftLayer API username and API Key.
    USERNAME = 'set-me'
    API_KEY = 'set-me'
    
    # Location where server will be provisioned.
    location = 'AMSTERDAM03'
    
    # The id of the SoftLayer_Product_Package, use the 835 for VSI Families.
    package_id = 835
    
    # Following is the preset id used to complete this example. 
    preset_id = 333   # B1_1X2X100  (1 x 2.0 GHz Cores, 2 GB RAM, and primary disk of 25 GB)
    
    # The number of servers you wish to order in this configuration.
    quantity = 1
    
    # Build a skeleton SoftLayer_Virtual_Guest object. If you set quantity greater than 1 
    # then you need to define one hostname/domain per server you wish to order.
    virtual_guest = [
        {
            'hostname' => 'test-vsi', 
            'domain' => 'mycompany.com',
            'primaryNetworkComponent' => { 'networkVlan' => { 'id' => 11111 } },
            'primaryBackendNetworkComponent' => { 'networkVlan' => { 'id' => 22222 }}
        }
    ]
    
    # Specify the item prices. Note that you don't need to specify the item price for 
    # cpus, ram, and primary disk, and take into account that “Balanced Local Storage”
    # and “Balanced Local Storage - SSD” requires a second disk, the system will select one
    # if you don’t specify it. 
    prices = [
        {'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
    ]
    
    # Build a skeleton SoftLayer_Container_Product_Order object containing the order
    # you wish to place.
    order_template = {
        'quantity' => quantity,
        'location' => location,
        'packageId' => package_id,
        'presetId' => preset_id,    
        'imageTemplateId' => 1111111,
        'useHourlyPricing' => true,
        'prices' => prices,    
        'virtual_guest' => virtual_guest
    }
    
    # Declare the API client to use the SoftLayer_Product_Order API service
    client = SoftLayer::Client.new(username: USERNAME, api_key: API_KEY)
    product_order_service = client.service_named('SoftLayer_Product_Order')
    
    begin
      # verifyOrder() will check your order for errors. Replace this with placeOrder()
      # when you're ready to order. 
      receipt = product_order_service.verifyOrder(order_template)
      puts JSON.pretty_generate(receipt)
    rescue StandardError => exception
      puts "There was an error in your order: #{exception}"
    end
    

    创建对象

    考虑到 createObject 方法是订购虚拟访客设备的一种简化方法,因此您可能无法设置 IPV6、辅助 IP 地址等项目。请参阅SoftLayer_Virtual_Guest::createObject 了解哪些属性你可以设置。

    下面的例子是订购一个vsi系列,风格配置为B1_1X2X100,在这种情况下需要设置参数supplementalCreateObjectOptions

    require 'rubygems'
    require 'softlayer_api'
    require 'json'
    
    # Your SoftLayer API username and API Key.
    USERNAME = 'set-me'
    API_KEY = 'set-me'
    
    # Build the skeleton of SoftLayer_Virtual_Guest object.
    virtual_guest_template = {
        'hostname' => 'test-vsi',
        'domain' => 'mycompany.com',
        'primaryNetworkComponent' => { 'networkVlan' => { 'id' => 11111 } },
        'primaryBackendNetworkComponent' => { 'networkVlan' => { 'id' => 22222 }},
        'datacenter' => { 'name' => 'dal05' },
        'supplementalCreateObjectOptions' => {
            'flavorKeyName' => 'B1_1X2X100'
        },
        'hourlyBillingFlag' => true,
        # Following is to specify the imageTemplate you want to use. But on this case you need
        # to set the globalIdentifier of imageTemplate.
        'blockDeviceTemplateGroup' => {      
          'globalIdentifier' => '6x06c3x8-4158-4b69-ba5x-433c18x3xac3'
        },
        'networkComponents' => [
            { 'maxSpeed' => 1000}   # 1 Gbps Public & Private Network Uplinks
        ]
    }
    
    # Declare the API client to use the SoftLayer_Virtual_Guest API service
    client = SoftLayer::Client.new(username: USERNAME,  api_key: API_KEY)
    virtual_guest_service = client['SoftLayer_Virtual_Guest']
    
    begin
      # Call to createObject() when you're ready to order. 
      # Call to generateOrderTemplate() if you want to create an order container that can be
      # used with the methods verifyOrder and  placeOrder. 
      virtual_guest = virtual_guest_service.createObject(virtual_guest_template)
      puts JSON.pretty_generate(virtual_guest)
    rescue StandardError => exception
      puts "There was an error in your order: #{exception}"
    end
    

    【讨论】:

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