🍬

WebARENA Indigo の API を試す

2024/10/17に公開

はじめに

格安VPSでおなじみの WebARENA Indigo では APIで機能呼び出しできる。
ここでいくつか試してみたい。

参考

APIドキュメント
NTTPC Indigo で OS を入れ替える

準備

  • ダッシュボードの「API鍵の管理」で「API鍵の作成」を実施する。
  • 表示されるAPI鍵 と API秘密鍵 を控える。(API秘密鍵 は2度と表示されない。紛失したら削除して再度作成する。漏洩したら削除して作成しなおす)
  • 控えた情報を以下で保存
.webarenaindigo
IndigoApiPrivateKey=API鍵
IndigoApiKey=API秘密鍵
  • 環境変数として読み込む
chmod 600 .webarenaindigo
. .webarenaindigo

アクセストークン

API鍵 と API秘密鍵をもとに、アクセストークンを取得するAPI。
この他のAPIは、ここで取得したアクセストークンにより認証を行うことになる。

curl -s -X POST \
  https://api.customer.jp/oauth/v1/accesstokens\
  -H 'Content-Type: application/json' \
  -d '{
    "grantType": "client_credentials",
    "clientId": "'${IndigoApiKey}'",
    "clientSecret": "'${IndigoApiPrivateKey}'",
    "code": ""
}' | tee tmp | jq .
{
  "accessToken": "アクセストークン",
  "tokenType": "BearerToken",
  "expiresIn": "3599",
  "scope": "",
  "issuedAt": "1728421337629"
}

issuedAt は以下のような情報。

$ date --date @$(expr $(jq -r '.issuedAt' tmp) / 1000)
Tue Oct  8 21:02:17 UTC 2024

expiresIn が示すのは、おそらく3600秒=1時間。

以下では、一時ファイルに保存した tmp ファイルを使って jq -r .accessToken tmp でアクセストークンを取得して利用する。
アクセストークンが期限切れしたら、同様にして再取得する。

python での例

Python3 の requests でアクセストークンを取得する

>>> import os
>>> import requests
>>> import json
>>>
>>> IndigoApiKey = os.environ['IndigoApiKey']
>>> IndigoApiPrivateKey = os.environ['IndigoApiPrivateKey']
>>>
>>> url = 'https://api.customer.jp/oauth/v1/accesstokens'
>>> headers = {'Content-Type': 'application/json'}
>>> payload = {
...     "grantType": "client_credentials",
...     "clientId": IndigoApiKey,
...     "clientSecret": IndigoApiPrivateKey,
...     "code": ""
... }
>>>
>>> r = requests.post(url, data=json.dumps(payload), headers=headers)
>>>
>>> r.status_code
201
>>>
>>> r.headers
{'content-type': 'application/json', 'access-control-allow-origin': '*', 'access-control-allow-headers': 'origin, x-requested-with, accept, Authorization, Content-Type', 'access-control-max-age': '1728000', 'access-control-allow-methods': 'GET, PUT, POST, DELETE', 'x-request-id': '68bd3d18-b318-49d2-aa72-4d879ceb7563', 'Content-Length': '140', 'date': 'Thu, 10 Oct 2024 22:36:32 GMT', 'via': '1.1 google', 'Alt-Svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'}
>>>
>>> r.encoding
'utf-8'
>>>
>>> r.content
b'{"accessToken": "アクセストークン", "tokenType": "BearerToken", "expiresIn": "3599" , "scope": "" , "issuedAt": "1728599792520"}'
>>>
>>> print(json.dumps(json.loads(r.text), indent=4))
{
    "accessToken": "アクセストークン",
    "tokenType": "BearerToken",
    "expiresIn": "3599",
    "scope": "",
    "issuedAt": "1728599792520"
}
>>>
>>> print(json.dumps(r.json(), indent=2))
{
  "accessToken": "アクセストークン",
  "tokenType": "BearerToken",
  "expiresIn": "3599",
  "scope": "",
  "issuedAt": "1728599792520"
}
>>>
>>> accesstoken = r.json().get("accessToken")
>>>
>>> print(accesstoken)
i4wFoE89bxrTUTsKQ49Lg1MGCQyi
>>>

SSH Key

VPS構築時にユーザホームディレクトリへ入れるSSH公開鍵を管理する

登録されている一覧の取得

curl -s -X GET \
https://api.customer.jp/webarenaIndigo/v1/vm/sshkey \
-H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)''  | jq .
{
  "success": true,
  "total": 1,
  "sshkeys": [
    {
      "id": xxxx,
      "service_id": xxxx,
      "user_id": xxxx,
      "name": "sshkeyname",
      "sshkey": "ssh-rsa xxxx",
      "status": "ACTIVE",
      "created_at": "2022-05-20 13:57:39",
      "updated_at": "2022-05-20 13:57:39"
    }
  ]
}

Python を使って取得してみる。

