fbpx

softlayer-api-ruby-client で Virtual Server を作成する #softlayer

この記事は1年以上前に投稿されました。情報が古い可能性がありますので、ご注意ください。

Virtual Server を作成するもう1つの方法

前回の記事では、softlayer-api-ruby-clientSoftLayer_Virtual_Guest::createObject を用いて Virtual Server を作成しました。
実は SoftLayer_Virtual_Guest::createObject は Overview に「This
method is a simplified alternative to interacting with the ordering system directly.」とあるように、システムを注文するためのシンプルな代替メソッドです。
つまり、シンプルではない本来のメソッドがあるということです。
本記事ではそのメソッド SoftLayer_Product_Order::verifyOrder および SoftLayer_Product_Order::placeOrder を用いて Virtual Server を作成する方法を紹介します。

SoftLayer_Product_Order サービス

SoftLayer_Product_Order サービスとは、さまざまな SoftLayer のサービスを新規あるいは追加注文するためのメソッドを提供します。
そのメソッドのうち、注文の検証を行う SoftLayer_Product_Order::verifyOrder と実際に注文を行う SoftLayer_Product_Order::placeOrder を見てみましょう。

まず、SoftLayer_Product_Order サービスを通して行う注文は極めて複雑です。
ただ複雑と言われても想像しにくいと思いますので、SoftLayer_Virtual_Guest::createObjectSoftLayer_Product_Order で扱う注文データを比較してみましょう。
作成する Virtual Server は、前回の記事で扱ったものと同じ次のようにします。

  • ホスト名: test-年月日時分秒
  • ドメイン名: example.jp
  • CPUコア数: 1
  • メモリ: 1024MB
  • 課金: 時
  • ディスク: ローカルディスク
  • ブロックデバイス: 0番 25GB
  • データセンター: サンノゼ
  • OS: Ubuntu 12.04 (amd64)
  • ネットワーク: 10Mbps

SoftLayer_Virtual_Guest::createObject での注文データ


template = {}


template['hostname'] = 'test-%s' % Time.now.strftime( '%F%T' ).gsub(/\D/, '' )
template['domain'] = 'example.jp'
template['startCpus'] = 1
template['maxMemory'] = 1024
template['hourlyBillingFlag'] = true
template['localDiskFlag'] = true
template['blockDevices'] = [ { 'device' => 0,
'diskImage' => { 'capacity' => 25 } } ]
template['datacenter'] = { 'name' => 'sjc01' }
template['operatingSystemReferenceCode'] = 'UBUNTU_12_64'
template['networkComponents'] = [ { 'maxSpeed' => 10 } ]

注文内容は容易に把握できると思います。

SoftLayer_Product_Order での注文データ


product_order = {}


product_order['complexType'] = 'SoftLayer_Container_Product_Order_Virtual_Guest'
product_order['quantity'] = 1
product_order['virtualGuests'] = [
{ 'hostname' => 'test-%s' % Time.now.strftime( '%F%T' ).gsub(/\D/, '' ),
'domain' => 'example.jp' }
]
product_order['location'] = 168642
product_order['packageId'] = 46
product_order['useHourlyPricing'] = true
product_order['prices'] = [
{ 'id' => 1640 },
{ 'id' => 1644 },
{ 'id' => 905 },
{ 'id' => 272 },
{ 'id' => 1800 },
{ 'id' => 21 },
{ 'id' => 13899 },
{ 'id' => 17446 },
{ 'id' => 55 },
{ 'id' => 57 },
{ 'id' => 58 },
{ 'id' => 420 },
{ 'id' => 418 },
]

いかがでしょうか。
マジックナンバーだらけで一体何のことかまったくわからないと思います。
これは別の見方をすると、各マジックナンバーを把握できさえすれば、かなり自由な注文を行えるということが言えるでしょう。

SoftLayer_Product_Order での注文 ID の確認

マジックナンバーが何を表しているのか調べるにはどうしたらいいでしょうか。
Virtual Guest Ordering には一覧を表示するプログラムが掲載されているので、それを少し変更したものを次に示します。


#!/usr/bin/ruby

require 'softlayer_api'
require 'pp'

#
# fill your SoftLayer API username and API key
#
api_username = ENV['SOFTLAYER_API_USERNAME'] || 'YOUR_SOFTLAYER_API_USERNAME'
api_key = ENV['SOFTLAYER_API_KEY'] || 'YOUR_SOFTLAYER_API_KEY'

softlayer_product_package = SoftLayer::Service.new("SoftLayer_Product_Package",
:username => api_username,
:api_key => api_key,
)

virtual_guest_package = softlayer_product_package.object_with_id( 46 )

virtual_guest_configuration = virtual_guest_package.object_mask("isRequired","itemCategory").getConfiguration()

#
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Package_Order_Configuration
#
item_prices = virtual_guest_package.object_mask("id", "item.description", "categories.id").getItemPrices()

virtual_guest_configuration.each do |configuration_entry|
if configuration_entry['isRequired'] == 1
print 'Required '
else
print 'Optional '
end

puts "Category \"#{configuration_entry['itemCategory']['name']}\" -- #{configuration_entry['itemCategory']['id']}:"
category_prices = item_prices.map do |item|
item["categories"].map do |category|
item if category["id"] == configuration_entry["itemCategory"]["id"]
end if item.include?("categories")
end.flatten.compact
category_prices.each do |category_price|
puts "\t #{category_price['id']} -- #{category_price['item']['description']}"
end
end


__END__

この中に46というマジックナンバーがまぎれていますが、これはVirtual Guestsを示す ID です。
では、このプログラムを実行してみましょう。


