8af7b47812
We had the clouds split from back when we used the openstack dynamic inventory plugin. We don't use that anymore, so we don't need these to be split. Any other usage we have directly references a cloud. Change-Id: I5d95bf910fb8e2cbca64f92c6ad4acd3aaeed1a3
27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
# Tool to clean up leaked Boot-From-Volume Volumes
|
|
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'])))
|