0

I use this code do list the available VLANs on my account

require 'softlayer_api'
require 'pp'

client = SoftLayer::Client.new
account_service = client[:Account]

object_filter = {'networkVlans': {'primaryRouter': {'datacenter': {'name': 'tor01'}}}}
object_mask = 'mask[id,name,primaryRouter[id,datacenter[id,name]]]'

vlans = account_service.object_mask(object_mask).getNetworkVlans(object_filter)

vlans.each { |vlan| pp plan }

I get

{"id"=>999999,
 "name"=>"VLAN1",
 "primaryRouter"=>
  {"id"=>777777, "datacenter"=>{"id"=>448994, "name"=>"tor01"}}}
{"id"=>888888,
 "name"=>"VLAN2",
 "primaryRouter"=>
  {"id"=>666666, "datacenter"=>{"id"=>448994, "name"=>"tor01"}}}

When I use e.g. 888888 in a virtual server order the server is provisioned with the default VLAN despite setting the value explicitly:

server_order = SoftLayer::VirtualServerOrder_Package.new(client)
server_order.datacenter = SoftLayer::Datacenter.datacenter_named 'tor01', client

server_order.hostname = 'hostname'
server_order.domain = 'domain.com'
# See code below to list out all vlan ids for the current account
server_order.private_vlan_id = 888888
server_order.public_vlan_id = 999999
server_order.hourly = true
server_order.configuration_options = config_options

server_order.place_order!()

What am I missing? How do I explicitly set the VLAN id when ordering a server?

1 Answers1

0

There exists an issue at the moment to specify vlans using VirtualServerOrder_Package class

I have opened an issue to track this: https://github.com/softlayer/softlayer-ruby/issues/111

However, you can use the following script to order VIrtual Server, specifying vlans (it doesn't use VirtualServerOrder_Package class to order). take a look the following script:

# Order Virtual Guest
#
# Important manual pages:
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Item_Price/
#
# License: http://sldn.softlayer.com/article/License
# Author: SoftLayer Technologies, Inc.<sldn@softlayer.com>

require 'rubygems'
require 'softlayer_api'
require 'json'

# Your SoftLayer API username.
USERNAME = 'set me'

# Your SoftLayer API key.
API_KEY = 'set me'

# The number of servers you wish to order in this configuration.
quantity = 1

# Where you'd like your new server provisioned.
# This can either be the id of the datacenter you wish your new server to be
# provisioned in or the string 'FIRST_AVAILABLE' if you have no preference
# where your server is provisioned.
# Location id 3     = Dallas
# Location id 18171 = Seattle
# Location id 37473 = Washington, D.C.
location = '138124' # Dallas 5

# The id of the SoftLayer_Product_Package you wish to order.
package_id = 46

# Build a skeleton SoftLayer_Hardware object to define hostname, domain, public and private vlan.
virtualGuests = [
  {
    'hostname' => 'test', # The hostname of the server you wish to order.
    'domain' => 'example.org', # The domain name of the server you wish to order.
    'primaryNetworkComponent' => { "networkVlan" => { "id" =>  971077}}, # public vlan id
    'primaryBackendNetworkComponent' => {'networkVlan'=> {""=> 971075}} # private vlan id
  }
]

# Build a skeleton SoftLayer_Product_Item_Price objects. These objects contain
# much more than ids, but SoftLayer's ordering system only needs the price's id
# to know what you want to order.

# Every item in SoftLayer's product catalog is assigned an id. Use these ids
# to tell the SoftLayer API which options you want in your new server. Use
# the getActivePackages() method in the SoftLayer_Account API service to get
# a list of available item and price options per available package.
prices = [
  { 'id' => 1640 }, # 1 x 2.0 GHz Core
  { 'id' => 1644 }, # 1 GB RAM
  { 'id' => 13940 }, # CentOS 6.x - LAMP Install (32 bit)
  { 'id' => 2202 }, # 25 GB (SAN)
  { 'id' => 50241 }, # 5000 GB Bandwidth
  { 'id' => 273 }, # 100 Mbps Public & Private Network Uplinks
  { 'id' => 2302 }, # Monitoring Package - Basic
  { 'id' => 55 }, # Host Ping
  { 'id' => 58 }, # Automated Notification
  { 'id' => 420}, # Unlimited SSL VPN Users & 1 PPTP VPN User per account
  { 'id' => 418 }, # Nessus Vulnerability Assessment & Reporting
  { 'id' => 21}, # 1 IP Address
  { 'id' => 57}, # Email and Ticket
  { 'id' => 905}, # Reboot / Remote Console
  {'id' => 14022} # International Services
]

# Build a skeleton SoftLayer_Container_Product_Order_Virtual_Guest object
# containing the order you wish to place.
order_template = {
  'quantity' => quantity,
  'location' => location,
  'packageId' => package_id,
  'prices' => prices,
  'hardware' => virtualGuests
}

# 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 a call to
  # placeOrder() when you're ready to order. Both calls return a receipt object
  # that you can use for your records.
  #
  # Once your order is placed it'll go through SoftLayer's provisioning process.
  # When it's done you'll have a new SoftLayer_Virtual_Guest object and CCI ready
  # to use.
  receipt = product_order_service.verifyOrder(order_template)
  puts receipt
rescue StandardError => exception
  puts "There was an error in your order: #{exception}"
end

Let me know any question, doubt or if you need more assistance to place an order,