>>> url = 'https://api.customer.jp/webarenaIndigo/v1/vm/sshkey'
>>>
>>> headers = {'Authorization': 'Bearer '+accesstoken }
または
>>> headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer '+accesstoken }
どちらでもいけた。結果は変わらない
>>>
>>> r = requests.get(url, headers=headers)
>>>
>>> r.headers
{'date': 'Sat, 12 Oct 2024 10:42:12 GMT', 'vary': 'Authorization', 'cache-control': 'no-cache, private', 'severity': '200', 'x-content-type-options': 'nosniff', 'x-frame-options': 'sameorigin', 'x-xss-protection': '1; mode=block', 'strict-transport-security': 'max-age=631138519; includeSubDomains', 'Content-Length': '596', 'content-type': 'application/json', 'access-control-allow-origin': '*', 'access-control-allow-headers': 'origin, x-requested-with, accept, Authorization, Content-Type', 'access-control-max-age': '1728000', 'access-control-allow-methods': 'GET, PUT, POST, DELETE', 'x-request-id': '17bce742-8ce3-43c4-a865-f684830ad7e1', 'via': '1.1 google', 'Alt-Svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'}
>>>
>>> r.status_code
200
>>>
>>> r.encoding
'utf-8'
>>>
>>> r.content
b'{"success":true,"total":1,"sshkeys":[{"id":xxxx,"service_id":"xxxx","user_id":xxxx,"name":"arukas","sshkey":"ssh-rsa xxxx","status":"ACTIVE","created_at":"2022-05-20 13:57:39","updated_at":"2022-05-20 13:57:39"}]}'
>>>

SSH公開鍵の登録

手持ちの公開鍵をアップロードする

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/vm/sshkey \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{
   "sshName": "testsshkeyname",
   "sshKey": "ssh-rsa xxxx
  }' | jq .
{
  "success": true,
  "message": "SSH key has been added successfully",
  "sshKey": {
    "name": "testsshkeyname",
    "sshkey": "ssh-rsa xxxx,
    "status": "ACTIVE",
    "user_id": xxxx,
    "service_id": "idg-xxxx",
    "updated_at": "2024-10-11 22:01:18",
    "created_at": "2024-10-11 22:01:18",
    "id": 40277
  }
}

結果確認

curl -s -X GET   https://api.customer.jp/webarenaIndigo/v1/vm/sshkey \
-H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)''  | jq '.sshkeys[] | select(.id == 40277)'
{
  "id": 40277,
  "service_id": "idg-xxxx",
  "user_id": xxxx,
  "name": "testsshkeyname",
  "sshkey": "ssh-rsa xxxx,
  "status": "ACTIVE",
  "created_at": "2024-10-11 22:01:18",
  "updated_at": "2024-10-11 22:01:18"
}

キー情報更新

キーを無効化してみた

curl -s -X PUT \
  https://api.customer.jp/webarenaIndigo/v1/vm/sshkey/40277 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{
   "sshName": "testsshkeyname",
   "sshKey": "ssh-rsa xxxx,
   "sshKeyStatus": "DEACTIVE"
}' | jq .
{
  "success": true,
  "message": "SSH key has been updated successfully "
}

結果確認

curl -s -X GET   https://api.customer.jp/webarenaIndigo/v1/vm/sshkey \
-H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)''  | jq '.sshkeys[] | select(.id == 40277)'
{
  "id": 40277,
  "service_id": "idg-xxxx",
  "user_id": xxxx,
  "name": "testsshkeyname",
  "sshkey": "ssh-rsa xxxx"id":xxxx,,
  "status": "DEACTIVE",
  "created_at": "2024-10-11 22:01:18",
  "updated_at": "2024-10-11 22:14:17"
}

キー削除

curl -s -X DELETE \
  https://api.customer.jp/webarenaIndigo/v1/vm/sshkey/40277 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "message": "SSH key has been removed successfully"
}

APIキー

APIを利用して、別のAPI鍵/API秘密鍵を作成することができる。

新規生成

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/auth/create/apikey \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "apiKey": "APIキー",
  "apiSecret": "APIシークレット"
}

確認

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/auth/apikey \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq '.accesstokens[] | select(.id == 7574)'
{
  "id": 7574,
  "apiKey": "APIキー",
  "created_at": "2024-10-08 23:22:50"
}

削除

curl -s -X DELETE \
  https://api.customer.jp/webarenaIndigo/v1/auth/apikey/7574 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "message": "API Key is removed successfully"
}

インスタンス

インスタンスタイプ一覧

現状使えるインスタンスタイプは KVM Instance のみ。

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/vm/instancetypes \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "total": 2,
  "instanceTypes": [
    {
      "id": 1,
      "name": "instance",
      "display_name": "KVM Instance",
      "created_at": "2019-10-09 13:11:20",
      "updated_at": "2019-10-09 13:11:20"
    },
    {
      "id": 2,
      "name": "microvps",
      "display_name": "MicroVPS",
      "created_at": "2019-10-09 13:11:20",
      "updated_at": "2019-10-09 13:11:20"
    }
  ]
}

リージョン一覧

