LoginSignup
2
2

More than 5 years have passed since last update.

SoftLayer の仮想サーバーで CLI から自分自身のイメージ・テンプレートを取得する

Last updated at Posted at 2015-08-28

o. はじめに

ある日、定期的に仮想サーバーのイメージ・テンプレート(スタンダード・イメージ)を自動取得をしたいと思い立ちました。しかし、対象となるサーバーが一台のみ、かつ、監視拠点もなく他システムからの操作も期待できません。
一方、イメージ・テンプレートの取得を要求すると、取得の際にリブートがかかります(無いとは思うものの、要求の完了前にリブートされてエラーになったりしない?)。きちんと取れることを確認し、そのテスト結果をより簡単にまとめるために CLI から操作した結果を記録したのがこの記事です。

1. 仮想サーバーのオーダー

既ににセットアップ済みの CLI 環境から、イメージ・テンプレートを取得要求の発行元および、イメージ・テンプレートの取得先として CENTOS6 64bit 1 CPU core、1GB RAM のサーバーをオーダーします。

# slcli vs create -D softlayer.com -H POC -c 1 -m 1024 -o CENTOS_6_64 --billing hourly -d tok02 --public -k id_rsa.pub --disk 25 -n 100
This action will incur charges on your account. Continue? [y/N]: y
:.........:......................................:
:    name : value                                :
:.........:......................................:
:      id : 11910733                             :
: created : 2015-08-28T09:51:48+09:00            :
:    guid : cfe92a69-ae12-4103-9673-22c4915fdfae :
:.........:......................................:

しばらくすると仮想サーバーのデプロイが完了します。

# slcli vs ready 11910733
READY

2. SoftLayer CLI のセットアップ

以前にセットアップした記憶を呼び起こしつつ、仮想サーバーに接続し、以下のコマンドを実行します。

# yum install -y python-setuptools
# easy_install pip
# pip install softlayer

ところが、上記コマンドの完了後、認証情報を追加しようとするとエラーになります。

# slcli config setup
Traceback (most recent call last):
  File "/usr/bin/slcli", line 7, in <module>
    from SoftLayer.CLI.core import main
  File "/usr/lib64/python2.6/site-packages/SoftLayer/__init__.py", line 20, in <module>
    from SoftLayer.API import *  # NOQA
  File "/usr/lib64/python2.6/site-packages/SoftLayer/API.py", line 13, in <module>
    from SoftLayer import transports
  File "/usr/lib64/python2.6/site-packages/SoftLayer/transports.py", line 12, in <module>
    import importlib
ImportError: No module named importlib

検索結果と、/usr/lib/python2.6/site-packages/ に importlib-xxx が無いことから、importlib をインストールすると問題なく実行できるようになりました。

# pip install importlib
# slcli config setup
Username []: xxxx
API Key or Password []:
Endpoint (public|private|custom) [public]:
Timeout [0]:
:..............:..................................................................:
:         Name : Value                                                            :
:..............:..................................................................:
:     Username : xxxx                                                             :
:      API Key : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                  :
: Endpoint URL : https://api.softlayer.com/xmlrpc/v3.1/                           :
:      Timeout : not set                                                          :
:..............:..................................................................:
Are you sure you want to write settings to "/root/.softlayer"? [Y/n]:
Configuration Updated Successfully

3. イメージ・テンプレートの取得

イメージ・テンプレート(スタンダード・イメージ)を取得します。コマンドが完了するとすぐに再起動が行われ、それまで作業していた ssh セッションも切断されます。

# slcli vs capture -n POC01 --note "Self caputre test 01" 11910733
:................:............................:
:           Name : Value                      :
:................:............................:
:          vs_id : 11910733                   :
:           date : 2015-08-28                 :
:           time : 10:57:44                   :
:    transaction : Create Cloud Disk Template :
: transaction_id : 22547431                   :
:      all_disks : None                       :
:................:............................:
#
Broadcast message from root@POC.softlayer.com
        (unknown) at 20:57 ...

The system is going down for power off NOW!

取得元の仮想サーバーが利用可能になり次第、再接続し、同じ手順で、合計3つのイメージ・テンプレート(POC01,POC02,POC03)を取得しました。

