Deleting volumes

At some point, you will no longer need the volumes you have created. To remove the volumes from the system permanently, so they are no longer available, we simply pull out another tool from the OpenStack client, the volume delete option.

Getting ready

To delete a volume, you will need the following:

  • The openstack command-line client
  • An openrc file with appropriate credentials for the environment
  • The name or ID of the volume to delete

For our example, these values are as follows:

  • Volume: cookbook.volume

Tip

Warning: This will remove the volume and any data stored on it, so ensure that this is the correct action you want to perform before continuing.

You can only delete a volume that isn't currently attached to an instance.

How to do it…

To delete a volume using the OpenStack client, carry out the following steps:

  1. First, we list the volumes available to identify the volume we want to delete, with the following command:
    openstack volume list
    

    This shows that the volume is available and not attached to any instance:

    How to do it…
  2. We will now use the volume name or ID to delete this from the system, with the following command:
    openstack volume delete cookbook.volume
    

    Tip

    This command produces no output when successful.

    As with attaching and detaching volumes, an ID or name can be used. Best practice is to use the ID to avoid any discrepancies and delete the wrong volume.

How it works…

How the actual volume is deleted depends largely on the Cinder volume driver. In the Configuring Cinder volume services recipe of this chapter, we used cinder.volume.drivers.lvm.LVMVolumeDriver. In this case, deleting images removes the LVM volume from use within our system.

There's more…

OpenStack Cinder volumes can be snapshotted, in which case, the openstack volume delete command will produce an error message like the following:

Invalid volume: Volume status must be available or error or error_restoring or error_extending or error_managing and must not be migrating, attached, belong to a group, have snapshots or be disassociated from snapshots after volume transfer. (HTTP 400) (Request-ID: req-2b82e7fc-0cb4-403f-8dd8-35d99a0f6c6c)

To delete a volume, and all of its snapshots, pass the --purge flag to the openstack volume delete command.

Tip

Be careful with this. It is a one-way operation, and openstack volume delete does not prompt for confirmation. Additionally, the command produces no output when successful.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.58.122