Optional Category "New Cloud Customer Setup" -- 95:
1798 -- Account Setup Fee
Optional Category "EVault Plugin" -- 57:
Required Category "Computing Instance" -- 80:
1642 -- 4 x 2.0 GHz Cores
1962 -- Private 1 x 2.0 GHz Core
1963 -- Private 2 x 2.0 GHz Cores
2156 -- 1 x 2.0 GHz Internal Core
1641 -- 2 x 2.0 GHz Cores
1965 -- Private 8 x 2.0 GHz Cores
2231 -- 12 x 2.0 GHz Cores
1964 -- Private 4 x 2.0 GHz Cores
1643 -- 8 x 2.0 GHz Cores
2235 -- 16 x 2.0 GHz Cores
1640 -- 1 x 2.0 GHz Core
Optional Category "Surcharges" -- 315:
14022 -- International Services
Required Category "RAM" -- 3:
1647 -- 8 GB
1645 -- 2 GB
1646 -- 4 GB
37042 -- 64 GB
1644 -- 1 GB
22422 -- 48 GB
1927 -- 16 GB
21275 -- 32 GB
2238 -- 6 GB
2243 -- 12 GB
Required Category "Remote Management" -- 46:
905 -- Reboot / Remote Console
Required Category "Uplink Port Speeds" -- 26:
274 -- 1 Gbps Public & Private Network Uplinks
14064 -- 10 Mbps Private Network Uplink
273 -- 100 Mbps Public & Private Network Uplinks
272 -- 10 Mbps Public & Private Network Uplinks
898 -- 100 Mbps Private Network Uplink
897 -- 10 Mbps Private Network Uplink
899 -- 1 Gbps Private Network Uplink
Required Category "Public Bandwidth" -- 10:
131 -- 10000 GB Bandwidth
1800 -- 0 GB Bandwidth
1123 -- 73000 GB Bandwidth
129 -- 6000 GB Bandwidth
36 -- Unlimited Bandwidth (10 Mbps Uplink)
125 -- Unlimited Bandwidth (100 Mbps Uplink)
130 -- 8000 GB Bandwidth
248 -- 5000 GB Bandwidth
2134 -- 54000 GB Bandwidth
126 -- 3000 GB Bandwidth
262 -- 5000 GB Bandwidth
22505 -- 0 GB Bandwidth
Required Category "Primary IP Addresses" -- 13:
21 -- 1 IP Address
Optional Category "Public Secondary IP Addresses" -- 14:
23 -- 8 Public IP Addresses
22 -- 4 Public IP Addresses
Optional Category "Public Static IPv6 Addresses" -- 69:
1481 -- /64 Block Static Public IPv6 Addresses
Optional Category "Primary IPv6 Addresses" -- 325:
17129 -- 1 IPv6 Address
Optional Category "Managed Resource" -- 123:
Required Category "First Disk" -- 81:
2202 -- 25 GB (SAN)
13754 -- 25 GB (SAN) COW
14016 -- 25 GB (SAN) - BETA
13899 -- 25 GB (LOCAL)
1639 -- 100 GB (SAN)
17256 -- 100 GB (LOCAL) COW
13887 -- 100 GB (LOCAL)
13760 -- 100 GB (SAN) COW
17255 -- 25 GB (LOCAL) COW
Optional Category "Storage Backend Upgrade" -- 349:
22017 -- Storage Backend Upgrade
Optional Category "Second Disk" -- 82:
2264 -- 200 GB (SAN)
13916 -- 100 GB (LOCAL)
2272 -- 250 GB (SAN)
2259 -- 50 GB (SAN)
2279 -- 1,000 GB (SAN)
14011 -- 150 GB (LOCAL)
2266 -- 350 GB (SAN)
2278 -- 750 GB (SAN)
13897 -- 200 GB (LOCAL)
2257 -- 30 GB (SAN)
2265 -- 300 GB (SAN)
2281 -- 2,000 GB (SAN)
2270 -- 500 GB (SAN)
2258 -- 40 GB (SAN)
2260 -- 75 GB (SAN)
21861 -- 25 GB (SAN)
2256 -- 20 GB (SAN)
2261 -- 125 GB (SAN)
2262 -- 150 GB (SAN)
2280 -- 1,500 GB (SAN)
21132 -- 40 GB (LOCAL)
2277 -- 100 GB (SAN)
2255 -- 10 GB (SAN)
2263 -- 175 GB (SAN)
2267 -- 400 GB (SAN)
13898 -- 300 GB (LOCAL)
13958 -- 250 GB (LOCAL)
21857 -- 25 GB (LOCAL)
Optional Category "Third Disk" -- 92:
2264 -- 200 GB (SAN)
2272 -- 250 GB (SAN)
2259 -- 50 GB (SAN)
2279 -- 1,000 GB (SAN)
2266 -- 350 GB (SAN)
2278 -- 750 GB (SAN)
2257 -- 30 GB (SAN)
2265 -- 300 GB (SAN)
2281 -- 2,000 GB (SAN)
2270 -- 500 GB (SAN)
2258 -- 40 GB (SAN)
2260 -- 75 GB (SAN)
21861 -- 25 GB (SAN)
2256 -- 20 GB (SAN)
2261 -- 125 GB (SAN)
2262 -- 150 GB (SAN)
2280 -- 1,500 GB (SAN)
2277 -- 100 GB (SAN)
2255 -- 10 GB (SAN)
2263 -- 175 GB (SAN)
2267 -- 400 GB (SAN)
Optional Category "Fourth Disk" -- 93:
2264 -- 200 GB (SAN)
2272 -- 250 GB (SAN)
2259 -- 50 GB (SAN)
2279 -- 1,000 GB (SAN)
2266 -- 350 GB (SAN)
2278 -- 750 GB (SAN)
2257 -- 30 GB (SAN)
2265 -- 300 GB (SAN)
2281 -- 2,000 GB (SAN)
2270 -- 500 GB (SAN)
2258 -- 40 GB (SAN)
2260 -- 75 GB (SAN)
21861 -- 25 GB (SAN)
2256 -- 20 GB (SAN)
2261 -- 125 GB (SAN)
2262 -- 150 GB (SAN)
2280 -- 1,500 GB (SAN)
2277 -- 100 GB (SAN)
2255 -- 10 GB (SAN)
2263 -- 175 GB (SAN)
2267 -- 400 GB (SAN)
Optional Category "Fifth Disk" -- 116:
2264 -- 200 GB (SAN)
2272 -- 250 GB (SAN)
2259 -- 50 GB (SAN)
2279 -- 1,000 GB (SAN)
2266 -- 350 GB (SAN)
2278 -- 750 GB (SAN)
2257 -- 30 GB (SAN)
2265 -- 300 GB (SAN)
2281 -- 2,000 GB (SAN)
2270 -- 500 GB (SAN)
2258 -- 40 GB (SAN)
2260 -- 75 GB (SAN)
21861 -- 25 GB (SAN)
2256 -- 20 GB (SAN)
2261 -- 125 GB (SAN)
2262 -- 150 GB (SAN)
2280 -- 1,500 GB (SAN)
2277 -- 100 GB (SAN)
2255 -- 10 GB (SAN)
2263 -- 175 GB (SAN)
2267 -- 400 GB (SAN)
Optional Category "Network Attached Storage" -- 15:
22429 -- 1 GB NAS
49 -- 100 GB NAS
48 -- 80 GB NAS
50 -- 250 GB NAS
47 -- 40 GB NAS
1152 -- 500 GB NAS
46 -- 20 GB NAS
Optional Category "EVault" -- 52:
1046 -- 40GB EVault Disk to Disk Enterprise Backup
19027 -- 175GB EVault Disk to Disk Enterprise Backup
1045 -- 20GB EVault Disk to Disk Enterprise Backup
1049 -- 500GB EVault Disk to Disk Enterprise Backup
19048 -- 1500GB EVault Disk to Disk Enterprise Backup
1050 -- 1000GB EVault Disk to Disk Enterprise Backup
1048 -- 250GB EVault Disk to Disk Enterprise Backup
1403 -- 30GB EVault Disk to Disk Enterprise Backup
2028 -- 60GB EVault Disk to Disk Enterprise Backup
19034 -- 350GB EVault Disk to Disk Enterprise Backup
1047 -- 100GB EVault Disk to Disk Enterprise Backup
19041 -- 750GB EVault Disk to Disk Enterprise Backup
1812 -- 2000GB EVault Disk to Disk Enterprise Backup
13692 -- 50GB EVault Disk to Disk Enterprise Backup
Required Category "Operating System" -- 12:
1703 -- Windows Server 2003 Enterprise SP2 with R2 (64 bit)
1686 -- CentOS 5.x - LAMP Install (32 bit)
1692 -- Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (32 bit)
1697 -- Debian GNU/Linux 5.x Lenny/Stable - Minimal Install (64 bit)
1742 -- Windows Server 2008 Standard Edition SP2 (32bit)
1860 -- Windows Server 2008 R2 Enterprise Edition (64bit)
1969 -- Windows 7 Professional 32 bit
2205 -- Fedora Release 13 (32bit) - LAMP Install
13947 -- CentOS 6.x - LAMP Install (64 bit)
13955 -- Fedora Release 15 (32bit) - Minimal Install
13957 -- Fedora Release 15 (64bit) - Minimal Install
14054 -- Debian GNU/Linux 6.x Squeeze/Stable - LAMP Install (32 bit)
20948 -- Windows Server 2012 Standard Edition (64 bit)
21074 -- Windows Server 2008 Standard SP1 with R2 (64 bit)
35433 -- Vyatta 6.6 Community Edition (64 bit)
37172 -- Ubuntu Linux 14.04 LTS Trusty Tahr - LAMP Install (32 bit)
37192 -- Ubuntu Linux 14.04 LTS Trusty Tahr - Minimal Install (32 bit)
13836 -- Windows Server 2008 Enterprise Edition SP2 (64bit)
13850 -- Windows Server 2008 Datacenter Edition SP2 (64bit)
2120 -- Windows Network Boot
2212 -- Fedora Release 13 (64bit) - Minimal Install
22174 -- Windows 8 Enterprise 64 bit
22263 -- Debian GNU/Linux 7.x Wheezy/Stable - Minimal Install (32 bit)
36192 -- Windows Server 2012 R2 Datacenter Edition (64bit)
37202 -- Ubuntu Linux 14.04 LTS Trusty Tahr - Minimal Install (64 bit)
1685 -- CentOS 5.x - Minimal Install (64 bit)
22384 -- Red Hat Enterprise Linux 5 - LAMP Install (64 bit)
1696 -- Debian GNU/Linux 5.x Lenny/Stable - Minimal Install (32 bit)
2142 -- Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install (32 bit)
2144 -- Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install (64 bit)
2159 -- Windows 7 Enterprise 32 bit
22395 -- Red Hat Enterprise Linux 6 - Minimal Install (32 bit)
22400 -- Red Hat Enterprise Linux 6 - Minimal Install (64 bit)
13938 -- CentOS 6.x - Minimal Install (32 bit)
13956 -- Fedora Release 15 (64bit) - LAMP Install
17446 -- Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)
22255 -- Debian GNU/Linux 7.x Wheezy/Stable - LAMP Install (32 bit)
22259 -- Debian GNU/Linux 7.x Wheezy/Stable - LAMP Install (64 bit)
1701 -- Windows Server 2003 Standard SP2 with R2 (64 bit)
1702 -- Windows Server 2003 Enterprise SP2 with R2 (32 bit)
1687 -- CentOS 5.x - LAMP Install (64 bit)
22375 -- Red Hat Enterprise Linux 5 - Minimal Install (64 bit)
1694 -- Ubuntu Linux 8 LTS Hardy Heron - LAMP Install (32 bit)
1699 -- Debian GNU/Linux 5.x Lenny/Stable - LAMP Install (64 bit)
1752 -- Windows Server 2008 Standard Edition SP2 (64bit)
13835 -- Windows Server 2008 Enterprise Edition SP2 (32bit)
1857 -- Windows Server 2008 R2 Standard Edition (64bit)
2139 -- Ubuntu Linux 10.04 LTS Lucid Lynx - LAMP Install (32 bit)
2210 -- Fedora Release 13 (64bit) - LAMP Install
13954 -- Fedora Release 15 (32bit) - LAMP Install
14055 -- Debian GNU/Linux 6.x Squeeze/Stable - Minimal Install (32 bit)
17440 -- Ubuntu Linux 12.04 LTS Precise Pangolin - LAMP Install (32 bit)
17442 -- Ubuntu Linux 12.04 LTS Precise Pangolin - LAMP Install (64 bit)
17444 -- Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (32 bit)
21014 -- Windows Server 2012 Datacenter Edition (64bit)
22267 -- Debian GNU/Linux 7.x Wheezy/Stable - Minimal Install (64 bit)
22381 -- Red Hat Enterprise Linux 5 - LAMP Install (32 bit)
1716 -- Windows Server 2003 Datacenter SP2 with R2 (32 bit)
2208 -- Fedora Release 13 (32bit) - Minimal Install
22394 -- Red Hat Enterprise Linux 6 - LAMP Install (64 bit)
13794 -- Red Hat Enterprise Linux 6 - LAMP Install (64 bit)
13945 -- CentOS 6.x - Minimal Install (64 bit)
17119 -- CloudLinux 6.x (64 bit)
21252 -- Vyatta 6.5 Community Edition (64 bit)
36270 -- Windows Server 2008 Enterprise SP1 with R2 (64 bit)
37182 -- Ubuntu Linux 14.04 LTS Trusty Tahr - LAMP Install (64 bit)
1689 -- Red Hat Enterprise Linux 5 - Minimal Install (64 bit)
1827 -- Windows Vista Business SP2
17117 -- CloudLinux 6.x (32 bit)
17115 -- CloudLinux 5.x (64 bit)
1684 -- CentOS 5.x - Minimal Install (32 bit)
1688 -- Red Hat Enterprise Linux 5 - Minimal Install (32 bit)
1695 -- Ubuntu Linux 8 LTS Hardy Heron - LAMP Install (64 bit)
1698 -- Debian GNU/Linux 5.x Lenny/Stable - LAMP Install (32 bit)
13799 -- Red Hat Enterprise Linux 6 - Minimal Install (64 bit)
13940 -- CentOS 6.x - LAMP Install (32 bit)
17113 -- CloudLinux 5.x (32 bit)
22178 -- Vyatta 6.5 Subscription Edition (64 bit)
580 -- Windows XP SP2
1700 -- Windows Server 2003 Standard SP2 with R2 (32 bit)
15318 -- CentOS 5.x - LAMP Install (64 bit)
22371 -- Red Hat Enterprise Linux 5 - Minimal Install (32 bit)
1690 -- Red Hat Enterprise Linux 5 - LAMP Install (32 bit)
1691 -- Red Hat Enterprise Linux 5 - LAMP Install (64 bit)
1693 -- Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)
1715 -- Windows Server 2003 Datacenter SP2 with R2 (64 bit)
1816 -- Vyatta 6.4 Community Edition (64 bit)
13865 -- Windows Server 2008 R2 Datacenter Edition (64bit)
2140 -- Ubuntu Linux 10.04 LTS Lucid Lynx - LAMP Install (64 bit)
22387 -- Red Hat Enterprise Linux 6 - LAMP Install (32 bit)
13792 -- Red Hat Enterprise Linux 6 - LAMP Install (32 bit)
13797 -- Red Hat Enterprise Linux 6 - Minimal Install (32 bit)
14056 -- Debian GNU/Linux 6.x Squeeze/Stable - LAMP Install (64 bit)
14057 -- Debian GNU/Linux 6.x Squeeze/Stable - Minimal Install (64 bit)
36222 -- Windows Server 2012 R2 Standard Edition (64 bit)
Optional Category "OS-Specific Addon" -- 34:
15390 -- RightLink
21276 -- VMware vCenter 5.1 Standard
21530 -- Idera Server Backup 5.0 Enterprise (Windows)
21526 -- Idera Server Backup 5.0 Enterprise (Linux)
17383 -- Idera Server Backup 3.0 Enterprise (Linux)
13915 -- Microsoft WebMatrix
17384 -- Idera Server Backup 3.0 Enterprise (Windows)
36542 -- VMware vCenter 5.5 Standard
Optional Category "CDP Addon" -- 329:
17396 -- Idera Disk Agent 10 Pack
17388 -- Idera Disk Agent 25 Pack
17386 -- Idera Disk Agent 5 Pack
21538 -- Idera Backup Agent 5 Pack
21542 -- Idera Backup Agent 10 Pack
21534 -- Idera Backup Agent 1 Pack
21546 -- Idera Backup Agent 25 Pack
Optional Category "Control Panel Software" -- 18:
20792 -- Parallels Plesk Panel 11 (Windows) Unlimited Domain w/ Power Pack
13704 -- Parallels Plesk Panel 10 (Windows) Unlimited Domain w/ Power Pack
20786 -- Parallels Plesk Panel 11 (Windows) 100 Domain w/ Power Pack
2339 -- Parallels Plesk Panel 10 (Linux) Unlimited Domain w/ Power Pack
20787 -- Parallels Plesk Panel 11 (Linux) Unlimited Domain w/ Power Pack
2340 -- Parallels Plesk Panel 10 (Linux) 100 Domain w/ Power Pack
20778 -- Parallels Plesk Panel 11 (Linux) 100 Domain w/ Power Pack
36756 -- cPanel/WHM with Softaculous and RVskin
1724 -- cPanel/WHM with Fantastico and RVskin
Optional Category "Database Software" -- 17:
94 -- Microsoft SQL Server 2005 Enterprise
17283 -- Microsoft SQL Server 2012 Web Edition
17278 -- Microsoft SQL Server 2012 Web Edition
17273 -- Microsoft SQL Server 2012 Web Edition
17296 -- Microsoft SQL Server 2012 Standard Edition
17307 -- Microsoft SQL Server 2012 Enterprise Edition
1334 -- Microsoft SQL Server 2008 Standard
2173 -- Microsoft SQL Server 2008 Web R2
17285 -- Microsoft SQL Server 2012 Web Edition
17281 -- Microsoft SQL Server 2012 Web Edition
17280 -- Microsoft SQL Server 2012 Web Edition
17275 -- Microsoft SQL Server 2012 Web Edition
17274 -- Microsoft SQL Server 2012 Web Edition
17301 -- Microsoft SQL Server 2012 Standard Edition
17297 -- Microsoft SQL Server 2012 Standard Edition
17316 -- Microsoft SQL Server 2012 Enterprise Edition
17315 -- Microsoft SQL Server 2012 Enterprise Edition
17311 -- Microsoft SQL Server 2012 Enterprise Edition
17310 -- Microsoft SQL Server 2012 Enterprise Edition
17309 -- Microsoft SQL Server 2012 Enterprise Edition
21501 -- Riak 1.x
1330 -- Microsoft SQL Server 2008 Express
1340 -- Microsoft SQL Server 2008 Web
2179 -- Microsoft SQL Server 2008 Express R2
17288 -- Microsoft SQL Server 2012 Web Edition
17269 -- Microsoft SQL Server 2012 Web Edition
17295 -- Microsoft SQL Server 2012 Standard Edition
17294 -- Microsoft SQL Server 2012 Standard Edition
17293 -- Microsoft SQL Server 2012 Standard Edition
17321 -- Microsoft SQL Server 2012 Enterprise Edition
17317 -- Microsoft SQL Server 2012 Enterprise Edition
17314 -- Microsoft SQL Server 2012 Enterprise Edition
21610 -- Riak Enterprise 1.3.0
28 -- MySQL for Linux
1331 -- Microsoft SQL Server 2008 Enterprise
17286 -- Microsoft SQL Server 2012 Web Edition
17277 -- Microsoft SQL Server 2012 Web Edition
17306 -- Microsoft SQL Server 2012 Standard Edition
17304 -- Microsoft SQL Server 2012 Standard Edition
17290 -- Microsoft SQL Server 2012 Standard Edition
17324 -- Microsoft SQL Server 2012 Enterprise Edition
17381 -- Microsoft SQL Server 2012 Express Edition
29 -- MySQL 5.0 for Windows
30 -- Microsoft SQL Server 2005 Express
90 -- Microsoft SQL Server 2005 Standard
2180 -- Microsoft SQL Server 2008 Standard R2
2176 -- Microsoft SQL Server 2008 Enterprise R2
17276 -- Microsoft SQL Server 2012 Web Edition
17300 -- Microsoft SQL Server 2012 Standard Edition
17322 -- Microsoft SQL Server 2012 Enterprise Edition
17279 -- Microsoft SQL Server 2012 Web Edition
17272 -- Microsoft SQL Server 2012 Web Edition
17302 -- Microsoft SQL Server 2012 Standard Edition
17298 -- Microsoft SQL Server 2012 Standard Edition
17319 -- Microsoft SQL Server 2012 Enterprise Edition
17308 -- Microsoft SQL Server 2012 Enterprise Edition
20893 -- MongoDB
92 -- Microsoft SQL Server 2005 Workgroup
2183 -- Microsoft SQL Server 2008 Workgroup R2
17287 -- Microsoft SQL Server 2012 Web Edition
17305 -- Microsoft SQL Server 2012 Standard Edition
17299 -- Microsoft SQL Server 2012 Standard Edition
17292 -- Microsoft SQL Server 2012 Standard Edition
17291 -- Microsoft SQL Server 2012 Standard Edition
17289 -- Microsoft SQL Server 2012 Standard Edition
36274 -- MySQL 5.0.51 for Windows
1337 -- Microsoft SQL Server 2008 Workgroup
17284 -- Microsoft SQL Server 2012 Web Edition
17282 -- Microsoft SQL Server 2012 Web Edition
17303 -- Microsoft SQL Server 2012 Standard Edition
17323 -- Microsoft SQL Server 2012 Enterprise Edition
17320 -- Microsoft SQL Server 2012 Enterprise Edition
17318 -- Microsoft SQL Server 2012 Enterprise Edition
17313 -- Microsoft SQL Server 2012 Enterprise Edition
17312 -- Microsoft SQL Server 2012 Enterprise Edition
36490 -- MySQL 5.7 for Windows
Optional Category "Web Analytics Software" -- 50:
Optional Category "Anti-Virus & Spyware Protection" -- 28:
594 -- McAfee VirusScan Anti-Virus - Windows
414 -- McAfee Total Protection - Windows
Optional Category "Insurance" -- 23:
104 -- Business Continuance Insurance
Required Category "Monitoring" -- 20:
55 -- Host Ping
56 -- Host Ping and TCP Service Monitoring
Required Category "Notification" -- 21:
57 -- Email and Ticket
Optional Category "Advanced Monitoring" -- 122:
2304 -- Monitoring Package - Premium Application
2302 -- Monitoring Package - Basic
2303 -- Monitoring Package - Advanced
Required Category "Response" -- 22:
59 -- Automated Reboot from Monitoring
60 -- NOC Monitoring
58 -- Automated Notification
Optional Category "Intrusion Detection & Protection" -- 29:
413 -- McAfee Host Intrusion Protection w/Reporting
Optional Category "Hardware & Software Firewalls" -- 30:
36236 -- 20Mbps Hardware Firewall
36245 -- 200Mbps Hardware Firewall
894 -- Microsoft Windows Firewall
409 -- 100Mbps Hardware Firewall
408 -- 1000Mbps Hardware Firewall
410 -- 10Mbps Hardware Firewall
411 -- APF Software Firewall for Linux
Required Category "VPN Management - Private Network" -- 31:
420 -- Unlimited SSL VPN Users & 1 PPTP VPN User per account
Required Category "Vulnerability Assessments & Management" -- 32:
418 -- Nessus Vulnerability Assessment & Reporting

