Hello everybody!
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04 LTS"
$ lxd --version
5.15
$ lxc ls test --fast
+-----------------------+---------+--------------+----------------------+-------------+-----------------+
| NAME | STATE | ARCHITECTURE | CREATED AT | PROFILES | TYPE |
+-----------------------+---------+--------------+----------------------+-------------+-----------------+
| test | STOPPED | x86_64 | 2023/08/15 04:56 UTC | default | CONTAINER |
$ INSTANCE_NAME=test && HOST_NAME='--unix-socket /var/snap/lxd/common/lxd/unix.socket' && OPERATION=`curl -s ${HOST_NAME} a/1.0/instances/${INSTANCE_NAME}/state -X PUT -d '{"action": "stop"}' | jq -r '.operation'` && echo ${OPERATION} && curl -s ${HOST_NAME} a${OPERATION} | jq
{
"type": "sync",
"status": "Success",
"status_code": 200,
"operation": "",
"error_code": 0,
"error": "",
"metadata": {
"id": "2261fc7b-e031-4c09-b577-e13b7ecab256",
"class": "task",
"description": "Stopping instance",
"created_at": "2023-08-15T14:15:55.082270524+07:00",
"updated_at": "2023-08-15T14:15:55.082270524+07:00",
"status": "Failure",
"status_code": 400,
"resources": {
"instances": [
"/1.0/instances/test"
]
},
"metadata": null,
"may_cancel": false,
"err": "The instance is already stopped",
"location": "ironman"
}
}
If we want to wait for the operation to complete, there will be an error
$ INSTANCE_NAME=test && HOST_NAME='--unix-socket /var/snap/lxd/common/lxd/unix.socket' && OPERATION=`curl -s ${HOST_NAME} a/1.0/instances/${INSTANCE_NAME}/state -X PUT -d '{"action": "stop"}' | jq -r '.operation'` && echo ${OPERATION} && curl -s ${HOST_NAME} a${OPERATION}/wait | jq
{
"type": "error",
"status": "",
"status_code": 0,
"operation": "",
"error_code": 500,
"error": "The instance is already stopped",
"metadata": null
}
Previously, the answer was the same with and without wait, but now code 500 has broken the logic of my application.
Any comments, please.