lxc/linuxcontainers.org

Add instructions to delete all the instances

kranurag7 opened this issue · 1 comments

After reading https://linuxcontainers.org/incus/docs/main/howto/instances_manage/

I used the following command to delete all the running instances.

incus ls -f csv | awk -F , '{print $1}' | xargs -n 1 incus delete --force

I think it would be great if we have a way to delete all the instance in one go and that is documented on the page mentioned above. As of now, I was not able to find it in the documentation.

Happy to send a patch for this if I can find the recommended way to delete all the instances in one go.

EDIT:
I think using jq and xargs in combination is easier.

~ $ incus launch images:ubuntu/24.04 tommy --vm
Launching tommy
~ $ incus launch images:ubuntu/24.04 foo --vm
Launching foo
~ $ incus launch images:ubuntu/24.04 bar --vm
Launching bar
~ $ incus list
+-------+---------+-------------------------+-------------------------------------------------+-----------------+-----------+
| NAME  |  STATE  |          IPV4           |                      IPV6                       |      TYPE       | SNAPSHOTS |
+-------+---------+-------------------------+-------------------------------------------------+-----------------+-----------+
| bar   | RUNNING |                         | fd42:84ba:ba59:a466:216:3eff:fe52:fab (eth0)    | VIRTUAL-MACHINE | 0         |
+-------+---------+-------------------------+-------------------------------------------------+-----------------+-----------+
| foo   | RUNNING | 10.152.227.111 (enp5s0) |                                                 | VIRTUAL-MACHINE | 0         |
+-------+---------+-------------------------+-------------------------------------------------+-----------------+-----------+
| tommy | RUNNING | 10.152.227.209 (enp5s0) | fd42:84ba:ba59:a466:216:3eff:feab:d83a (enp5s0) | VIRTUAL-MACHINE | 0         |
+-------+---------+-------------------------+-------------------------------------------------+-----------------+-----------+
~ $ incus list -f json |  jq .[].name -r | xargs -n1 incus delete --force
~ $ incus list
+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+

We've avoided doing that on purpose as when we did back in the LXD days we had to deal with a bunch of folks who copy pasted the wrong command and lost all their company's data.

That's also why we never implemented a --all flag to the delete command despite most other commands having it.

These days the problem is even worse as LLMs have that annoying property of very confidently giving users the wrong instructions, making it likely that if we were to document this, even with big warnings, some future version of ChatGPT will still end up providing that command for something completely unrelated.