これが Virtual Guests を作成する際に指定できる ID の一覧です。必須項目(Required)か任意項目(Optional)かも区別できるようになっています。

なお、データセンターの ID はこのプログラムでは取得できていません。サンノゼの ID は 168642 です。

この結果をもとにすると先程の注文データは次のように表すことができます。


# 80 -- Computing Instance
{ 'id' => 1640 }, # 1640 -- 1 x 2.0 GHz Core
# 3 -- RAM
{ 'id' => 1644 }, # 1644 -- 1 GB
# 46 -- Remote Management
{ 'id' => 905 }, # 905 -- Reboot / Remote Console
# 26 -- Uplink Port Speeds
{ 'id' => 272 }, # 272 -- 10 Mbps Public & Private Network Uplinks
# 10 -- Public Bandwidth
{ 'id' => 1800 }, # 1800 -- 0 GB Bandwidth
# 13 -- Primary IP Addresses
{ 'id' => 21 }, # 21 -- 1 IP Address
# 81 -- First Disk
{ 'id' => 13899 }, # 13899 -- 25 GB (LOCAL)
# 12 -- Operating System
{ 'id' => 17446 }, # 17446 -- Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)
# 20 -- Monitoring
{ 'id' => 55 }, # 55 -- Host Ping
# 21 -- Notification
{ 'id' => 57 }, # 57 -- Email and Ticket
# 22 -- Response
{ 'id' => 58 }, # 58 -- Automated Notification
# 31 -- VPN Management - Private Network
{ 'id' => 420 }, # 420 -- Unlimited SSL VPN Users & 1 PPTP VPN User per account
# 32 -- Vulnerability Assessments & Management
{ 'id' => 418 }, # 418 -- Nessus Vulnerability Assessment & Reporting

