概要
SoftLayerのコマンドライン・インタフェースをインストールして、ユーザーIDとAPIキーを設定して利用開始できるところまでの手順です。
Linux ディストリビューションにバンドルされている Python を利用して、slcli を利用すると、Python の バーションが古いために、警告メッセージが出ます。そこで、pyenv を利用して、任意のPythonのバージョンが利用できる様にして、警告が出ない様にします。
slcli ユーザーの作成
pyenvは、一般ユーザー環境に導入する必要があるので、ここでは、ユーザーとして takara を登録します。
# adduser takara
ユーザー `takara' を追加しています...
新しいグループ `takara' (1000) を追加しています...
新しいユーザー `takara' (1000) をグループ `takara' に追加しています...
ホームディレクトリ `/home/chef' を作成しています...
`/etc/skel' からファイルをコピーしています...
新しい UNIX パスワードを入力してください: mAnhatt0n
新しい UNIX パスワードを再入力してください: mAnhatt0n
passwd: password updated successfully
Changing the user information for chef
Enter the new value, or press ENTER for the default
Full Name []: Chef Administrator
Room Number []:
Work Phone []:
Home Phone []:
Other []:
以上で正しいですか? [Y/n] Y
次に、sudoersに追加して、自由にrootになれる様にしておきます。
takara ALL=(ALL) NOPASSWD: ALL
ssh鍵をrootからchefにコピーして、同じ鍵でログインできる様にします。
# cp -r .ssh /home/takara/
# chown -R chef:chef /home/takara/.ssh/
pyenv の導入と設定
詳しい導入方法と設定の解説は、https://github.com/yyuu/pyenv にありますので、参考に導入していきます。 注意点としては、rootではなくchefユーザーでインストールを実行します。
$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
.bash_profile を反映させるために、ソースするか、再ログインして、以下のコマンドで確認します。 そうすると、Linux Distribution のPython しか入っていないことが判ります。
$ pyenv versions
* system (set by /home/chef/.pyenv/version)
Python を導入する前に、gcc と zlib がビルドに必要なので、ここは root でインストールします。
$ sudo apt-get install git gcc make openssl libssl-dev libbz2-dev libreadline-dev libsqlite3-dev
次は Python の slcli コマンドで ワーニングで出ないバージョンをインストールします。
$ pyenv install 2.7.10
確認として以下のコマンドの結果から、導入されているものの、選択されていない事が判ります。
$ pyenv versions
* system (set by /home/chef/.pyenv/version)
2.7.10
今回導入したバージョンを選択して、再確認します。
$ pyenv global 2.7.10
$ pyenv versions
system
* 2.7.10 (set by /home/chef/.pyenv/version)
もう一回、念押しの確認
$ python --version
Python 2.7.10
これで Python の作成が完了しました。
pipを利用して slcli をインストール
以下のコマンドで、slcliコマンドの導入が完了です。
$ pip install softlayer
Collecting softlayer
Downloading SoftLayer-4.1.1-py2.py3-none-any.whl (248kB)
100% |████████████████████████████████| 249kB 1.3MB/s
Collecting prompt-toolkit (from softlayer)
Downloading prompt_toolkit-0.52-py2-none-any.whl (188kB)
100% |████████████████████████████████| 188kB 1.7MB/s
Collecting click>=5 (from softlayer)
Downloading click-5.1-py2.py3-none-any.whl (65kB)
100% |████████████████████████████████| 65kB 3.9MB/s
Collecting six>=1.7.0 (from softlayer)
Downloading six-1.9.0-py2.py3-none-any.whl
Collecting prettytable>=0.7.0 (from softlayer)
Downloading prettytable-0.7.2.tar.bz2
Collecting requests>=2.7.0 (from softlayer)
Downloading requests-2.7.0-py2.py3-none-any.whl (470kB)
100% |████████████████████████████████| 471kB 756kB/s
Collecting pygments (from prompt-toolkit->softlayer)
Downloading Pygments-2.0.2-py2-none-any.whl (672kB)
100% |████████████████████████████████| 675kB 554kB/s
Collecting wcwidth (from prompt-toolkit->softlayer)
Downloading wcwidth-0.1.5-py2.py3-none-any.whl
Installing collected packages: six, pygments, wcwidth, prompt-toolkit, click, prettytable, requests, softlayer
Running setup.py install for prettytable
Successfully installed click-5.1 prettytable-0.7.2 prompt-toolkit-0.52 pygments-2.0.2 requests-2.7.0 six-1.9.0 softlayer-4.1.1 wcwidth-0.1.5
ユーザーIDとAPIキーの取得とセット
以下のコマンドで、ユーザー名とAPIキーをセットします。 このユーザー名とAPIキーは、「Account」->「Users」で目的のユーザーIDの場所で、「API Key」 列の View をクリックすると表示されるので、コピペしてインプットします。
$ slcli config setup
Username []: *********
API Key or Password []:
Endpoint (public|private|custom) [public]:
Timeout [0]:
:..............:..................................................................:
: Name : Value :
:..............:..................................................................:
: Username : ********* :
: API Key : **************************************************************** :
: Endpoint URL : https://api.softlayer.com/xmlrpc/v3.1/ :
: Timeout : not set :
:..............:..................................................................:
Are you sure you want to write settings to "/home/chef/.softlayer"? [Y/n]: Y
Configuration Updated Successfully
動作確認のために、次のコマンドを実行して、エラーが出なければ完了です。
$ slcli summary