RichB
RichB

Reputation: 43

Error when using SoftLayer Ruby API to specify addtional disks with a virtual server

Building on the answer to this question:

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

I have converted my script to use placeOrder and have gotten it to work with a single disk but I am still stuck on how I go about specifying a 2nd disk. This code is my attempt at specifying two disks:

#!/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

but it produces the error:

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

How do I go about specifying the second disk in my order for a virtual server?

Upvotes: 0

Views: 61

Answers (2)

Ruber Cuellar Valenzuela
Ruber Cuellar Valenzuela

Reputation: 2757

The "23065" price has the following categories:

  1. First Disk

and "29237":

  1. Second Disk
  2. Third Disk
  3. Fourth Disk
  4. Fifth Disk

It means that the "23065" item price can order only as first disk and "29237" as: Second, Third, Fourth or Fifth disk.

The following script will help to provide information about item prices and their categories:

# 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. <[email protected]>

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

References:

Upvotes: 1

RichB
RichB

Reputation: 43

Right after I posted my question, I realized there are two different 100GB SAN price items. One has a key name of GUEST_DISK_100_GB_SAN which corresponds to the 23065 item used in the sample code. These is also an item with key name of GUEST_DISK_100_GB_SAN_3. When I used that id, things works as excepted. So when I changed the order from:

 {'id' => 23065 }, # 100 GB (SAN)
 {'id' => 23065 }, # 100 GB (SAN)

to

 {'id' => 23065 }, # 100 GB (SAN)
 {'id' => 29237 }, # 100 GB (SAN)
 {'id' => 29237 }, # 100 GB (SAN)

I ended up with a virtual server made from an image template with two additional 100GB disks.

Upvotes: 0

Related Questions