SoftLayer_Product_Order::verifyOrder メソッド

では、この注文内容を SoftLayer_Product_Order::verifyOrder を用いて検証してみましょう。


#!/usr/bin/ruby

require 'softlayer_api'
require 'pp'

#
# fill your SoftLayer API username and API key
#
api_username = ENV['SOFTLAYER_API_USERNAME'] || 'YOUR_SOFTLAYER_API_USERNAME'
api_key = ENV['SOFTLAYER_API_KEY'] || 'YOUR_SOFTLAYER_API_KEY'

#
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest
#
product_order = {
'complexType' => 'SoftLayer_Container_Product_Order_Virtual_Guest',
'quantity' => 1,
#
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
#
'virtualGuests' => [
{
'hostname' => 'test-%s' % Time.now.strftime( '%F%T' ).gsub(/\D/, '' ),
'domain' => 'example.jp'
}
],
'location' => 168642, # NOTE: 168642 is 'sjc01' location ID
'packageId' => 46, # NOTE: 46 is 'Virtual Guests' package ID
'useHourlyPricing' => true,
'prices' => [
#
# Required Categories
#
# 80 -- Computing Instance
{ 'id' => 1640 }, # 1640 -- 1 x 2.0 GHz Core
# 3 -- RAM
{ 'id' => 1644 }, # 1644 -- 1 GB
# 46 -- Remote Management
{ 'id' => 905 }, # 905 -- Reboot / Remote Console
# 26 -- Uplink Port Speeds
{ 'id' => 272 }, # 272 -- 10 Mbps Public & Private Network Uplinks
# 10 -- Public Bandwidth
{ 'id' => 1800 }, # 1800 -- 0 GB Bandwidth
# 13 -- Primary IP Addresses
{ 'id' => 21 }, # 21 -- 1 IP Address
# 81 -- First Disk
{ 'id' => 13899 }, # 13899 -- 25 GB (LOCAL)
# 12 -- Operating System
{ 'id' => 17446 }, # 17446 -- Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)
# 20 -- Monitoring
{ 'id' => 55 }, # 55 -- Host Ping
# 21 -- Notification
{ 'id' => 57 }, # 57 -- Email and Ticket
# 22 -- Response
{ 'id' => 58 }, # 58 -- Automated Notification
# 31 -- VPN Management - Private Network
{ 'id' => 420 }, # 420 -- Unlimited SSL VPN Users & 1 PPTP VPN User per account
# 32 -- Vulnerability Assessments & Management
{ 'id' => 418 }, # 418 -- Nessus Vulnerability Assessment & Reporting
#
# Optional
#
# #
# { 'id' => }, #
]
}

