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

╄→尐↘猪︶ㄣ 提交于 2019-12-23 19:56:28

问题


We are seeing same issue with the SoftLayer Ruby API as in this post:

CLI - Error when disk parameter is in use

This code can reproduce the issue:

#!/usr/bin/ruby

require 'softlayer_api'

def image_template_id(sl_client, image_template_name)
  templates = sl_client['Account'].getBlockDeviceTemplateGroups
  templates.each do | template |
    if image_template_name == template['name']
      return SoftLayer::ImageTemplate.template_with_id(template['id'], {:client => sl_client})
    end
  end
  return nil
end

sl_username = "USER"
sl_apikey = "API-KEY"

sl_client                       = SoftLayer::Client.new(username: sl_username, api_key: sl_apikey)
server_order                    = SoftLayer::VirtualServerOrder.new(sl_client)
server_order.hostname           = "test"
server_order.domain             = "mycompany.com"
server_order.datacenter         =  SoftLayer::Datacenter.datacenter_named("par02", sl_client)
server_order.cores              = 2
server_order.memory             = 4

server_order.image_template     = image_template_id(sl_client, "IMAGE NAME") 
server_order.disks              = [100, 100]

puts server_order.verify

which results in this in this error:

/usr/share/ruby/xmlrpc/client.rb:414:in `call': Invalid value provided for 'blockDevices'. Block devices may not be provided when using an image template. (XMLRPC::FaultException)
    from /fs/home/richb/.gem/ruby/1.9.1/gems/softlayer_api-3.0.0/lib/softlayer/Service.rb:281:in `call_softlayer_api_with_params'
    from /fs/home/richb/.gem/ruby/1.9.1/gems/softlayer_api-3.0.0/lib/softlayer/Service.rb:210:in `method_missing'
    from /fs/home/richb/.gem/ruby/1.9.1/gems/softlayer_api-3.0.0/lib/softlayer/VirtualServerOrder.rb:122:in `verify'
    from ./sltest:29:in `<main>'

I understand that the API is not allowing you to specify disks but this is something you can do with an image template via the SoftLayer portal so is there any way to do this via the API?


回答1:


You are seeing the same error, because in both cases you are using the createObject method to create the VSI.

If you take a look to the docuemntation you will see this:

blockDevices

Block device and disk image settings for the computing instance Optional Type - array of [[SoftLayer_Virtual_Guest_Block_Device (type)|SoftLayer_Virtual_Guest_Block_Device]]

Default - The smallest available capacity for the primary disk will be used. If an image template is specified the disk capacity will be be provided by the template

Note: "When an image template is specified the disk capacity will be provided by the template"

The portal uses another method to create the orders which allow more options, but the drawback is that is not so easy to create the orders. You can see more information about that method here, the article will show you the basics to order devices in softlayer using the placeOrder method. Basically in your case, using the placeOrder method, you just need specify the prices of the disk you want plus the image template.

I hope it helps Regards



来源:https://stackoverflow.com/questions/37128160/error-when-using-softlayer-ruby-api-to-specific-additional-disks-with-a-virtual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!