Detaching volumes from an instance

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.

Getting ready

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

How to do it...

To detach a volume using Nova client, carry out the following steps:

  1. First, we identify the volumes attached to running instances by running the following command:
    nova volume-list
    

    This returns the following output:

    How to do it...
  2. On the instance that has the volume mounted, we must first unmount it with the following command (if using the earlier example, this is on /mnt1):
    sudo unmount /mnt1
    
  3. Back on the Ubuntu client, where Nova client is installed, we can now detach this volume with the following command:
    nova volume-detach <instance_id> <volume_id>
    

Now we can attach this to another running instance and the data will be preserved.

How it works...

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.

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

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