#
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order
#
product_order_service = SoftLayer::Service.new( 'SoftLayer_Product_Order',
:username => api_username,
:api_key => api_key,
)

#
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
#
begin
result = product_order_service.verifyOrder( product_order )
puts "The order was verified successfully"
pp result
rescue => error_reason
puts "The order could not be verified by the server: #{error_reason}"
exit
end


__END__

これを実行すると次のような結果が得られます。


The order was verified successfully
{"bigDataOrderFlag"=>false,
"billingOrderItemId"=>nil,
"containerSplHash"=>"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"currencyShortName"=>"USD",
"extendedHardwareTesting"=>nil,
"imageTemplateId"=>nil,
"isManagedOrder"=>0,
"location"=>"168642",
"locationObject"=>
{"id"=>168642,
"longName"=>"San Jose 1",
"name"=>"sjc01",
"activePresaleEvents"=>[]},
"packageId"=>46,
"postTaxRecurring"=>"0.042",
"postTaxRecurringHourly"=>"0.042",
"postTaxRecurringMonthly"=>"0",
"postTaxSetup"=>"0",
"preTaxRecurring"=>"0.042",
"preTaxRecurringHourly"=>"0.042",
"preTaxRecurringMonthly"=>"0",
"preTaxSetup"=>"0",
"presetId"=>nil,
"prices"=>
[{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>".022",
"id"=>1640,
"itemId"=>857,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"guest_core",
"id"=>80,
"name"=>"Computing Instance",
"quantityLimit"=>20}],
"item"=>
{"capacity"=>"1",
"description"=>"1 x 2.0 GHz Core",
"id"=>857,
"softwareDescriptionId"=>nil,
"units"=>"CORE",
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>".02",
"id"=>1644,
"itemId"=>861,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"ram", "id"=>3, "name"=>"RAM", "quantityLimit"=>0}],
"item"=>
{"capacity"=>"1",
"description"=>"1 GB",
"id"=>861,
"softwareDescriptionId"=>nil,
"units"=>"GB",
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>905,
"itemId"=>503,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"remote_management",
"id"=>46,
"name"=>"Remote Management",
"quantityLimit"=>0}],
"item"=>
{"description"=>"Reboot / Remote Console",
"id"=>503,
"softwareDescriptionId"=>nil,
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>272,
"itemId"=>186,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>4,
"categories"=>
[{"categoryCode"=>"port_speed",
"id"=>26,
"name"=>"Uplink Port Speeds",
"quantityLimit"=>0}],
"item"=>
{"capacity"=>"10",
"description"=>"10 Mbps Public & Private Network Uplinks",
"id"=>186,
"softwareDescriptionId"=>nil,
"units"=>"Mbps",
"upgradeItemId"=>187,
"bundle"=>
[{"bundleItemId"=>186,
"id"=>2662,
"itemPriceId"=>31,
"category"=>
{"categoryCode"=>"public_port",
"id"=>8,
"name"=>"Public Network Port",
"quantityLimit"=>0},
"itemPrice"=>
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>31,
"itemId"=>25,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"setupFee"=>"0",
"sort"=>0,
"item"=>
{"capacity"=>"10",
"description"=>"10 Mbps Public Uplink",
"id"=>25,
"softwareDescriptionId"=>nil,
"units"=>"Mbps",
"upgradeItemId"=>nil}}},
{"bundleItemId"=>186,
"id"=>2661,
"itemPriceId"=>52,
"category"=>
{"categoryCode"=>"service_port",
"id"=>9,
"name"=>"Private Network Port",
"quantityLimit"=>0},
"itemPrice"=>
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>52,
"itemId"=>46,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"setupFee"=>"0",
"sort"=>0,
"item"=>
{"capacity"=>"10",
"description"=>"10 Mbps Private Uplink",
"id"=>46,
"softwareDescriptionId"=>nil,
"units"=>"Mbps",
"upgradeItemId"=>nil}}}]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>1800,
"itemId"=>439,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>99,
"categories"=>
[{"categoryCode"=>"bandwidth",
"id"=>10,
"name"=>"Public Bandwidth",
"quantityLimit"=>0}],
"item"=>
{"capacity"=>"0",
"description"=>"0 GB Bandwidth",
"id"=>439,
"softwareDescriptionId"=>nil,
"units"=>"GB",
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>21,
"itemId"=>15,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"pri_ip_addresses",
"id"=>13,
"name"=>"Primary IP Addresses",
"quantityLimit"=>0}],
"item"=>
{"capacity"=>"1",
"description"=>"1 IP Address",
"id"=>15,
"softwareDescriptionId"=>nil,
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>13899,
"itemId"=>3891,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>20,
"categories"=>
[{"categoryCode"=>"guest_disk0",
"id"=>81,
"name"=>"First Disk",
"quantityLimit"=>0}],
"item"=>
{"capacity"=>"25",
"description"=>"25 GB (LOCAL)",
"id"=>3891,
"softwareDescriptionId"=>nil,
"units"=>"GB",
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>17446,
"itemId"=>4174,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>4,
"categories"=>
[{"categoryCode"=>"os",
"id"=>12,
"name"=>"Operating System",
"quantityLimit"=>0}],
"item"=>
{"capacity"=>"0",
"description"=>
"Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)",
"id"=>4174,
"softwareDescriptionId"=>1025,
"units"=>"N/A",
"upgradeItemId"=>nil,
"bundle"=>[],
"softwareDescription"=>
{"controlPanel"=>0,
"id"=>1025,
"longDescription"=>"Ubuntu / Ubuntu / 12.04-64 Minimal for VSI",
"manufacturer"=>"Ubuntu",
"name"=>"Ubuntu",
"operatingSystem"=>1,
"referenceCode"=>"UBUNTU_12_64",
"upgradeSoftwareDescriptionId"=>nil,
"upgradeSwDescId"=>nil,
"version"=>"12.04-64 Minimal for VSI",
"virtualLicense"=>0,
"virtualizationPlatform"=>0,
"attributes"=>[],
"requiredUser"=>"root"}}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>55,
"itemId"=>49,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"monitoring",
"id"=>20,
"name"=>"Monitoring",
"quantityLimit"=>0}],
"item"=>
{"description"=>"Host Ping",
"id"=>49,
"softwareDescriptionId"=>nil,
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>57,
"itemId"=>51,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"notification",
"id"=>21,
"name"=>"Notification",
"quantityLimit"=>0}],
"item"=>
{"description"=>"Email and Ticket",
"id"=>51,
"softwareDescriptionId"=>nil,
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>58,
"itemId"=>52,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"response",
"id"=>22,
"name"=>"Response",
"quantityLimit"=>0}],
"item"=>
{"description"=>"Automated Notification",
"id"=>52,
"softwareDescriptionId"=>nil,
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>420,
"itemId"=>309,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"vpn_management",
"id"=>31,
"name"=>"VPN Management - Private Network",
"quantityLimit"=>0}],
"item"=>
{"description"=>"Unlimited SSL VPN Users & 1 PPTP VPN User per account",
"id"=>309,
"softwareDescriptionId"=>nil,
"upgradeItemId"=>nil,
"bundle"=>[]}},
{"currentPriceFlag"=>nil,
"hourlyRecurringFee"=>"0",
"id"=>418,
"itemId"=>307,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"0",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"0",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"vulnerability_scanner",
"id"=>32,
"name"=>"Vulnerability Assessments & Management",
"quantityLimit"=>0}],
"item"=>
{"description"=>"Nessus Vulnerability Assessment & Reporting",
"id"=>307,
"softwareDescriptionId"=>nil,
"upgradeItemId"=>nil,
"bundle"=>[]}}],
"primaryDiskPartitionId"=>1,
"privateCloudOrderFlag"=>false,
"proratedInitialCharge"=>"0",
"proratedOrderTotal"=>"0",
"quantity"=>1,
"resourceGroupId"=>nil,
"resourceGroupTemplateId"=>nil,
"sendQuoteEmailFlag"=>nil,
"serverCoreCount"=>4,
"sourceVirtualGuestId"=>nil,
"stepId"=>nil,
"storageGroups"=>[],
"totalRecurringTax"=>"0",
"totalSetupTax"=>"0",
"useHourlyPricing"=>true,
"virtualGuests"=>
[{"accountId"=>nil,
"createDate"=>nil,
"dedicatedAccountHostOnlyFlag"=>nil,
"domain"=>"example.jp",
"hostname"=>"test-20140514171736",
"id"=>nil,
"lastPowerStateId"=>nil,
"lastVerifiedDate"=>nil,
"maxCpu"=>nil,
"maxMemory"=>nil,
"metricPollDate"=>nil,
"modifyDate"=>nil,
"startCpus"=>nil,
"statusId"=>nil,
"billingItem"=>
{"allowCancellationFlag"=>nil,
"cancellationDate"=>nil,
"createDate"=>nil,
"cycleStartDate"=>nil,
"id"=>nil,
"lastBillDate"=>nil,
"modifyDate"=>nil,
"nextBillDate"=>nil,
"orderItemId"=>nil,
"parentId"=>nil,
"recurringMonths"=>nil,
"serviceProviderId"=>nil,
"resourceTableId"=>nil},
"primaryBackendNetworkComponent"=>
{"createDate"=>nil,
"guestId"=>nil,
"id"=>nil,
"maxSpeed"=>nil,
"modifyDate"=>nil,
"networkId"=>nil,
"port"=>nil,
"speed"=>nil,
"networkVlan"=>
{"accountId"=>nil,
"id"=>nil,
"modifyDate"=>nil,
"networkVrfId"=>nil,
"primarySubnetId"=>nil,
"vlanNumber"=>nil}},
"primaryNetworkComponent"=>
{"createDate"=>nil,
"guestId"=>nil,
"id"=>nil,
"maxSpeed"=>nil,
"modifyDate"=>nil,
"networkId"=>nil,
"port"=>nil,
"speed"=>nil,
"networkVlan"=>
{"accountId"=>nil,
"id"=>nil,
"modifyDate"=>nil,
"networkVrfId"=>nil,
"primarySubnetId"=>nil,
"vlanNumber"=>nil}}}]}