現状使えるリージョンは Tokyo のみ。

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/vm/getregion?instanceTypeId=1 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "total": 1,
  "regionlist": [
    {
      "id": 1,
      "oem_id": 1,
      "name": "Tokyo",
      "use_possible_date": "2019-10-03 23:07:19"
    }
  ]
}
curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/vm/getregion?instanceTypeId=2 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "total": 0,
  "regionlist": []
}

OSタイプ

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/vm/oslist?instanceTypeId=1 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "total": 9,
  "osCategory": [
    {
      "id": 1,
      "name": "Ubuntu",
      "logo": "Ubudu.png",
      "osLists": [
        {
          "id": 1,
          "categoryid": 1,
          "code": "Ubuntu",
          "name": "Ubuntu18.04",
          "viewname": "Ubuntu 18.04",
          "instancetype_id": 1
        },
        {
          "id": 6,
          "categoryid": 1,
          "code": "Ubuntu",
          "name": "Ubuntu20.04",
          "viewname": "Ubuntu 20.04",
          "instancetype_id": 1
        },
        {
          "id": 13,
          "categoryid": 1,
          "code": "Ubuntu",
          "name": "Ubuntu22.04",
          "viewname": "Ubuntu 22.04",
          "instancetype_id": 1
        },
        {
          "id": 25,
          "categoryid": 1,
          "code": "Ubuntu",
          "name": "Ubuntu24.04",
          "viewname": "Ubuntu 24.04",
          "instancetype_id": 1
        }
      ]
    },
    {
      "id": 2,
      "name": "CentOS",
      "logo": "CentOS.png",
      "osLists": [
        {
          "id": 2,
          "categoryid": 2,
          "code": "CentOS",
          "name": "CentOS7.5",
          "viewname": "CentOS 7.5",
          "instancetype_id": 1
        },
        {
          "id": 5,
          "categoryid": 2,
          "code": "CentOS",
          "name": "CentOS8.1",
          "viewname": "CentOS 8.1",
          "instancetype_id": 1
        },
        {
          "id": 9,
          "categoryid": 2,
          "code": "CentOS",
          "name": "CentOS_Stream8",
          "viewname": "CentOS Stream8",
          "instancetype_id": 1
        },
        {
          "id": 14,
          "categoryid": 2,
          "code": "CentOS",
          "name": "CentOS_Stream9",
          "viewname": "CentOS Stream9",
          "instancetype_id": 1
        }
      ]
    },
    {
      "id": 3,
      "name": "Import VM",
      "logo": "ImportVm.png",
      "osLists": []
    },
    {                                                                                                                                                                                                                               [93/1964]
      "id": 4,
      "name": "Windows",
      "logo": "windows.png",
      "osLists": [
        {
          "id": 7,
          "categoryid": 4,
          "code": "WinOS",
          "name": "WindowsServer2019",
          "viewname": "Windows Server 2019 (no-RDS)",
          "instancetype_id": 1
        },
        {
          "id": 11,
          "categoryid": 4,
          "code": "WinOS",
          "name": "WindowsServer2022",
          "viewname": "Windows Server 2022 (no-RDS)",
          "instancetype_id": 1
        }
      ]
    },
    {
      "id": 5,
      "name": "Rocky",
      "logo": "Rocky.png",
      "osLists": [
        {
          "id": 10,
          "categoryid": 5,
          "code": "Rocky",
          "name": "RockyLinux8.4",
          "viewname": "Rocky Linux 8.4",
          "instancetype_id": 1
        },
        {
          "id": 19,
          "categoryid": 5,
          "code": "Rocky",
          "name": "RockyLinux9.0",
          "viewname": "Rocky Linux 9.0",
          "instancetype_id": 1
        },
        {
          "id": 23,
          "categoryid": 5,
          "code": "Rocky",
          "name": "RockyLinux9.3",
          "viewname": "Rocky Linux 9.3",
          "instancetype_id": 1
        }
      ]
    },
    {                                                                                                                                                                                                                               [39/1964]
      "id": 6,
      "name": "Oracle",
      "logo": "Oracle.png",
      "osLists": [
        {
          "id": 15,
          "categoryid": 6,
          "code": "Oracle",
          "name": "OracleLinux8.6",
          "viewname": "Oracle Linux 8.6",
          "instancetype_id": 1
        }
      ]
    },
    {
      "id": 7,
      "name": "Alma",
      "logo": "Alma.png",
      "osLists": [
        {
          "id": 16,
          "categoryid": 7,
          "code": "Alma",
          "name": "AlmaLinux8.6",
          "viewname": "AlmaLinux 8.6",
          "instancetype_id": 1
        },
        {
          "id": 17,
          "categoryid": 7,
          "code": "Alma",
          "name": "AlmaLinux9.0",
          "viewname": "AlmaLinux 9.0",
          "instancetype_id": 1
        },
        {
          "id": 24,
          "categoryid": 7,
          "code": "Alma",
          "name": "AlmaLinux9.3",
          "viewname": "AlmaLinux 9.3",
          "instancetype_id": 1
        }
      ]
    },
    {
      "id": 8,
      "name": "Debian",
      "logo": "Debian.png",
      "osLists": [
        {
          "id": 18,
          "categoryid": 8,
          "code": "Debian",
          "name": "Debian11",
          "viewname": "Debian 11",
          "instancetype_id": 1
        },
        {
          "id": 22,
          "categoryid": 8,
          "code": "Debian",
          "name": "Debian12",
          "viewname": "Debian 12",
          "instancetype_id": 1
        }
      ]
    },
    {
      "id": 9,
      "name": "KUSANAGI",
      "logo": "",
      "osLists": [
        {
          "id": 20,
          "categoryid": 9,
          "code": "KUSANAGI",
          "name": "KUSANAGI9_CentOS_Stream8",
          "viewname": "KUSANAGI 9 (CentOS Stream8)",
          "instancetype_id": 1
        },
        {
          "id": 21,
          "categoryid": 9,
          "code": "KUSANAGI",
          "name": "KUSANAGI9_CentOS_Stream9",
          "viewname": "KUSANAGI 9 (CentOS Stream9)",
          "instancetype_id": 1
        }
      ]
    }
  ]
}
curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/vm/oslist?instanceTypeId=2 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "total": 9,
  "osCategory": [
    {
      "id": 1,
      "name": "Ubuntu",
      "logo": "Ubudu.png",
      "osLists": []
    },
    {
      "id": 2,
      "name": "CentOS",
      "logo": "CentOS.png",
      "osLists": []
    },
    {
      "id": 3,
      "name": "Import VM",
      "logo": "ImportVm.png",
      "osLists": []
    },
    {
      "id": 4,
      "name": "Windows",
      "logo": "windows.png",
      "osLists": []
    },
    {
      "id": 5,
      "name": "Rocky",
      "logo": "Rocky.png",
      "osLists": []
    },
    {
      "id": 6,
      "name": "Oracle",
      "logo": "Oracle.png",
      "osLists": []
    },
    {
      "id": 7,
      "name": "Alma",
      "logo": "Alma.png",
      "osLists": []
    },
    {
      "id": 8,
      "name": "Debian",
      "logo": "Debian.png",
      "osLists": []
    },
    {
      "id": 9,
      "name": "KUSANAGI",
      "logo": "",
      "osLists": []
    }
  ]
}

