Now that we have a usable volume, we can attach this to any instance. We do this by using the nova volume-attach
command in the Nova client.
To begin with, ensure you are logged in to the Ubuntu client that has access to the Nova client tools. If using the Vagrant environment that accompanies the book, you can access these tools from the controller
node by running this command:
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
Carry out the following steps to attach a volume to an instance using the Nova client:
nova list
command and note the instance ID:source openrc nova list --fields name
The following output is generated:
+--------------------------------------+-------+ | ID | Name | +--------------------------------------+-------+ | f9659289-82f1-435f-98fc-add99c7a611b | test1 | +--------------------------------------+-------+
nova volume-attach <instance_id> <volume_id> /dev/vdc
sudo fdisk -l /dev/vdc
sudo mkfs.ext4 /dev/vdc sudo mkdir /mnt1 sudo mount /dev/vdc /mnt1
/mnt1
, as shown here:df -h Filesystem Size Used Avail Use% Mounted on /dev/vda 1.4G 602M 733M 46% / devtmpfs 248M 12K 248M 1% /dev none 50M 216K 50M 1% /run none 5.0M 0 5.0M 0% /run/lock none 248M 0 248M 0% /run/shm /dev/vdb 5.0G 204M 4.6G 5% /mnt /dev/vdc 1.0G 204M 784M 5% /mnt1
Attaching a Cinder volume is no different from plugging in a USB stick on your own computer; similar to a USB stick, a Cinder volume can only be attached to a single host and must be formatted and mounted.
Under Nova client, the option volume-attach
takes the following syntax:
nova volume-attach instance_id volume_id device
The instance_id
parameter is the ID returned from the Nova list for the instance that we want to attach the volume to. The volume_id
is the name of the device within the instance that we will use to mount the volume that can be retrieved using the nova volume-list
. This device is the device that will be created on our instance that we use to mount the volume.