Skip to content

Commit 23ebc23

Browse files
committed
add docs for volume attachement
1 parent c32ab23 commit 23ebc23

File tree

6 files changed

+50
-19
lines changed

6 files changed

+50
-19
lines changed

doc/services/compute/v2/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ OpenStack Compute (Nova) API Version 2. Nova is the OpenStack project that provi
1111

1212
create
1313
servers
14+
volume-attachments
1415
flavors
1516
images
1617
states
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Volume Attachments
2+
==================
3+
4+
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.
5+
6+
.. osdoc:: https://docs.openstack.org/api-ref/compute/#servers-with-volume-attachments-servers-os-volume-attachments
7+
8+
.. |models| replace:: volume attachments
9+
10+
.. include:: /common/service.rst
11+
12+
.. warning::
13+
14+
The server must be fully started before you can attach a volume to it. Just because the server is in the ``ACTIVE``
15+
state does not mean that it is ready to accept a volume attachment. See `https://bugs.launchpad.net/nova/+bug/1960346`_
16+
and `https://bugs.launchpad.net/nova/+bug/1998148`_ for more information.
17+
18+
Create
19+
------
20+
21+
To attach a volume to a server, you need to know the server ID and the volume ID.
22+
23+
.. sample:: Compute/v2/volume_attachments/create.php
24+
25+
26+
Delete
27+
------
28+
29+
To detach a volume from a server, you need to know the server ID and the volume ID.
30+
31+
.. sample:: Compute/v2/volume_attachments/delete.php
32+
33+
List
34+
----
35+
36+
.. sample:: Compute/v2/volume_attachments/list.php
37+
38+
.. include:: /common/generators.rst

samples/Compute/v2/servers/attach_volume_attachment.php renamed to samples/Compute/v2/volume_atachments/create.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
'id' => '{userId}',
1414
'password' => '{password}'
1515
],
16-
'scope' => ['project' => ['id' => '{projectId}']]
1716
]);
1817

19-
$compute = $openstack->computeV2(['region' => '{region}']);
20-
18+
$compute = $openstack->computeV2();
2119
$server = $compute->getServer(['id' => '{serverId}']);
2220

2321
$volumeAttachment = $server->attachVolume('{volumeId}');

samples/Compute/v2/servers/detach_volume_attachment.php renamed to samples/Compute/v2/volume_atachments/delete.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313
'id' => '{userId}',
1414
'password' => '{password}'
1515
],
16-
'scope' => ['project' => ['id' => '{projectId}']]
1716
]);
1817

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

21-
/**@var OpenStack\Compute\v2\Models\Server $server */
22-
$server = $compute->getServer(['id' => '{serverId}']);
23-
24-
//Must detach by volumeAttachment id
25-
$server->detachVolume('{volumeAttachmentId}');
21+
$server->detachVolume('{volumeId}');

samples/Compute/v2/servers/list_volume_attachments.php renamed to samples/Compute/v2/volume_atachments/list.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
'id' => '{userId}',
1010
'password' => '{password}',
1111
],
12-
'scope' => ['project' => ['id' => '{projectId}']],
1312
]);
1413

15-
$compute = $openstack->computeV2(['region' => '{region}']);
16-
14+
$compute = $openstack->computeV2();
1715
$server = $compute->getServer(['id' => '{serverId}']);
1816

1917
foreach ($server->listVolumeAttachments() as $volumeAttachment) {

tests/sample/Compute/v2/VolumeAttachmentTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testAttach(): VolumeAttachment
2727
$this->assertEquals('available', $volume->status);
2828

2929
/** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */
30-
require_once $this->sampleFile('servers/attach_volume_attachment.php', [
30+
require_once $this->sampleFile('volume_attachments/create.php', [
3131
'{serverId}' => $server->id,
3232
'{volumeId}' => $volume->id,
3333
]);
@@ -47,12 +47,12 @@ public function testList(VolumeAttachment $createdVolumeAttachment)
4747
{
4848
$found = false;
4949
require_once $this->sampleFile(
50-
'servers/list_volume_attachments.php',
50+
'volume_attachments/list.php',
5151
[
5252
'{serverId}' => $createdVolumeAttachment->serverId,
5353
'/** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */' => <<<'PHP'
5454
/** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */
55-
if ($volumeAttachment->id === $createdVolumeAttachment->id) {
55+
if ($volumeAttachment->volumeId === $createdVolumeAttachment->volumeId) {
5656
$found = true;
5757
}
5858
PHP
@@ -73,10 +73,10 @@ public function testDetach(VolumeAttachment $createdVolumeAttachment)
7373
sleep(15);
7474

7575
require_once $this->sampleFile(
76-
'servers/detach_volume_attachment.php',
76+
'volume_attachments/delete.php',
7777
[
78-
'{serverId}' => $createdVolumeAttachment->serverId,
79-
'{volumeAttachmentId}' => $createdVolumeAttachment->id,
78+
'{serverId}' => $createdVolumeAttachment->serverId,
79+
'{volumeId}' => $createdVolumeAttachment->volumeId,
8080
]
8181
);
8282

0 commit comments

Comments
 (0)