スペック

利用できるスペックは、LinuxかWindowsかで異なる。

Debian12の場合

curl -s -X GET \
  'https://api.customer.jp/webarenaIndigo/v1/vm/getinstancespec?instanceTypeId=1&osId=22' \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "total": 7,
  "speclist": [
    {
      "id": 1,
      "code": "1vCPU1GB20GB",
      "name": "Memory1GB,1vCPU,SSD20GB",
      "description": "<b>1</b> vCPU <br> <b>1 GB</b> RAM <br> <b>20 GB</b> SSD <br><b>100 </b> Mbps",
      "use_possible_date": "2019-10-03 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv46dual",
      "created_at": "2019-10-09 13:11:49",
      "updated_at": "2019-10-09 13:11:49",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 1,
        "plan_id": 1,
        "name": "1CR1GB",
        "param": "vcpus",
        "limitnum": 1
      }
    },
    {
      "id": 2,
      "code": "2vCPU2GB40GB",
      "name": "Memory2GB,2vCPU,SSD40GB",
      "description": "<b>2</b> vCPU <br> <b>2 GB</b> RAM <br> <b>40 GB</b> SSD <br><b>100 </b> Mbps",
      "use_possible_date": "2019-10-03 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv46dual",
      "created_at": "2019-10-09 13:11:49",
      "updated_at": "2019-10-09 13:11:49",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 8,
        "plan_id": 2,
        "name": "2CR2GB",
        "param": "vcpus",
        "limitnum": 2
      }
    },
    {                                                                                                                                                                                                                               [72/1835]
      "id": 3,
      "code": "4vCPU4GB80GB",
      "name": "Memory4GB,4vCPU,SSD80GB",
      "description": "<b>4</b> vCPU <br> <b>4 GB</b> RAM <br> <b>80 GB</b> SSD <br><b>500 </b> Mbps",
      "use_possible_date": "2019-11-19 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv46dual",
      "created_at": "2019-10-09 13:11:49",
      "updated_at": "2019-10-09 13:11:49",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 15,
        "plan_id": 3,
        "name": "4CR4GB",
        "param": "vcpus",
        "limitnum": 4
      }
    },
    {
      "id": 4,
      "code": "6vCPU8GB160GB",
      "name": "Memory8GB,6vCPU,SSD160GB",
      "description": "<b>6</b> vCPU <br> <b>8 GB</b> RAM <br> <b>160 GB</b> SSD <br><b>1000 </b> Mbps",
      "use_possible_date": "2019-11-19 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv46dual",
      "created_at": "2019-10-09 13:11:49",
      "updated_at": "2019-10-09 13:11:49",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 22,
        "plan_id": 4,
        "name": "6CR8GB",
        "param": "vcpus",
        "limitnum": 6
      }
    },
    {                                                                                                                                                                                                                               [22/1835]
      "id": 5,
      "code": "6vCPU16GB320GB",
      "name": "Memory16GB,6vCPU,SSD320GB",
      "description": "<b>6</b> vCPU <br> <b>16 GB</b> RAM <br> <b>320 GB</b> SSD <br><b>1000 </b> Mbps",
      "use_possible_date": "2020-04-22 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv46dual",
      "created_at": "2020-04-23 01:20:39",
      "updated_at": "2020-04-23 01:20:39",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 29,
        "plan_id": 5,
        "name": "6CR16GB",
        "param": "vcpus",
        "limitnum": 6
      }
    },
    {
      "id": 6,
      "code": "8vCPU32GB640GB",
      "name": "Memory32GB,8vCPU,SSD640GB",
      "description": "<b>8</b> vCPU <br> <b>32 GB</b> RAM <br> <b>640 GB</b> SSD <br><b>1000 </b> Mbps",
      "use_possible_date": "2020-04-22 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv46dual",
      "created_at": "2020-04-23 01:20:39",
      "updated_at": "2020-04-23 01:20:39",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 36,
        "plan_id": 6,
        "name": "8CR32GB",
        "param": "vcpus",
        "limitnum": 8
      }
    },
    {
      "id": 13,
      "code": "1vCPU768MB20GB",
      "name": "Memory768MB,1vCPU,SSD20GB",
      "description": "<b>1</b> vCPU <br> <b>768 MB</b> RAM <br> <b>20 GB</b> SSD <br><b>100 </b> Mbps",
      "use_possible_date": "2022-03-27 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv6",
      "created_at": "2022-03-28 05:05:16",
      "updated_at": "2022-03-28 05:05:16",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 85,
        "plan_id": 13,
        "name": "1CR768MB",
        "param": "vcpus",
        "limitnum": 1
      }
    }
  ]
}
curl -s -X GET \
  'https://api.customer.jp/webarenaIndigo/v1/vm/getinstancespec?instanceTypeId=2&osId=22' \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "total": 0,
  "speclist": []
}

