Now that we have created a Cinder volume service, we can now create volumes for use by our instances. We do this under our client environment using the Python-OpenStack client with the python-cinderclient
library; so we are creating volumes specific to our project (tenant).
Refer to Chapter 2, The OpenStack Client, for more information on installing and configuring the OpenStack client.
To create a volume, the following is required:
openstack
command line clientopenrc
file with appropriate credentials for the environmentFor our example, these are the following:
cookbook.volume
Carry out the following steps to create a volume:
We simply create the volume that we will attach to our instance with the following command:
openstack volume create --size 10 --description "Cookbook Volume" cookbook.volume
On completion, the command returns the following output:
Creating volumes is very straightforward. Using the openstack
client, we supply the volume
context and the create
action with the following syntax:
openstack volume create --size size_GiB --description "meaningful description" volume_name
Here, volume_name
can be any arbitrary name with no spaces.
As we are using a server that runs the cinder-volume
service, we can see the actual LVM volumes on cinder-volumes
, using the usual LVM tools, as follows (ensure that you are logged in as root
on the server we specified as storage host):
lvdisplay cinder-volumes --- Logical volume --- LV Path /dev/cinder-volumes/volume-bb7a7d2c-8069-4924-a18e-8fb398584a5d LV Name volume-bb7a7d2c-8069-4924-a18e-8fb398584a5d VG Name cinder-volumes LV UUID XqZY27-Ei32-EEdC-3UtE-MR6e-2EKw-XCvIGt LV Write Access read/write LV Creation host, time cinder-volume, 2017-09-22 20:25:17 +0000 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:2
By default, Cinder volumes operate like a physical disk, insofar as they can only be attached to one instance at a time. However, for workloads that require a disk be shared between instances, you can pass the --multi-attach
flag when creating the volume to enable the volume to be attached to more than once instance:
openstack volume create --multi-attach --description "description" --size size_GiB volume_name
A word of warning
This feature is quite new and considered experimental for production environments, and is not a replacement for a shared storage service such as NFS. NFS supports locking that allows multiple clients to read and write to the same mount point. Multi-attach block storage does not support locking. Therefore, a valid use case could be a scenario where a master/slave service is employed and where the data should only be written to by only one instance at a time, but there is a benefit to having the data immediately available on failover.
18.119.167.87