Skip to content

Commit

Permalink
add docs for volume attachement
Browse files Browse the repository at this point in the history
  • Loading branch information
k0ka committed Feb 5, 2024
1 parent c32ab23 commit 23ebc23
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
1 change: 1 addition & 0 deletions doc/services/compute/v2/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ OpenStack Compute (Nova) API Version 2. Nova is the OpenStack project that provi

create
servers
volume-attachments
flavors
images
states
38 changes: 38 additions & 0 deletions doc/services/compute/v2/volume-attachments.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Volume Attachments
==================

Nova allows you to attach a volume to a server on the fly. This model represents a point of attachment between a server and a volume.

.. osdoc:: https://docs.openstack.org/api-ref/compute/#servers-with-volume-attachments-servers-os-volume-attachments

.. |models| replace:: volume attachments

.. include:: /common/service.rst

.. warning::

The server must be fully started before you can attach a volume to it. Just because the server is in the ``ACTIVE``
state does not mean that it is ready to accept a volume attachment. See `https://bugs.launchpad.net/nova/+bug/1960346`_
and `https://bugs.launchpad.net/nova/+bug/1998148`_ for more information.

Create
------

To attach a volume to a server, you need to know the server ID and the volume ID.

.. sample:: Compute/v2/volume_attachments/create.php


Delete
------

To detach a volume from a server, you need to know the server ID and the volume ID.

.. sample:: Compute/v2/volume_attachments/delete.php

List
----

.. sample:: Compute/v2/volume_attachments/list.php

.. include:: /common/generators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
'id' => '{userId}',
'password' => '{password}'
],
'scope' => ['project' => ['id' => '{projectId}']]
]);

$compute = $openstack->computeV2(['region' => '{region}']);

$compute = $openstack->computeV2();
$server = $compute->getServer(['id' => '{serverId}']);

$volumeAttachment = $server->attachVolume('{volumeId}');
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
'id' => '{userId}',
'password' => '{password}'
],
'scope' => ['project' => ['id' => '{projectId}']]
]);

$compute = $openstack->computeV2(['region' => '{region}']);
$compute = $openstack->computeV2();
$server = $compute->getServer();

/**@var OpenStack\Compute\v2\Models\Server $server */
$server = $compute->getServer(['id' => '{serverId}']);

//Must detach by volumeAttachment id
$server->detachVolume('{volumeAttachmentId}');
$server->detachVolume('{volumeId}');
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
'id' => '{userId}',
'password' => '{password}',
],
'scope' => ['project' => ['id' => '{projectId}']],
]);

$compute = $openstack->computeV2(['region' => '{region}']);

$compute = $openstack->computeV2();
$server = $compute->getServer(['id' => '{serverId}']);

foreach ($server->listVolumeAttachments() as $volumeAttachment) {
Expand Down
12 changes: 6 additions & 6 deletions tests/sample/Compute/v2/VolumeAttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testAttach(): VolumeAttachment
$this->assertEquals('available', $volume->status);

/** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */
require_once $this->sampleFile('servers/attach_volume_attachment.php', [
require_once $this->sampleFile('volume_attachments/create.php', [
'{serverId}' => $server->id,
'{volumeId}' => $volume->id,
]);
Expand All @@ -47,12 +47,12 @@ public function testList(VolumeAttachment $createdVolumeAttachment)
{
$found = false;
require_once $this->sampleFile(
'servers/list_volume_attachments.php',
'volume_attachments/list.php',
[
'{serverId}' => $createdVolumeAttachment->serverId,
'/** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */' => <<<'PHP'
/** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */
if ($volumeAttachment->id === $createdVolumeAttachment->id) {
if ($volumeAttachment->volumeId === $createdVolumeAttachment->volumeId) {
$found = true;
}
PHP
Expand All @@ -73,10 +73,10 @@ public function testDetach(VolumeAttachment $createdVolumeAttachment)
sleep(15);

require_once $this->sampleFile(
'servers/detach_volume_attachment.php',
'volume_attachments/delete.php',
[
'{serverId}' => $createdVolumeAttachment->serverId,
'{volumeAttachmentId}' => $createdVolumeAttachment->id,
'{serverId}' => $createdVolumeAttachment->serverId,
'{volumeId}' => $createdVolumeAttachment->volumeId,
]
);

Expand Down

0 comments on commit 23ebc23

Please sign in to comment.