Windows2022の場合

curl -s -X GET \
  'https://api.customer.jp/webarenaIndigo/v1/vm/getinstancespec?instanceTypeId=1&osId=11' \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "total": 6,
  "speclist": [
    {
      "id": 7,
      "code": "2vCPU1GB50GB",
      "name": "Memory1GB,2vCPU,SSD50GB",
      "description": "<b>2</b> vCPU <br> <b>1 GB</b> RAM <br> <b>50 GB</b> SSD <br><b>100 </b> Mbps",
      "use_possible_date": "2020-10-14 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv4",
      "created_at": "2020-10-05 08:50:43",
      "updated_at": "2020-10-05 08:50:43",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 43,
        "plan_id": 7,
        "name": "2CR1GB",
        "param": "vcpus",
        "limitnum": 2
      }
    },
    {
      "id": 8,
      "code": "3vCPU2GB100GB",
      "name": "Memory2GB,3vCPU,SSD100GB",
      "description": "<b>3</b> vCPU <br> <b>2 GB</b> RAM <br> <b>100 GB</b> SSD <br><b>100 </b> Mbps",
      "use_possible_date": "2020-10-14 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv4",
      "created_at": "2020-10-05 08:50:44",
      "updated_at": "2020-10-05 08:50:44",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 50,
        "plan_id": 8,
        "name": "3CR2GB",
        "param": "vcpus",
        "limitnum": 3
      }
    },
    {                                                                                                                                                                                                                               [47/1845]
      "id": 9,
      "code": "4vCPU4GB200GB",
      "name": "Memory4GB,4vCPU,SSD200GB",
      "description": "<b>4</b> vCPU <br> <b>4 GB</b> RAM <br> <b>200 GB</b> SSD <br><b>500 </b> Mbps",
      "use_possible_date": "2020-10-14 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv4",
      "created_at": "2020-10-05 08:50:44",
      "updated_at": "2020-10-05 08:50:44",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 57,
        "plan_id": 9,
        "name": "4CR4GB",
        "param": "vcpus",
        "limitnum": 4
      }
    },
    {
      "id": 10,
      "code": "6vCPU8GB400GB",
      "name": "Memory8GB,6vCPU,SSD400GB",
      "description": "<b>6</b> vCPU <br> <b>8 GB</b> RAM <br> <b>400 GB</b> SSD <br><b>1000 </b> Mbps",
      "use_possible_date": "2020-10-14 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv4",
      "created_at": "2020-10-05 08:50:44",
      "updated_at": "2020-10-05 08:50:44",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 64,
        "plan_id": 10,
        "name": "6CR8GB",
        "param": "vcpus",
        "limitnum": 6
      }
    },
    {
      "id": 11,
      "code": "8vCPU16GB800GB",
      "name": "Memory16GB,8vCPU,SSD800GB",
      "description": "<b>8</b> vCPU <br> <b>16 GB</b> RAM <br> <b>800 GB</b> SSD <br><b>1000 </b> Mbps",
      "use_possible_date": "2020-10-14 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv4",
      "created_at": "2020-10-05 08:50:44",
      "updated_at": "2020-10-05 08:50:44",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 71,
        "plan_id": 11,
        "name": "8CR16GB",
        "param": "vcpus",
        "limitnum": 8
      }
    },
    {
      "id": 12,
      "code": "10vCPU32GB1600GB",
      "name": "Memory32GB,10vCPU,SSD1600GB",
      "description": "<b>10</b> vCPU <br> <b>32 GB</b> RAM <br> <b>1600 GB</b> SSD <br><b>1000 </b> Mbps",
      "use_possible_date": "2020-10-14 00:00:00",
      "instancetype_id": 1,
      "ipaddress_type": "ipv4",
      "created_at": "2020-10-05 08:50:45",
      "updated_at": "2020-10-05 08:50:45",
      "instance_type": {
        "id": 1,
        "name": "instance",
        "display_name": "KVM Instance",
        "created_at": "2019-10-09 13:11:20",
        "updated_at": "2019-10-09 13:11:20"
      },
      "kvm_resources": {
        "id": 78,
        "plan_id": 12,
        "name": "10CR32GB",
        "param": "vcpus",
        "limitnum": 10
      }
    }
  ]
}
curl -s -X GET \
  'https://api.customer.jp/webarenaIndigo/v1/vm/getinstancespec?instanceTypeId=2&osId=11' \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "total": 0,
  "speclist": []
}

