1
1

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 3 years have passed since last update.

ConoHaVPS API の「ローカルディスクのイメージ保存」の実践例

Last updated at Posted at 2021-07-03

ConoHa API を使ったローカルディスクのイメージ保存方法

下記 ConoHa API の使用例である.
簡潔な記載のため試行錯誤したので、補足しておく.

検証条件

時期

2021/01頃である

ローカルホスト環境

Bash Shellscript および jq コマンドを使用できる環境が便利である.
なお、jq コマンドのインストール方法は別途調べてほしい.

手順

1. 事前に VPS サーバを「停止」させておく

事前にイメージを保存したい VPS サーバを停止させておく 必要がある.
サーバを停止させておかないと、イメージ保存 API を叩いた際に HTTP ステータスコード 404 が返される (はずである).

2. API Token を得る

ここでは下記 URL の操作を行う. (API を実行するたびに使い捨ての API Token が必要になる)
https://support.conoha.jp/v/apitokens/#01

2-1. 「APIユーザ名」と「テナントID」を得る

事前に、上記 URL に記された要領で自身の「APIユーザ名」と「テナントID」を確認しておくこと.
ここでは下表のような値であったものと仮定する.

項目
APIユーザ名 gncu76543210
テナントID 1234567890abcdef0987654321fedcba
ConoHa ログインパスワード p@ssw0rd

2-2. 「API Token」を取り出す

上記「2-1」の値を使って、次の要領で「API Token」を取得する.

$ curl -i -X POST \
   -H "Accept: application/json" \
   -d '{ "auth": { "passwordCredentials": { "username": "gncu76543210", "password": "p@ssw0rd" }, 
   "tenantId": "1234567890abcdef0987654321fedcba" } }' \
   https://identity.tyo2.conoha.io/v2.0/tokens | sed -n '7,$p' | jq .access.token.id

3. イメージ保存 を行う

イメージを保存する際の名称を「BACKUP-1」とする.

URL は次のようになっている
・「v2」直後に「テナントID」を書く
・「servers」直後には後述の参考図の赤枠の値 (「aaaabbbb〜」) を書く

$ curl -i -X POST \
    -H "Accept: application/json" \
    -H "Content-Type: application/json" \
    -H "X-Auth-Token: 〈上記 2-2 で得られた API Token の値〉" \
    -d '{"createImage": {"name": "BACKUP-1"}}' \
    https://compute.tyo2.conoha.io/v2/1234567890abcdef0987654321fedcba/servers/aaaabbbb-cccc-dddd-eeee-ffffffffffff/action

 
参考図
conohaapi.jpg

以上

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?