このように、注文内容の項目に過不足や矛盾といった問題がないことがわかります。

では、受け付けられない注文の場合の結果も見てみましょう。
例えば、Optional Category である 410 -- 10Mbps Hardware Firewall を注文に含めてみましょう。ハードウェアファイアウォールを適用する Virtual Guests は課金が月額である必要があるので、時間課金としているこの注文が受け付けられません。


#
# Optional
#
{ 'id' => 410 },

先程のプログラムをこのように変更して実行してみます。


The order could not be verified by the server: 10Mbps Hardware Firewall (410) is not available at an hourly rate.

このように注文を拒否されました。

SoftLayer_Product_Order::placeOrder メソッド

SoftLayer_Product_Order::placeOrder を用いて実際に注文してみましょう。


#!/usr/bin/ruby

require 'softlayer_api'
require 'pp'

#
# fill your SoftLayer API username and API key
#
api_username = ENV['SOFTLAYER_API_USERNAME'] || 'YOUR_SOFTLAYER_API_USERNAME'
api_key = ENV['SOFTLAYER_API_KEY'] || 'YOUR_SOFTLAYER_API_KEY'

#
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest
#
product_order = {
'complexType' => 'SoftLayer_Container_Product_Order_Virtual_Guest',
'quantity' => 1,
#
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
#
'virtualGuests' => [
{
'hostname' => 'test-%s' % Time.now.strftime( '%F%T' ).gsub(/\D/, '' ),
'domain' => 'example.jp'
}
],
'location' => 168642, # NOTE: 168642 is 'sjc01' location ID
'packageId' => 46, # NOTE: 46 is 'Virtual Guests' package ID
'useHourlyPricing' => true,
'prices' => [
#
# Required Categories
#
{ 'id' => 1640 }, # 1640 -- 1 x 2.0 GHz Core
{ 'id' => 1644 }, # 1644 -- 1 GB
{ 'id' => 905 }, # 905 -- Reboot / Remote Console
{ 'id' => 272 }, # 272 -- 10 Mbps Public & Private Network Uplinks
{ 'id' => 1800 }, # 1800 -- 0 GB Bandwidth
{ 'id' => 21 }, # 21 -- 1 IP Address
{ 'id' => 13899 }, # 13899 -- 25 GB (LOCAL)
{ 'id' => 17446 }, # 17446 -- Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)
{ 'id' => 55 }, # 55 -- Host Ping
{ 'id' => 57 }, # 57 -- Email and Ticket
{ 'id' => 58 }, # 58 -- Automated Notification
{ 'id' => 420 }, # 420 -- Unlimited SSL VPN Users & 1 PPTP VPN User per account
{ 'id' => 418 }, # 418 -- Nessus Vulnerability Assessment & Reporting
]
}