インスタンス作成

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/vm/createinstance \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{
  "sshKeyId": 21633,
  "regionId": 1,
  "osId": 22,
  "instancePlan": 13,
  "instanceName": "APItest"
}' | jq .
{
  "success": true,
  "message": "Instance has been created successfully",
  "vms": {
    "id": 616513,
    "instance_name": "APItest",
    "set_no": 18,
    "vps_kind": "10",
    "sequence_id": 616513,
    "user_id": xxxx,
    "service_id": "idg-xxxx",
    "status": "READY",
    "sshkey_id": 21633,
    "snapshot_id": 0,
    "created_at": {
      "date": "2024-10-09 20:26:06.875022",
      "timezone_type": 3,
      "timezone": "UTC"
    },
    "host_id": 191,
    "plan_id": 13,
    "plan": "1CR768MB",
    "disk_point": 0,
    "memsize": 0.768,
    "cpus": 1,
    "os_id": 22,
    "otherstatus": 10,
    "uuid": null,
    "uidgid": 626513,
    "vnc_port": 0,
    "vnc_passwd": "xxxx",
    "arpaname": null,
    "arpadate": 0,
    "started_at": null,
    "closed_at": null,
    "vm_revert": 0,
    "ipaddress": null,
    "secondary_ip": null,
    "macaddress": null,
    "instancetype_id": 1,
    "import_instance": 0,
    "container_id": null,
    "daemonstatus": "",
    "outofstock": 0,
    "ipaddress_type": "ipv6"
  }
}

確認

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/vm/getinstancelist \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq '.[] | select(.id == 616513)'
{
  "id": 616513,
  "instance_name": "APItest",
  "set_no": 18,
  "vps_kind": 10,
  "sequence_id": 616513,
  "user_id": xxxx,
  "service_id": "idg-xxxx",
  "status": "OPEN",
  "sshkey_id": 21633,
  "snapshot_id": 0,
  "created_at": "2024-10-09 20:26:06",
  "host_id": 191,
  "plan_id": 13,
  "plan": "1CR768MB",
  "disk_point": 0,
  "memsize": 0.768,
  "cpus": 1,
  "os_id": 22,
  "otherstatus": 20,
  "uuid": "UUID",
  "uidgid": 626513,
  "vnc_port": 11191,
  "vnc_passwd": "xxxx",
  "arpaname": "IPv6アドレス.pro.static.arena.ne.",
  "arpadate": 1728505630,
  "started_at": "2024-10-09 20:27:10",
  "closed_at": null,
  "vm_revert": 0,
  "ipaddress": "IPv6アドレス",
  "secondary_ip": "",
  "macaddress": "MACアドレス",
  "instancetype_id": 1,
  "import_instance": 0,
  "container_id": null,
  "daemonstatus": "",
  "outofstock": 0,
  "ipaddress_type": "ipv6",
  "VEID": "18100000616513",
  "os": {
    "id": 22,
    "categoryid": 8,
    "code": "Debian",
    "name": "Debian12",
    "viewname": "Debian 12",
    "instancetype_id": 1
  },
  "ip": "IPv6アドレス",
  "instancecreatedbyuser": "____ ____ ",
  "regionname": "Tokyo",
  "instancestatus": "Stopped",
  "instancetype": {
    "id": 1,
    "name": "instance",
    "display_name": "KVM Instance",
    "created_at": "2019-10-09 13:11:20",
    "updated_at": "2019-10-09 13:11:20"
  }
}

作成後の状態(instancestatus) は Stopped なので、利用するには起動する必要がある。

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/vm/instance/statusupdate \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{"instanceId":"616513","status":"start"}' | jq .
{
  "success": true,
  "message": "Instance has started successfully ",
  "sucessCode": "I20008",
  "instanceStatus": "running"
}

