手順①cloudmonkeyの実行環境を用意
インストール
# yum -y install python python-setuptools
# easy_install cloudmonkey
keyのセット
$ cloudmonkey
(これ以降はshellではなくcloudmonkey内でのコマンド実行)
> set url https://comp-api.jp-e1.cloudn-service.com/client/api
> set apikey ## APIアクセスキーIDを入力する
> set secretkey ## API秘密鍵を入力する
> exit
実行
# cloudmonkey
> list virtualmachines
で正常に仮想マシンの一覧を取得できることを確認
手順②シェルファイル作成
/path/test.sh
# !/bin/bash
cli=cloudmonkey
id=【仮想サーバのID】
echo "サーバの状態確認"
state=`$cli listVirtualMachines id=$id | grep ^state\ = | awk '{print $3}'`
echo "state" $state
if [ "$state" = "Running" ]; then
echo "状態は正常です。"
else
echo "サーバ起動実行"
start=`$cli startVirtualMachine id=$id`
fi
echo "完了しました。"
一度コンソールでサーバを停止させてから実行し、サーバが起動することを確認。
叩くAPIはこの辺を参照
https://www.cloudn-service.com/guide/manuals/html/flat-api/rsts/ComputeStyle/index.html