fbpx

CL LAB

HOME > CL LAB > softlayer-api-ruby-client で NAS を追加する #softlayer

softlayer-api-ruby-client で NAS を追加する #softlayer

 ★ 2

NAS (Network Attached Storage) とは

SoftLayer のストレージにはさまざまな種類がありますが、本記事では NAS を取り扱います。
以前の記事 でも触れましたが、NAS (Network Attached Storage) とはネットワーク経由で利用可能なストレージです。現状では CIFS(Common Internet File System)プロトコルを用いてアクセスできます。

softlayer-api-ruby-client で NAS を注文する

NAS も softlayer-api-ruby-client を用いて注文が可能です。SoftLayer_Product_Order::placeOrder を用いますが、やはりマジックナンバーが必要です。先の記事のプログラムで NAS の Package ID を調べてみました。


:
(中略)
:
{"firstOrderStepId"=>1,
"id"=>216,
"isActive"=>1,
"name"=>"Network Attached Storage",
"unitSize"=>nil},
:
(中略)
:

NAS の Package ID は 216 とわかりました。

次に NAS の Price ID を確認しましょう。これも 先の記事のプログラムのように確認します。


Required Category "Network Attached Storage" -- 15:
508 -- 20 GB NAS
511 -- 250 GB NAS
1347 -- 2000 GB NAS
22437 -- 1 GB NAS
509 -- 40 GB NAS
1208 -- 1000 GB NAS
1152 -- 500 GB NAS
13708 -- 3000 GB NAS
21690 -- 6000 GB NAS
510 -- 80 GB NAS
49 -- 100 GB NAS

これで NAS を注文するために必要な ID が揃いました。

softlayer-api-ruby-client で NAS の注文内容を検証する

NAS の注文内容は SoftLayer_Container_Product_Order データタイプで構成されています。次のような形になるでしょう。


product_order = {
'complexType' => 'SoftLayer_Container_Product_Order',
'quantity' => 1,
'location' => 168642, # NOTE: 168642 is 'sjc01' location ID
'packageId' => 216, # NOTE: 216 is 'Network Attached Storage' package ID
'useHourlyPricing' => false,
'prices' => [
{ 'id' => 22437 }, # 1 GB NAS
]
}

先の記事と同様に、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'

#
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
#
product_order = {
'complexType' => 'SoftLayer_Container_Product_Order',
'quantity' => 1,
'location' => 168642, # NOTE: 168642 is 'sjc01' location ID
'packageId' => 216, # NOTE: 216 is 'Network Attached Storage' package ID
'useHourlyPricing' => false,
'prices' => [
{ 'id' => 22437 }, # 1 GB NAS
]
}

#
# 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 )
pp result
puts "The order was verified successfully"
rescue => error_reason
puts "The order could not be verified by the server: #{error_reason}"
exit
end

exit

__END__

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


{"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"=>216,
"postTaxRecurring"=>"10",
"postTaxRecurringHourly"=>"0",
"postTaxRecurringMonthly"=>"10",
"postTaxSetup"=>"0",
"preTaxRecurring"=>"10",
"preTaxRecurringHourly"=>"0",
"preTaxRecurringMonthly"=>"10",
"preTaxSetup"=>"0",
"presetId"=>nil,
"prices"=>
[{"currentPriceFlag"=>nil,
"id"=>22437,
"itemId"=>4469,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"5.6666666666667",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"10",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"nas",
"id"=>15,
"name"=>"Network Attached Storage",
"quantityLimit"=>0}],
"item"=>
{"capacity"=>"1",
"description"=>"1 GB NAS",
"id"=>4469,
"softwareDescriptionId"=>nil,
"units"=>"GIGABYTE",
"upgradeItemId"=>40,
"bundle"=>[]}}],
"primaryDiskPartitionId"=>nil,
"privateCloudOrderFlag"=>false,
"proratedInitialCharge"=>"19.67",
"proratedOrderTotal"=>"5.67",
"quantity"=>1,
"resourceGroupId"=>nil,
"resourceGroupTemplateId"=>nil,
"sendQuoteEmailFlag"=>nil,
"serverCoreCount"=>nil,
"sourceVirtualGuestId"=>nil,
"sshKeys"=>[],
"stepId"=>nil,
"storageGroups"=>[],
"totalRecurringTax"=>"0",
"totalSetupTax"=>"0",
"useHourlyPricing"=>false}
The order was verified successfully

注文内容が問題ないことがわかります。

softlayer-api-ruby-client で NAS を注文する

では、検証した注文内容を実際に注文してみましょう。
次のプログラムになります。


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

#
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
#
product_order = {
'complexType' => 'SoftLayer_Container_Product_Order',
'quantity' => 1,
'location' => 168642, # NOTE: 168642 is 'sjc01' location ID
'packageId' => 216, # NOTE: 216 is 'Network Attached Storage' package ID
'useHourlyPricing' => false,
'prices' => [
{ 'id' => 22437 }, # 1 GB NAS
]
}

#
# 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"
pp result
rescue => error_reason
puts "The order could not be placed by the server: #{error_reason}"
exit
end

exit

__END__

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


