Score:0

OpenStack creation and attachment of volumes

vn flag

I am trying to create and attach a volume with:

openstack volume create ... VOLUME_NAME

and

openstack server add volume ...

But I am having two problems:

  • The volume is always created, and I would like to prevent the creation if VOLUME_NAME already exists.
  • 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.

Is there a way to create volumes only if the name does not already exist? Is there a way to specify the specific device in the instance for the attachment?

Score:1
pt flag

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
user1156544 avatar
vn flag
This is helpful, thanks. For the attach, I do it by name as you say. But my script needs to open an encrypted volume, so I need to specify explicitly the `/dev/sdX` device. The problem is that I cannot predict the name because depending on how many times a volume was attached and detach I get a different letter...
pt flag
Why do you need to specify the explicit `/dev/sdX` device? The `/dev/disk/by-id` path points to the equivalent device and can be used interchangeably.
user1156544 avatar
vn flag
It gets more complicated, but I guess it is the way to go. Is there an easy command for my script to collect these `first 20 characters of the id`?
pt flag
If you're using bash and you have the UUID in a variable, you can ask for `${variable:0:20}`.
user1156544 avatar
vn flag
Sorry for the confusion, I meant the ID. But I got it with -c and -f
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.