In this guide I show how to forcibly delete volumes that cannot be deleted on OpenStack
First of all the first thing you need to do is list all the volumes
openstack volume list
+--------------------------------------+---------+-----------+------+--------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+---------+-----------+------+--------------+
| e0cdbe70-4735-4d48-b22d-60ad5d4072da | volume1 | available | 8 | |
| 7147e283-1769-4c6b-9121-489ebbfe8afa | volume2 | available | 8 | |
+--------------------------------------+---------+-----------+------+--------------+
Good, now take note of the IDs of the volumes you are unable to delete, copy all the IDs
Now we will also need to see your project ID with the undeletable volumes
openstack project list
+----------------------------------+---------+
| ID | Name |
+----------------------------------+---------+
| 4134113820564e62a4688466a016b078 | demo |
| 63410375f6704524a10c9fd9233bf8ac | service |
| 7525837924d04556acde939f0922fd01 | admin |
| a8cb8e03d0e14f0990c45d5a6fce7e16 | stef |
+----------------------------------+---------+
And now copy your project ID
And lastly now check the status of the cinder volume which is in error_deleting or Detaching and restore the available status with:
cinder reset-state –state available volumeid
You can skip this step if the above command fails
Well, now that you have all the IDs you need we can proceed to delete the volumes from the MySQL database
first of all enter the MySQL shell
mysql
Now enter the cinder's database
MariaDB [(none)]> use cinder;
Now that you're inside the database, and now enter these four fairly complex commands
MariaDB [cinder]> update volumes set attach_status='detached',status='available' where id ='volumeid';
MariaDB [cinder]> update volumes set deleted=1,status='deleted',deleted_at=now(),updated_at=now() where deleted=0 and id='volumeid';
Obviously replace volumeid with the ID of the volume you want to forcibly delete
Finally we modify the quota usage value to the number of volumes remaining before deleting the non-deletable ones (i.e. all those that have not been deleted)
MariaDB [cinder]> update quota_usages set in_use=remainedvolumes where (project_id='projectid'&&resource='volumes');
MariaDB [cinder]> update quota_usages set in_use=remainedgigabytes where (project_id='projectid'&&resource='gigabytes');
Replace remaining gigabytes with the number of GB that are left over from other existing volumes, if you have not left 0
Replace remainedvolumes with the number of volumes you still have and projectid with your previously obtained project ID
(If you have deleted all the volumes, the value can be set to 0)
(Always remember to run this last command, because otherwise Cinder thinks those volumes are still there when in fact they no longer exist)
Well and that's all now you can go back to the OpenStack Dashboard, and see that the quota is set correctly and the undeletable volumes will be gone