#
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order
#
product_order_service = SoftLayer::Service.new( 'SoftLayer_Product_Order',
:username => api_username,
:api_key => api_key,
)

#
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
#
begin
result = product_order_service.verifyOrder( product_order )
puts "The order was verified successfully"
rescue => error_reason
puts "The order could not be verified by the server: #{error_reason}"
exit
end

#
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
#
begin
result = product_order_service.placeOrder( product_order )
puts "The order was placed successfully"
rescue => error_reason
puts "The order could not be placed by the server: #{error_reason}"
exit
end


__END__

これを実行すると次のような結果が得られます。


The order was verified successfully
The order was placed successfully

次のようにslコマンドで Virtual Server が作成できたことが確認できました。


% sl vs list
:.........:............:................................:.......:........:.................:..............:....................:
: id : datacenter : host : cores : memory : primary_ip : backend_ip : active_transaction :
:.........:............:................................:.......:........:.................:..............:....................:
: XXXXXXX : sjc01 : test-20140514183858.example.jp : 1 : 1G : 108.168.XXX.XXX : 10.88.XX.XXX : Service setup :
:.........:............:................................:.......:........:.................:..............:....................:


% sl vs detail XXXXXXX
:....................:................................:
: Name : Value :
:....................:................................:
: id : XXXXXXX :
: hostname : test-20140514183858.example.jp :
: status : Active :
: active_transaction : Service setup :
: state : Running :
: datacenter : sjc01 :
: os : Ubuntu :
: os_version : 12.04-64 Minimal for VSI :
: cores : 1 :
: memory : 1G :
: public_ip : 108.168.XXX.XXX :
: private_ip : 10.88.XX.XXX :
: private_only : False :
: private_cpu : False :
: created : 2014-05-14T18:39:03+09:00 :
: modified : 2014-05-14T18:40:57+09:00 :
: vlans : :.........:........:........: :
: : : type : number : id : :
: : :.........:........:........: :
: : : PUBLIC : 16XX : 425XXX : :
: : : PRIVATE : 16XX : 425XXX : :
: : :.........:........:........: :
:....................:................................:

まとめ

本記事では SoftLayer_Product_Order::verifyOrder および SoftLayer_Product_Order::placeOrder を用いて、SoftLayer_Virtual_Guest::createObject で作成できるものと同じ Virtual Server を作成しました。
次回は SoftLayer_Virtual_Guest::createObject では行えないオプションつきの Virtual Server を作成してみます。

Author

Chef・Docker・Mirantis製品などの技術要素に加えて、会議の進め方・文章の書き方などの業務改善にも取り組んでいます。「Chef活用ガイド」共著のほか、Debian Official Developerもやっています。

Daisuke Higuchiの記事一覧

新規CTA