softlayer / softlayer-ruby

http://softlayer.github.io/softlayer-ruby/
MIT License
54 stars 35 forks source link

VirtualServerOrder_Package class doesn't define VLANs #111

Open rubercuellar opened 8 years ago

rubercuellar commented 8 years ago

There is an issue at the moment to specify vlans:

 product_order['primaryNetworkComponent']        = { "networkVlan" => { "id" => @public_vlan_id.to_i } } if @public_vlan_id
 product_order['primaryBackendNetworkComponent'] = { "networkVlan" => {"id" => @private_vlan_id.to_i } } if @private_vlan_id

The vlans should be specified inside of "hardware" object. This could be a possible solution

  def virtual_server_order
      product_order = {
        'packageId'        => @package.id,
        'useHourlyPricing' => !!@hourly,
        'hardware'    => [{
                                 'domain'   => @domain,
                                 'hostname' => @hostname,
                                 'primaryNetworkComponent' => { "networkVlan" => { "id" => @public_vlan_id.to_i } } if @public_vlan_id,
                                 'primaryBackendNetworkComponent' => { "networkVlan" => {"id" => @private_vlan_id.to_i } } if @private_vlan_id
                               }]
      }

I replaced 'hardware' instead of 'virtualGuests', because it is not possible to set vlans using 'virtualGuests' object. (It seems an issue)

renier commented 7 years ago

Why is this a softlayer-ruby issue?

It makes sense that the network components are specified per device, after all.

ArtsiomMusin commented 7 years ago

I faced the issue here when a private VLAN is not assigned correctly. Whenever I try to use any other VLAN, the server is created with a default VLAN which is auto-assigned when, for example, you don't specify a VLAN at all.

Playing around with changes suggested by @rubercuellar didn't help. I found a helpful solution in #92 Basically what I did for my workaround was to replace { "networkVlan" => {"id" => 123 } } to { "networkVlanId" => 123 }

At the moment my final workaround, which works correctly, looks like that: add_vlans = lambda { |order_template| order_template['primaryBackendNetworkComponent'] = { "networkVlanId" => private_vlan_id } order_template } server_order.verify(&add_vlans) server_order.place_order!(&add_vlans)

@renier, still not a softlayer-ruby issue?

renier commented 7 years ago

@ArtsiomMusin could should show the whole code you are trying?, from when you get an instance of server order. and use '```' do delimit the code block

ArtsiomMusin commented 7 years ago

sorry I cannot show the whole code... confidential stuff you know. But here is the main calls we use to build the order:

server_order = ::SoftLayer::VirtualServerOrder_Package.new(@client)

vs_package = ::SoftLayer::ProductPackage.virtual_server_package(@client)
required_categories = vs_package.configuration.select(&:required?)
config_options = {}
required_categories.each { |required_category| config_options[required_category.categoryCode] = required_category.default_option }

server_order.datacenter = ::SoftLayer::Datacenter.datacenter_named dc_name, @client
server_order.image_template = ::SoftLayer::ImageTemplate.template_with_id(template_id, client: @client)

server_order.hostname = hostname
server_order.domain = domain
server_order.configuration_options = config_options

add_vlans = lambda do |order_template|
  order_template['primaryBackendNetworkComponent'] =
    { 'networkVlanId' => input[:private_vlan_id].to_i } unless input[:private_vlan_id].blank?
  order_template
end

server_order.verify(&add_vlans)
server_order.place_order!(&add_vlans)