Cmd Execution
デバイスに対して任意のコマンドを実行し、実行結果を取得するAPIです。コマンドの実行を開始するとexec_id
と呼ばれるIDが生成され、デバイスと共有されます。その後はexec_id
を指定してコマンドの実行結果を取得することが可能です。
コマンド実行データのstatus
パラメータには、現在のコマンドの実行状態が保存されています。status
は以下の3つの値を取ることができます。
executing
: クライアントにコマンドを送信中・またはクライアントでの実行待ちです。
executed
: コマンドの実行が完了し、結果が保存されている状態です。
error
: 何らかのエラーが発生し、コマンドの実行自体が行えなかった状態です。最もよくあるのはデバイスが未接続の際にAPIをリクエストした時です。
またデバイスで実行されたコマンドが異常終了した場合はstatus=executed
となります。
指定したデバイスに対してコマンドの実行をリクエストします。
POST https://api.legs.iij.jp/api/devices/{device_id}/cmd_exec?token=api-token
Parameters
type |
parameter |
require |
example |
description |
path |
device_id |
yes |
02fcd662-5113-53d8-a118-747e81b99d03 |
デバイスID |
query |
token |
yes |
api-token |
API Token |
Request Body
{
"command": "uname -a"
}
Response Body 201
show example
{
"id": "CKP02THB8Rue6xTc",
"device_id": "02fcd662-5113-53d8-a118-747e81b99d03",
"account_id": 1,
"status": "executing",
"command": "uname -a",
"result": "",
"requested_at": "2018-08-06T10:36:05.858365263Z",
"executed_at": "0001-01-01T00:00:00Z"
}
過去のコマンド実行結果をリストで取得します。取得時にページ数の指定が可能です。
GET https://api.legs.iij.jp/api/devices/{device_id}/cmd_exec?token=api-token&page=1&per_page=10
Parameters
type |
parameter |
require |
example |
description |
path |
device_id |
yes |
02fcd662-5113-53d8-a118-747e81b99d03 |
デバイスID |
query |
token |
yes |
api-token |
API Token |
query |
page |
no |
1 |
ページ数の指定。デフォルト: 1 |
query |
per_page |
no |
10 |
1ページあたりの表示数。デフォルト: 20 |
Response Body 200
show example
{
current_page: 1,
max_page: 3,
per_page: 20,
records: [
{
"id": "B9gZZoRcGlM2",
"device_id": "02fcd662-5113-53d8-a118-747e81b99d03",
"account_id": 14,
"status": "executed",
"command": "uname -a",
"result": "Linux work.localdomain 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux\n",
"requested_at": "2018-12-27T12:53:50.764087789Z",
"executed_at": "2018-12-27T12:53:50.768238832Z",
},
{
"id": "oVCM48juCJzZ",
"device_id": "02fcd662-5113-53d8-a118-747e81b99d03",
"account_id": 14,
"status": "executed",
"command": "uname",
"result": "Linux\n",
"requested_at": "2018-12-27T12:53:49.087378915Z",
"executed_at": "2018-12-27T12:53:49.097921033Z",
},
...
]
}
`exec_id` を指定して特定のコマンド実行結果を取得します。
GET https://api.legs.iij.jp/api/devices/{device_id}/cmd_exec/{exec_id}?token=api-token
Parameters
type |
parameter |
require |
example |
description |
path |
device_id |
yes |
02fcd662-5113-53d8-a118-747e81b99d03 |
デバイスID |
path |
exec_id |
yes |
CKP02THB8Rue6xTc |
exec_id |
query |
token |
yes |
api-token |
API Token |
Response Body 200
show example
{
"id": "CKP02THB8Rue6xTc",
"device_id": "02fcd662-5113-53d8-a118-747e81b99d03",
"account_id": 1,
"status": "executed",
"command": "uname -a",
"result": "Linux raspberrypi 4.14.52-v7+ #1123 SMP Wed Jun 27 17:35:49 BST 2018 armv7l GNU/Linux\n",
"requested_at": "2018-08-06T10:36:05.858365263Z",
"executed_at": "2018-08-06T10:36:05.498746277Z"
}