# slcli image list --private
<中略>
: 0aa24bdb-91d8-4166-bc01-1afebdd3617c :                        POC01               :       System       :  Private   :  xxxxxx :
: a8d6554f-b9bc-41b3-b590-09009b20ab4c :                        POC02               :       System       :  Private   :  xxxxxx :
: 51d35d4b-1755-48b9-bdd4-fe2e8ca546ce :                        POC03               :       System       :  Private   :  xxxxxx :
<以下略>

4. 取得したイメージからサーバーを作成(デプロイ)できることを確認

以下の様に取得したイメージからサーバーをデプロイできることを確認します。

# slcli vs create -D softlayer.com -H POC01 --image 0aa24bdb-91d8-4166-bc01-1afebdd3617c -c 1 -m 1024 --billing hourly -d tok02 --public -k id_rsa.pub -n 100
This action will incur charges on your account. Continue? [y/N]: y
:.........:......................................:
:    name : value                                :
:.........:......................................:
:      id : 11912673                             :
: created : 2015-08-28T11:11:51+09:00            :
:    guid : b33a295c-7b69-4adf-a0a8-4c3cff945e2e :
:.........:......................................:
# slcli vs create -D softlayer.com -H POC02 --image a8d6554f-b9bc-41b3-b590-09009b20ab4c -c 1 -m 1024 --billing hourly -d tok02 --public -k id_rsa.pub -n 100
This action will incur charges on your account. Continue? [y/N]: y
:.........:......................................:
:    name : value                                :
:.........:......................................:
:      id : 11912793                             :
: created : 2015-08-28T11:13:31+09:00            :
:    guid : 45305c86-9379-4538-b2f5-7812e180a154 :
:.........:......................................:
# slcli vs create -D softlayer.com -H POC03 --image 51d35d4b-1755-48b9-bdd4-fe2e8ca546ce -c 1 -m 1024 --billing hourly -d tok02 --public -k id_rsa.pub -n 100
This action will incur charges on your account. Continue? [y/N]: y
:.........:......................................:
:    name : value                                :
:.........:......................................:
:      id : 11912981                             :
: created : 2015-08-28T11:14:15+09:00            :
:    guid : 9b9469b8-b338-40df-8c20-a23ddd1cd283 :
:.........:......................................:

つづいて、しばらく待った後、デプロイが完了したかを確認します。

# slcli vs ready 11912673 ; slcli vs ready 11912793 ; slcli vs ready 11912981
READY
READY
READY

3. 後片付け

テンプレートとして正常に利用できることが確認できたので、テストで利用したサーバーおよびテンプレートをキャンセル/削除しておきます。

# slcli vs cancel 11912673
This action cannot be undone! Type "11912673" or press Enter to abort: 11912673
# slcli vs cancel 11912793
This action cannot be undone! Type "11912793" or press Enter to abort: 11912793
# slcli vs cancel 11912981
This action cannot be undone! Type "11912981" or press Enter to abort: 11912981
# slcli image delete 0aa24bdb-91d8-4166-bc01-1afebdd3617c
# slcli image delete a8d6554f-b9bc-41b3-b590-09009b20ab4c
# slcli image delete 51d35d4b-1755-48b9-bdd4-fe2e8ca546ce

最後にテンプレートの取得元を削除して、テスト終了となります。

# slcli vs cancel 11910733
This action cannot be undone! Type "11910733" or press Enter to abort: 11910733

4. まとめ

仮想サーバーから、自分自身のイメージ・テンプレート(スタンダード・イメージ) を取得することが可能であることを確認できました。
また、一連のテストを CLI から実行することで、カスタマー・ポータルでの選択間違いの可能性を低減し、(コマンド履歴を保存することで)楽に記録を残しつつ、テストできます。

蛇足

この記事を書く為にテストを繰り返していた際、イメージ・テンプレートからのデプロイがとまっている場合がありました。カスタマー・ポータルからチケットで問い合わせるべき状態でしたが、ちょっと別のことをしていて放置していたところ、数時間後に(SoftLayer側で対応してくれた?)無事に起動していることがわかりました。

参考

SoftLayer API Python Client
SoftLayerをコマンドラインから操作する #softlayer
ソフトレイヤー活用ガイド 4.9 コマンドでサーバーをオーダーするには?
SoftLayer への移行: SoftLayer コマンドライン・クライアントを扱う

注:各コマンド出力は見易さなどの為に、一部編集しています。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2