The volume is always created, and I would like to prevent the creation if VOLUME_NAME already exists.
Volume names are not unique; they are primarily informational. If you want to avoid creating multiple volumes with the same name, then you must check if the volume exists first:
openstack volume show testvolume >& /dev/null ||
openstack volume create testvolume --size 1
The volume is attached in the machine under a sequential device. So, the first time, it is attached in /dev/sdb. If I detach and attach again, it is in /dev/sdc and so on. I have tried to use --device but apparently it does not work like this.
You shouldn't be relying on the device name when interacting with disk devices in your virtual machines. Your can identify your volume by it's id; look in the path /dev/disk/by-id
and you should find a device virtio-<first 20 characters of the id>
. So if I have:
$ openstack volume list
+--------------------------------------+------------------+-----------+------+----------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+------------------+-----------+------+----------------------------------+
| b53f67ae-bf74-41ee-879d-a16eea110395 | vol1 | available | 2 | |
| 8c584c0b-5c85-4c5d-afc6-283afe0abed3 | vol0 | available | 2 | |
+--------------------------------------+------------------+-----------+------+----------------------------------+
And I attach volume vol1
to my server voltest
:
$ openstack server add volume voltest vol1
I will find:
root@voltest:~# ls -lL /dev/disk/by-id
total 0
brw-rw---- 1 root disk 252, 16 Nov 10 18:55 virtio-b53f67ae-bf74-41ee-8