As Cinder volumes can only be attached to one host at a time, you need to detach it from one instance before attaching it to another. To detach a volume, we use another Nova client option called volume-detach
.
To begin with, ensure you are logged in to the Ubuntu host that has access to Nova client tools. If using the Vagrant environment that accompanies the book, you can access these tools from the controller
node:
vagrant ssh controller
This recipe assumes you have created an openrc
file. To create an openrc
file on each node where you need it, open a text file named openrc
, and add the following contents:
export OS_TENANT_NAME=cookbook export OS_USERNAME=admin export OS_PASSWORD=openstack export OS_AUTH_URL=https://192.168.100.200:5000/v2.0/ export OS_KEY=/path/to/cakey.pem export OS_CACERT=/path/to/ca.pem
These packages can be installed using the following commands:
sudo apt-get update sudo apt-get install python-novaclient
To detach a volume using Nova client, carry out the following steps:
nova volume-list
This returns the following output:
unmount
it with the following command (if using the earlier example, this is on /mnt1
):sudo unmount /mnt1
nova volume-detach <instance_id> <volume_id>
Now we can attach this to another running instance and the data will be preserved.
Detaching Cinder volumes is no different from removing a USB stick from a computer. We first unmount the volume from our running instance. Then we detach the volume from the running instance using nova volume-detach
from the Nova Client.
The nova volume-detach
command has the following syntax:
nova volume-detach instance_id volume_id
The instance_id
parameter is the ID from the attached to
column returned from the nova volume-list
command, and this notifies which ID we want to detach the volume from.
The volume_id
parameter is the ID listed in the ID column from the nova volume-list
command.