Lxc delete --all

We have lxc stop --all, why not lxc delete --all ?

As you can imagine, “lxd delete --all” would allow an individual to delete ALL containers with one command. I know I would have used it a couple of times but it could be dangerous as well. Here is a script. I am assuming basic scripting and Linux command knowledge.

At command prompt:
touch lxcdelall.sh
chmod +x lxcdelall.sh
lxcdelall.sh

#--------------------------------
#!/bin/bash
arContainers=(lxc list -c n -f compact)
#Remove first element of array
unset ‘arContainers[0]’

read -p “Are you sure you want to delete ALL containers (Y/N):” reply
if [ ${reply} == “Y” ] || [ ${reply} == “Y” ]; then
#User confirmed deletion of ALL Containers!
for container in ${arContainers[*]}; do
echo “Deleting ${container}…”

  #Uncomment the following lines
  #lxc stop ${container} --force
  #lcx delete ${container} --force

done
echo “Delete ALL Containers complete…”
else
echo “Deletion process aborted…”
exit 1
fi

exit 0
#--------------------------------

To execute ./lxcdelall.sh

Hope this helps…

If you really must, you can do lxc list -fcsv -cn | xargs lxc delete -f, but we figured that adding a bulk deletion API and CLI would likely make it a bit too easy to cause massive data loss.

For start/stop/restart/… we use PUT /1.0/instances, if we were to implement DELETE /1.0/instances in the same vain, it would just take a tiny typo, say someone wanting to do GET /1.0/instances to wipe everything they have on the system…

3 Likes