The order was verified successfully
The order was placed successfully
{"orderDate"=>"2014-06-10T17:15:12+09:00",
"orderDetails"=>
{"bigDataOrderFlag"=>false,
:
(中略)
:
"billingOrderItemId"=>nil,
"containerSplHash"=>"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"currencyShortName"=>"USD",
"extendedHardwareTesting"=>nil,
"imageTemplateId"=>nil,
"isManagedOrder"=>0,
"itemCategoryQuestionAnswers"=>[],
"location"=>"168642",
"locationObject"=>
{"id"=>168642,
"longName"=>"San Jose 1",
"name"=>"sjc01",
"activePresaleEvents"=>[]},
"packageId"=>216,
"paymentType"=>"CARD_ON_FILE",
"postTaxRecurring"=>"10",
"postTaxRecurringHourly"=>"0",
"postTaxRecurringMonthly"=>"10",
"postTaxSetup"=>"0",
"preTaxRecurring"=>"10",
"preTaxRecurringHourly"=>"0",
"preTaxRecurringMonthly"=>"10",
"preTaxSetup"=>"0",
"presetId"=>nil,
"prices"=>
[{"currentPriceFlag"=>nil,
"id"=>22437,
"itemId"=>4469,
"laborFee"=>"0",
"onSaleFlag"=>nil,
"oneTimeFee"=>"0",
"oneTimeFeeTax"=>"0",
"proratedRecurringFee"=>"5.6666666666667",
"proratedRecurringFeeTax"=>"0",
"quantity"=>nil,
"recurringFee"=>"10",
"recurringFeeTax"=>"0",
"setupFee"=>"0",
"sort"=>0,
"categories"=>
[{"categoryCode"=>"nas",
"id"=>15,
"name"=>"Network Attached Storage",
"quantityLimit"=>0}],
"item"=>
{"capacity"=>"1",
"description"=>"1 GB NAS",
"id"=>4469,
"softwareDescriptionId"=>nil,
"units"=>"GIGABYTE",
"upgradeItemId"=>40,
"bundle"=>[]}}],
"primaryDiskPartitionId"=>nil,
"privateCloudOrderFlag"=>false,
"properties"=>[],
"proratedInitialCharge"=>"19.67",
"proratedOrderTotal"=>"5.67",
"quantity"=>1,
"resourceGroupId"=>nil,
"resourceGroupTemplateId"=>nil,
"sendQuoteEmailFlag"=>nil,
"serverCoreCount"=>nil,
"sourceVirtualGuestId"=>nil,
"sshKeys"=>[],
"stepId"=>nil,
"storageGroups"=>[],
"totalRecurringTax"=>"0",
"totalSetupTax"=>"0",
"useHourlyPricing"=>false},
"orderId"=>XXXXX02,
"placedOrder"=>
{"accountId"=>XXXX78,
"createDate"=>"2014-06-10T17:15:11+09:00",
"id"=>XXXXX02,
"impersonatingUserRecordId"=>nil,
"modifyDate"=>nil,
"orderQuoteId"=>nil,
"orderTypeId"=>4,
"presaleEventId"=>nil,
"privateCloudOrderFlag"=>false,
"status"=>"PENDING_AUTO_APPROVAL",
"userRecordId"=>181942,
"account"=>
:
(中略)
:
"items"=>
[{"categoryCode"=>"nas",
"description"=>"1 GB NAS",
"id"=>XXXXXX38,
"itemId"=>4469,
"itemPriceId"=>"22437",
"laborFee"=>"0",
"laborFeeTaxRate"=>"0",
"oneTimeFee"=>"0",
"oneTimeFeeTaxRate"=>"0",
"parentId"=>nil,
"promoCodeId"=>nil,
"quantity"=>nil,
"recurringFee"=>"10",
"setupFee"=>"0",
"setupFeeDeferralMonths"=>12,
"setupFeeTaxRate"=>"0",
"bundledItems"=>[],
"category"=>
{"categoryCode"=>"nas",
"id"=>15,
"name"=>"Network Attached Storage",
"quantityLimit"=>0},
"children"=>[],
"location"=>{"id"=>168642, "longName"=>"San Jose 1", "name"=>"sjc01"},
"order"=>nil,
"storageGroups"=>[]}],
"orderTopLevelItems"=>
[{"categoryCode"=>"nas",
"description"=>"1 GB NAS",
"id"=>XXXXXX38,
"itemId"=>4469,
"itemPriceId"=>"22437",
"laborFee"=>"0",
"laborFeeTaxRate"=>"0",
"oneTimeFee"=>"0",
"oneTimeFeeTaxRate"=>"0",
"parentId"=>nil,
"promoCodeId"=>nil,
"quantity"=>nil,
"recurringFee"=>"10",
"setupFee"=>"0",
"setupFeeDeferralMonths"=>12,
"setupFeeTaxRate"=>"0",
"bundledItems"=>[],
"category"=>
{"categoryCode"=>"nas",
"id"=>15,
"name"=>"Network Attached Storage",
"quantityLimit"=>0},
"children"=>[],
"location"=>{"id"=>168642, "longName"=>"San Jose 1", "name"=>"sjc01"},
"order"=>nil,
"storageGroups"=>[]}],
:
(中略)
:

このように 1GB NAS が注文できました。

softlayer-api-ruby-client で NAS を確認する

ポータルの NAS から確認することもできますが、softlayer-api-ruby-client からも確認してみましょう。
SoftLayer_Account サービスの SoftLayer_Account::getNasNetworkStorage で NAS の一覧が確認できます。


#!/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/services/SoftLayer_Account
#
account_service = SoftLayer::Service.new( 'SoftLayer_Account',
:username => api_username,
:api_key => api_key,
)

#
# result
#
pp account_service.getNasNetworkStorage

__END__

このプログラムを実行すると、次のように先に注文した NAS の内容が取得できます。


[{"accountId"=>XXXX78,
"capacityGb"=>1,
"createDate"=>"2014-06-10T17:15:18+09:00",
"guestId"=>nil,
"hardwareId"=>nil,
"hostId"=>nil,
"id"=>XXXXX18,
"nasType"=>"NAS",
"password"=>"XXXXXXXX",
"serviceProviderId"=>1,
"upgradableFlag"=>true,
"username"=>"SLXXXX78-1",
"serviceResourceBackendIpAddress"=>"nasXXX.service.softlayer.com",
"serviceResourceName"=>"NASXXX"}]

NAS を Virtual Server から利用する

ここからは特に softlayer-api-ruby-client は利用しませんので、詳細は以前の記事に譲り、簡単に手順を見ていきます。

まず cifs-utils をインストールします。


root@test-20140610171516:~# apt-get install cifs-utils
:
(中略)
:
Setting up libavahi-common-data:amd64 (0.6.31-4ubuntu1) ...
Setting up libavahi-common3:amd64 (0.6.31-4ubuntu1) ...
Setting up libavahi-client3:amd64 (0.6.31-4ubuntu1) ...
Setting up libcups2:amd64 (1.7.2-0ubuntu1) ...
Setting up libgmp10:amd64 (2:5.1.3+dfsg-1ubuntu1) ...
Setting up libtalloc2:amd64 (2.1.0-1) ...
Setting up libtdb1:amd64 (1.2.12-1) ...
Setting up libtevent0:amd64 (0.9.19-1) ...
Setting up libldb1:amd64 (1:1.1.16-1) ...
Setting up libntdb1:amd64 (1.0-2ubuntu1) ...
Setting up libpython2.7:amd64 (2.7.6-8) ...
Setting up libwbclient0:amd64 (2:4.1.6+dfsg-1ubuntu2.14.04.1) ...
Setting up python-ldb (1:1.1.16-1) ...
Setting up python-talloc (2.1.0-1) ...
Setting up samba-common (2:4.1.6+dfsg-1ubuntu2.14.04.1) ...
Creating config file /etc/samba/smb.conf with new version
Setting up samba-libs:amd64 (2:4.1.6+dfsg-1ubuntu2.14.04.1) ...
Setting up cifs-utils (2:6.0-1ubuntu2) ...
Setting up keyutils (1.5.6-1) ...
Setting up python-crypto (2.6.1-4build1) ...
Setting up python-ntdb (1.0-2ubuntu1) ...
Setting up python-tdb (1.2.12-1) ...
Setting up python-samba (2:4.1.6+dfsg-1ubuntu2.14.04.1) ...
Setting up samba-common-bin (2:4.1.6+dfsg-1ubuntu2.14.04.1) ...
Processing triggers for libc-bin (2.19-0ubuntu6) ...
root@test-20140610171516:~#

NAS をマウントします。


root@test-20140610171516:~# mount -t cifs //nasXXX.service.softlayer.com/SLXXXX78-1 -o username=SLXXXX78-1,password=XXXXXXXX /mnt
root@test-20140610171516:~#

マウントできたことを確認します。


root@test-20140610171516:~# df -h /mnt
Filesystem Size Used Avail Use% Mounted on
//nasXXX.service.softlayer.com/SLXXXX78-1 16T 7.9T 8.2T 49% /mnt
root@test-20140610171516:~#


root@test-20140610171516:~# ls -la /mnt/
total 4
drwx------ 2 XXXX86 513 0 Apr 9 2012 .
drwxr-xr-x 22 root root 4096 Jun 10 2014 ..
root@test-20140610171516:~#

アンマウントします。


root@test-20140610171516:~# umount /mnt
root@test-20140610171516:~#

アンマウントできたことを確認します。


root@test-20140610171516:~# df -h /mnt
Filesystem Size Used Avail Use% Mounted on
/dev/xvda2 25G 886M 23G 4% /
root@test-20140610171516:~#

まとめ

NAS は高速で信頼性がありコストパフォーマンスに優れています。システム間でデータの共有を行うのに有効でしょう。是非活用してみてください。

CL LAB Mail Magazine

CL LABの情報を逃さずチェックしよう!

メールアドレスを登録すると記事が投稿されるとメールで通知します。

メールアドレス: 登録

※登録後メールに記載しているリンクをクリックして認証してください。

Related post

220323_GitLab_CI/CDハンズオンwebinar