Ask Your Question
0

How to delete multiple instances ( bulk delete ) via curl or cli ?

asked 2014-09-18 09:04:19 -0600

neerbeer gravatar image

I've been doing testing and spinning up 100s of VMs via nova boot and through horizon.

Is there an way to do a bulk delete of multiple VMs ?

'nova delete $id ' only acts on one VM at a time. And horizon only allows 20 or so deletes at a time and I'd like to know how to do this without having to increase the horizon variable that will show 100 VMs per page.

AHA ( any help apprec )

Thank

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2014-09-18 10:58:01 -0600

larsks gravatar image

This is more correct (and possibly faster, since it doesn't rely on a for loop):

nova list | awk '$2 && $2 != "ID" {print $2}' | xargs -n1 nova delete

In particular, the solution from dbxs uses the "name" field. If there are multiple instances with the same name, the "nova delete" operation will fali with:

Multiple server matches found for 'c0', use an ID to be more specific.
ERROR: Unable to delete any of the specified servers.
edit flag offensive delete link more
0

answered 2016-08-23 18:30:13 -0600

If using the unified openstack client you can do:

openstack server list -c ID -f value | xargs -n1 openstack server delete

edit flag offensive delete link more
0

answered 2014-09-18 09:27:01 -0600

dbaxps gravatar image

updated 2014-09-18 11:13:10 -0600

[root@icehouse1 ~(keystone_boris)]# cat ./test01
for V in `nova list | awk '{print $4}' | grep -v ^N | grep -v ^$`
do
echo $V ;
nova delete $V ;
done

Another version ( fixed per notice larsks)

[root@icehouse1 ~(keystone_boris)]# cat ./test01
for V in `nova list | awk '{print $2}' | grep -v ^ID | grep -v ^$`
do
echo $V ;
nova delete $V;
done
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

Stats

Asked: 2014-09-18 09:04:19 -0600

Seen: 4,371 times

Last updated: Aug 23 '16