0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cloudn APIをサーバから実行させる

Last updated at Posted at 2018-05-29

手順①cloudmonkeyの実行環境を用意

参考:https://www.cloudn-service.com/guide/manuals/html/flat-api/rsts/APIInfo/api_client.html#how-to-api-client

インストール

# 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

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?