起動したインスタンスの停止

WebARENA indigo では、停止状態でも動いているときと同様の課金となる。

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/vm/instance/statusupdate \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{"instanceId":"616513","status":"stop"}' | jq .
{
  "success": false,
  "message": "Shutdown of the instance is initiated. It will take few minutes to complete the shutdown process",
  "sucessCode": "I10025"
}

課金停止するには、インスタンスを削除(destroy)する必要がある。

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/vm/instance/statusupdate \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{"instanceId":"616513","status":"destroy"}' | jq .
{
  "success": true,
  "message": "Instance has been destroyed successfully",
  "sucessCode": "I20010",
  "instanceStatus": "shutoff"
}

なお、stop する前に destroy すると次のようにエラーになる。destroy する場合、その前に stop する必要がある。

{
  "success": false,
  "errorMessage": "Instance is in running status. Please stop the instance before destroying.",
  "errorCode": "I10055"
}

qcow2をインポートしてVPSインスタンス作成

以下のような感じで、起動することができるらしい。
(自分は起動に成功していないが)

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/vm/createinstance \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{
  "importUrl": "https://cloud.debian.org/images/cloud/bookworm/20241004-1890/debian-12-nocloud-ppc64el-20241004-1890.qcow2",
  "regionId": 1,
  "osId": 3,
  "instancePlan": 1,
  "instanceName": "ImportURLinstance"
}' | jq .
{
  "success": true,
  "message": "Instance has been created successfully",
  "vms": {
    "id": 618126,
    "instance_name": "ImportURLinstance",
    "set_no": 10,
    "vps_kind": "10",
    "sequence_id": 618126,
    "user_id": xxxx,
    "service_id": "idg-xxxx",
    "status": "READY",
    "sshkey_id": 0,
    "snapshot_id": 0,
    "created_at": {
      "date": "2024-10-11 20:16:33.939453",
      "timezone_type": 3,
      "timezone": "UTC"
    },
    "host_id": 6,
    "plan_id": 1,
    "plan": "1CR1GB",
    "disk_point": 0,
    "memsize": 1,
    "cpus": 1,
    "os_id": 3,
    "otherstatus": 10,
    "uuid": null,
    "uidgid": 628126,
    "vnc_port": 0,
    "vnc_passwd": "xxxx",
    "arpaname": null,
    "arpadate": 0,
    "started_at": null,
    "closed_at": null,
    "vm_revert": 0,
    "ipaddress": null,
    "secondary_ip": null,
    "macaddress": null,
    "instancetype_id": 1,
    "import_instance": 1,
    "container_id": null,
    "daemonstatus": "",
    "outofstock": 0,
    "ipaddress_type": "ipv46dual"
  }
}

在庫不足の時は以下のメッセージが表示される。

{
  "success": false,
  "errorMessage": "Out of stock.",
  "errorCode": "I10059"
}

以下のように、イメージファイルのダウンロードが始まる。

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/vm/getinstancelist \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq '.[] | select(.id == 618126 )'

  "instancestatus": "Disk image download in-progress (5% Completed)",

ダウンロードできない時、以下のようになる

  "instancestatus": "The URL entered is invalid.",

stop 状態で作成されるので start する。

自分はOS起動までできていない。
cloud-init の CDROMがマウントされないとかなんとか。
Webコンソールからアクセスしてログイン、IPアドレス設定をすればいいのではないかと考えている。

起動したインスタンスを stop で停止できない場合、forcestop で停止する。
停止できたら destroy で削除する。

FireWall

FW作成

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/nw/createfirewall \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{
    "name": "APItest",
    "inbound": [
        {"type": "HTTP", "protocol": "TCP","port":"80","source": "0.0.0.0"},
        {"type": "HTTPS", "protocol": "TCP","port":"443","source": "0.0.0.0"}
    ]
}' | jq .
{
  "success": true,
  "message": "Firewall template has been created successfully.",
  "sucessCode": "F60002",
  "firewallId": 12836
}

確認

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/nw/gettemplate/12836 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq '.[]'
[
  {
    "id": 12836,
    "name": "APItest",
    "direction": "in",
    "type": "HTTP",
    "protocol": "TCP",
    "port": "80",
    "source": "0.0.0.0"
  },
  {
    "id": 12836,
    "name": "APItest",
    "direction": "in",
    "type": "HTTPS",
    "protocol": "TCP",
    "port": "443",
    "source": "0.0.0.0"
  }
]

作成したFWをインスタンスに適用

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/nw/assign \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{
      "instanceid": "616516",
      "templateid": "12836"
}' | jq .
{
  "success": true,
  "message": "Firewall template is assigned successfully.",
  "sucessCode": "F60003"
}

FW設定変更

ここではルールを追加している。

