SoftLayerをコマンドラインから操作する #softlayer

この記事は1年以上前に投稿されました。情報が古い可能性がありますので、ご注意ください。
SoftLayerコマンドライン・クライアントとは
SoftLayerコマンドライン・クライアントとは、Pythonで作成されたSoftLayerをコマンドラインから操作するためのツールです。
SoftLayerコマンドライン・クライアントのインストール
インストールに従い、Pythonのeasy_installコマンドでインストールしてください。
$ sudo yum install -y python-setuptools $ sudo easy_install softlayer
$ sudo apt-get install python-setuptools $ sudo easy_install softlayer
$ sl
usage: sl [...]
sl help
sl help
sl [-h | --help]
SoftLayer Command-line Client
The available modules are:
Compute:
bmc Bare Metal Cloud
cci Cloud Compute Instances
image Manages compute and flex images
metadata Get details about this machine. Also available with 'my' and 'meta'
server Hardware servers
sshkey Manage SSH keys on your account
Networking:
dns Domain Name System
firewall Firewall rule and security management
globalip Global IP address management
rwhois RWhoIs operations
ssl Manages SSL
subnet Subnet ordering and management
vlan Manage VLANs on your account
Storage:
iscsi View iSCSI details
nas View NAS details
General:
config View and edit configuration for this tool
summary Display an overall summary of your account
help Show help
See 'sl help ' for more information on a specific module.
To use most commands your SoftLayer username and api_key need to be configured.
The easiest way to do that is to use: 'sl config setup'
APIキーの取得
APIキーはSoftLayerカスタマーポータルから取得します。
メニューバーのAccountタブからUsersを選択してください。
表示されたユーザのAPI KeyのViewを選択すると、そのユーザのAPIキーが表示されます。
SoftLayerコマンドライン・クライアントはこのユーザ名とAPIキーを用いてSoftLayerにアクセスします。
SoftLayerコマンドライン・クライアントの設定
まず、最初は何も設定がされていないことをsl config showコマンドで確認します。
$ sl config show :..............:.....................................: : Name : Value : :..............:.....................................: : Username : not set : : API Key : not set : : Endpoint URL : https://api.softlayer.com/xmlrpc/v3 : : Timeout : not set : :..............:.....................................:
sl config setupコマンドで設定を行います。
Usernameにはユーザ名、API Key or PasswordにはAPIキー、Endpointはそのままエンターを入力してください。
$ sl config setup Username []: SL****** API Key or Password []: Endpoint (public|private|custom): :..............:..................................................................: : Name : Value : :..............:..................................................................: : Username : SL****** : : API Key : **************************************************************** : : Endpoint URL : https://api.softlayer.com/xmlrpc/v3/ : : Timeout : not set : :..............:..................................................................: Are you sure you want to write settings to "/home/********/.softlayer"? [Y/n]: Configuration Updated Successfully
問題なければホームディレクトリの.softlayerに内容が保存されます。
$ cat ~/.softlayer [softlayer] username = SL****** api_key = **************************************************************** endpoint_url = https://api.softlayer.com/xmlrpc/v3/
これで以降、slコマンドを通してSoftLayerを操作できます。
SoftLayerコマンドライン・クライアントの利用
仮想サーバ(Cloud Compute Instances, CCI)の一覧を表示します。
$ sl cci list :.........:............:............................:.......:........:...............:...............:....................: : id : datacenter : host : cores : memory : primary_ip : backend_ip : active_transaction : :.........:............:............................:.......:........:...............:...............:....................: : ******* : sjc01 : softlayer-test.example.com : 1 : 1G : 50.23.***.*** : 10.55.***.*** : - : :.........:............:............................:.......:........:...............:...............:....................:
仮想サーバの詳細を表示します。
$ sl cci detail ******* :....................:...............................: : Name : Value : :....................:...............................: : id : ******* : : hostname : softlayer-test.example.com : : status : Active : : active_transaction : - : : state : Running : : datacenter : sjc01 : : os : Ubuntu : : os_version : 12.04-64 Minimal for CCI : : cores : 1 : : memory : 1G : : public_ip : 50.23.***.*** : : private_ip : 10.55.***.*** : : private_only : False : : private_cpu : False : : created : 2014-02-25T10:44:44+09:00 : : modified : 2014-02-25T11:19:23+09:00 : : vlans : :.........:........:........: : : : : type : number : id : : : : :.........:........:........: : : : : PRIVATE : **** : ****** : : : : : PUBLIC : **** : ****** : : : : :.........:........:........: : :....................:...............................:
仮想サーバを停止します。
$ sl cci power-off ******* This will power off the CCI with id *******. Continue? [y/N]: y
仮想サーバを起動します。
$ sl cci power-on *******
仮想サーバを破棄します。
$ sl cci cancel ******* This action cannot be undone! Type "*******" or press Enter to abort: *******
仮想サーバを作成する前に、指定可能なリソースを確認しておきます。
$ sl cci create-options :.................:....................................................................................................: : Name : Value : :.................:....................................................................................................: : datacenter : ams01,dal01,dal05,dal06,sea01,sjc01,sng01,wdc01 : : cpus (private) : 1,2,4,8 : : cpus (standard) : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 : : memory : 1024,2048,3072,4096,5120,6144,7168,8192,9216,10240,11264,12288,13312,14336,15360,16384,32768,49152 : : os (CENTOS) : CENTOS_5_32 : : : CENTOS_5_64 : : : CENTOS_6_32 : : : CENTOS_6_64 : : os (CLOUDLINUX) : CLOUDLINUX_5_32 : : : CLOUDLINUX_5_64 : : : CLOUDLINUX_6_32 : : : CLOUDLINUX_6_64 : : os (DEBIAN) : DEBIAN_5_32 : : : DEBIAN_5_64 : : : DEBIAN_6_32 : : : DEBIAN_6_64 : : : DEBIAN_7_32 : : : DEBIAN_7_64 : : os (REDHAT) : REDHAT_5_32 : : : REDHAT_5_32 : : : REDHAT_5_64 : : : REDHAT_5_64 : : : REDHAT_6_32 : : : REDHAT_6_32 : : : REDHAT_6_64 : : : REDHAT_6_64 : : os (UBUNTU) : UBUNTU_10_32 : : : UBUNTU_10_64 : : : UBUNTU_12_32 : : : UBUNTU_12_64 : : : UBUNTU_8_32 : : : UBUNTU_8_64 : : os (VYATTACE) : VYATTACE_6.5_64 : : : VYATTACE_6.6_64 : : os (WIN) : WIN_2003-DC-SP2-1_32 : : : WIN_2003-DC-SP2-1_64 : : : WIN_2003-ENT-SP2-5_32 : : : WIN_2003-ENT-SP2-5_64 : : : WIN_2003-STD-SP2-5_32 : : : WIN_2003-STD-SP2-5_64 : : : WIN_2008-DC-R2_64 : : : WIN_2008-DC-SP2_64 : : : WIN_2008-ENT-R2_64 : : : WIN_2008-ENT-SP2_32 : : : WIN_2008-ENT-SP2_64 : : : WIN_2008-STD-R2-SP1_64 : : : WIN_2008-STD-R2_64 : : : WIN_2008-STD-SP2_32 : : : WIN_2008-STD-SP2_64 : : : WIN_2012-DC_64 : : : WIN_2012-STD_64 : : local disk(0) : 25,100 : : local disk(2) : 25,100,150,200,300 : : san disk(0) : 25,100 : : san disk(2) : 10,20,25,30,40,50,75,100,125,150,175,200,250,300,350,400,500,750,1000,1500,2000 : : san disk(3) : 10,20,25,30,40,50,75,100,125,150,175,200,250,300,350,400,500,750,1000,1500,2000 : : san disk(4) : 10,20,25,30,40,50,75,100,125,150,175,200,250,300,350,400,500,750,1000,1500,2000 : : san disk(5) : 10,20,25,30,40,50,75,100,125,150,175,200,250,300,350,400,500,750,1000,1500,2000 : : nic : 10,100,1000 : :.................:....................................................................................................:
仮想サーバを作成する際のオプション一覧です。
$ sl cci create --help
usage: sl cci create [--key=KEY...] [options]
Order/create a CCI. See 'sl cci create-options' for valid options
Required:
-c, --cpu=CPU Number of CPU cores
-D, --domain=DOMAIN Domain portion of the FQDN. example: example.com
-H, --hostname=HOST Host portion of the FQDN. example: server
--image=GUID Image GUID. See: 'sl image list' for reference
-m, --memory=MEMORY Memory in mebibytes. example: 2048
-o, --os=OS OS install code. Tip: you can specify _LATEST
--hourly Hourly rate instance type
--monthly Monthly rate instance type
Optional:
-d, --datacenter=DC Datacenter shortname (sng01, dal05, ...)
Note: Omitting this value defaults to the first
available datacenter
--dedicated Allocate a dedicated CCI (non-shared host)
--dry-run, --test Do not create CCI, just get a quote
--export=FILE Exports options to a template file
-F, --userfile=FILE Read userdata from file
(Only HTTPS executes, HTTP leaves file in /root)
-i, --postinstall=URI Post-install script to download
-k, --key=KEY SSH keys to add to the root user. Can be specified
multiple times
--like=IDENTIFIER Use the configuration from an existing CCI
-n, --network=MBPS Network port speed in Mbps
--private Forces the CCI to only have access the private
network
-t, --template=FILE A template file that defaults the command-line
options using the long name in INI format
-u, --userdata=DATA User defined metadata string
--vlan_public=VLAN The ID of the public VLAN on which you want the CCI
placed.
--vlan_private=VLAN The ID of the private VLAN on which you want the CCI
placed.
--wait=SECONDS Block until CCI is finished provisioning for up to X
seconds before returning
Prompt Options:
-y, --really Confirm all prompt actions
Standard Options:
--format=ARG Output format. [Options: table, raw] [Default: table]
-C FILE --config=FILE Config file location. [Default: ~/.softlayer]
--debug=LEVEL Specifies the debug noise level
1=warn, 2=info, 3=debug
--timings Time each API call and display after results
-h --help Show this screen
- CPUコア数: 1
- ドメイン名: example.com
- ホスト名: softlayer-test01
- メモリ: 1024MB
- OS: Ubuntu 12.04 (amd64)
- データセンター: サンノゼ
で仮想サーバを作成します。
$ sl cci create -c 1 -D example.com -H softlayer-test01 -m 1024 -o UBUNTU_12_64 -d sjc01 --hourly This action will incur charges on your account. Continue? [y/N]: y :.........:......................................: : name : value : :.........:......................................: : id : ******* : : created : 2014-02-26T16:33:33+09:00 : : guid : ********-****-****-****-************ : :.........:......................................:
数分で仮想サーバが準備され、アクセスできるようになります。
$ sl cci detail ******* --password :....................:...............................: : Name : Value : :....................:...............................: : id : ******* : : hostname : softlayer-test01.example.com : : status : Active : : active_transaction : - : : state : Running : : datacenter : sjc01 : : os : Ubuntu : : os_version : 12.04-64 Minimal for CCI : : cores : 1 : : memory : 1G : : public_ip : 50.97.***.*** : : private_ip : 10.55.***.*** : : private_only : False : : private_cpu : False : : created : 2014-02-26T16:33:33+09:00 : : modified : 2014-02-26T16:35:57+09:00 : : vlans : :.........:........:........: : : : : type : number : id : : : : :.........:........:........: : : : : PRIVATE : **** : ****** : : : : : PUBLIC : **** : ****** : : : : :.........:........:........: : : users : :..........:..........: : : : : username : password : : : : :..........:..........: : : : : root : ******** : : : : :..........:..........: : :....................:...............................:
$ ssh root@50.97.***.*** The authenticity of host '50.97.***.*** (50.97.***.***)' can't be established. ECDSA key fingerprint is **:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '50.97.***.***' (ECDSA) to the list of known hosts. root@50.97.***.***'s password: Welcome to Ubuntu 12.04.4 LTS (GNU/Linux 3.2.0-58-virtual x86_64) * Documentation: https://help.ubuntu.com/ The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. -bash: warning: setlocale: LC_ALL: cannot change locale (ja_JP.UTF-8) -bash: warning: setlocale: LC_ALL: cannot change locale (ja_JP.UTF-8) root@softlayer-test01:~#
このように、とても容易に仮想サーバを準備することができました。


