Add quick script for cleaning boot from volume leaks
Sometimes we leak boot from volume volumes. This will clean them up. Change-Id: I45182c1dcad0cdcbc327aaef3a63d37947f8a66d
This commit is contained in:
parent
f30b39c769
commit
2aebe4e09f
28
tools/clean-leaked-bfv.py
Normal file
28
tools/clean-leaked-bfv.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Tool to clean up leaked Boot-From-Volume Volumes
|
||||||
|
# Run this with:
|
||||||
|
# OS_CLIENT_CONFIG_FILE=/etc/openstack/all-clouds.yaml python3 clean-volumes.py
|
||||||
|
from openstack import connection
|
||||||
|
import openstack
|
||||||
|
import datetime
|
||||||
|
import sys
|
||||||
|
# openstack.enable_logging(http_debug=True)
|
||||||
|
|
||||||
|
c = openstack.connect(cloud='openstackjenkins-vexxhost', region_name='sjc1')
|
||||||
|
now = datetime.datetime.utcnow()
|
||||||
|
|
||||||
|
server_ids = [s.id for s in c.list_servers()]
|
||||||
|
for vol in c.list_volumes():
|
||||||
|
vol_age = datetime.datetime.strptime(vol['created_at'][:19], '%Y-%m-%dT%H:%M:%S') - now
|
||||||
|
if (vol.size == 80
|
||||||
|
and vol_age.seconds > 3600
|
||||||
|
and vol.attachments
|
||||||
|
and vol.attachments[0]['server_id'] not in server_ids):
|
||||||
|
att = vol.attachments[0]
|
||||||
|
print('DELETE /attachments/{attachment} for {server}'.format(
|
||||||
|
server=att['server_id'],
|
||||||
|
attachment=att['attachment_id']))
|
||||||
|
print(c.block_storage.delete(
|
||||||
|
'/attachments/{attachment}'.format(attachment=att['attachment_id']),
|
||||||
|
microversion='3.31'))
|
||||||
|
print('DELETE volume {vol}'.format(vol=att['volume_id']))
|
||||||
|
print(c.delete_volume(dict(id=att['volume_id'])))
|
Loading…
Reference in New Issue
Block a user