curl -s -X PUT \
  https://api.customer.jp/webarenaIndigo/v1/nw/updatefirewall \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{
    "templateid": "12836",
    "name": "APItest",
    "inbound": [
        {"type": "HTTP", "protocol": "TCP", "port": "80", "source": "0.0.0.0"},
        {"type": "HTTPS", "protocol": "TCP", "port": "443", "source": "0.0.0.0"},
        {"type": "Custom", "protocol": "TCP", "port": "22", "source": "'$(curl -s https://ddns.techjunk.net/getaddress/ | jq -r .sourceip)'"}
    ],
    "instances":["616516"]
}' | jq .
{
  "success": true,
  "message": "Firewall template is updated successfully.",
  "sucessCode": "F6004",
  "firewallId": "12836"
}

結果確認

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/nw/gettemplate/12836 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
[
  {
    "id": 12836,
    "name": "APItest",
    "direction": "in",
    "type": "HTTP",
    "protocol": "TCP",
    "port": "80",
    "source": "0.0.0.0"
  },
  {
    "id": 12836,
    "name": "APItest",
    "direction": "in",
    "type": "HTTPS",
    "protocol": "TCP",
    "port": "443",
    "source": "0.0.0.0"
  },
  {
    "id": 12836,
    "name": "APItest",
    "direction": "in",
    "type": "Custom",
    "protocol": "TCP",
    "port": "22",
    "source": "220.146.61.235"
  }
]

FW削除

インスタンスの紐づけがあると、FW削除できない。
インスタンスの紐づけを外すか、紐づいているインスタンスを削除してからFWを削除する。
(インスタンスの紐づけを外すAPIが無いように思う)

curl -s -X DELETE \
  https://api.customer.jp/webarenaIndigo/v1/nw/deletefirewall/12836 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "success": true,
  "message": "Firewall template has been deleted successfully.",
  "sucessCode": "F6005"
}

インスタンスの紐づけがある状態で削除すると以下のエラーメッセージが出る。

{
  "success": false,
  "errorMessage": "This firewall template has already been assigned to an active instance.",
  "errorCode": "F60009"
}

スナップショット

スナップショット一覧

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/disk/snapshotlist/616516 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
[]

スナップショット取得

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/disk/takesnapshot \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{"name":"APItest", "instanceid":616516, "slotnum":"0"}' | jq .
{
  "STATUS": 0
}

結果確認。

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/disk/snapshotlist/616516 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
[
  {
    "id": 12089,
    "name": "APItest",
    "service_id": "idg-xxxx",
    "user_id": "xxxx",
    "disk_id": xxxx,
    "volume": 12,
    "slot_number": 0,
    "status": "running",
    "size": "",
    "deleted": 0,
    "completed_timestamp": "0000-00-00 00:00:00",
    "deleted_timestamp": "0000-00-00 00:00:00"
  }
]

保存が完了すると、status が running から created へ遷移する。

[
  {
    "id": 12089,
    "name": "APItest",
    "service_id": "idg-xxxx",
    "user_id": "xxxx",
    "disk_id": xxxx,
    "volume": 12,
    "slot_number": 0,
    "status": "created",
    "size": "1071529984",
    "deleted": 0,
    "completed_timestamp": "2024-10-09 22:48:52",
    "deleted_timestamp": "0000-00-00 00:00:00"
  }
]

スナップショットからの戻し

最初にインスタンスを停止する

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/vm/instance/statusupdate \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{"instanceId":"616516","status":"stop"}' | jq .
{
  "success": false,
  "message": "Shutdown of the instance is initiated. It will take few minutes to complete the shutdown process",
  "sucessCode": "I10025"
}

止まったことを確認

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/vm/getinstancelist \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq '.[] | select(.id == 616516 ) | .instancestatus'
"Stopped"

戻し実行。戻したらインスタンスを start する。

curl -s -X POST \
  https://api.customer.jp/webarenaIndigo/v1/disk/restoresnapshot \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' \
  -d '{"instanceid":"616516", "snapshotid":"12089"}' | jq .
{
  "STATUS": 0
}

参考までに、インスタンスを止めずに戻すと、以下のエラーになる。

{
  "success": false,
  "errorMessage": "Please turn-off Instance before restoring a snapshot",
  "errorCode": "S10002"
}

スナップショット削除

削除

curl -s -X DELETE \
  https://api.customer.jp/webarenaIndigo/v1/disk/deletesnapshot/12089 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
{
  "STATUS": 0
}

確認

curl -s -X GET \
  https://api.customer.jp/webarenaIndigo/v1/disk/snapshotlist/616516 \
  -H 'Authorization: Bearer '$(jq -r ".accessToken" tmp)'' | jq .
[]

まとめ的ななにか

自分が書いたスクリプトが動かなくなったので、改めて確認してみたかったのが、この投稿を作った背景。

自宅のルータの動的IPアドレスが変更された時のFWルール変更の自動化とか、疎通がおかしくなったら自動的にOS再起動とか、いろいろ便利に使えると思う。
自動化せずともスクリプト化しておけば、わざわざブラウザ開いてログインしてコンパネ開いてメニュー辿って操作しなくてもいいので、便利なのではなかろうか。

GitHubで編集を提案

Discussion