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.
More information can be found in the official documentation.
In order to work with volume attachments you have to create the service first.
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.
$compute = $openstack->computeV2();
$server = $compute->getServer(['id' => '{serverId}']);
$volumeAttachment = $server->attachVolume('{volumeId}');
Delete
To detach a volume from a server, you need to know the server ID and the volume ID.
$compute = $openstack->computeV2();
$server = $compute->getServer(['id' => '{serverId}']);
$server->detachVolume('{volumeId}');
List
$compute = $openstack->computeV2();
$server = $compute->getServer(['id' => '{serverId}']);
foreach ($server->listVolumeAttachments() as $volumeAttachment) {
/** @var \OpenStack\BlockStorage\v2\Models\VolumeAttachment $volumeAttachment */
}
By default, PHP generators are used to represent collections of resources in the SDK. The benefit of using
generators is that it generally improves performance, since objects are not saved in memory as the iteration cycle goes
on; instead, each resource is directly output to the user-defined foreach
loop. For all intents and purposes, you
interact with generators like any other Traversable object, but to retain collections in memory, you will need to
implement your own logic.