Volume Types

Listing volume types

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => ['id' => '{userId}', 'password' => '{password}'],
    'scope'   => ['project' => ['id' => '{projectId}']]
]);
$service = $openstack->blockStorageV2();

$volumeTypes = $service->listVolumeTypes();

foreach ($volumeTypes as $volumeType) {
    /** @var $volumeType \OpenStack\BlockStorage\v2\VolumeType */
}

To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.

Each iteration will return a VolumeType instance <OpenStack/BlockStorage/v2/Models/VolumeType.html>.

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.

Create volume type

The only attributes that are required when creating a volume are a name. The simplest example would therefore be this:

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => ['id' => '{userId}', 'password' => '{password}'],
    'scope'   => ['project' => ['id' => '{projectId}']]
]);
$service = $openstack->blockStorageV2();

$volumeType = $service->createVolumeType([
    'name' => '{name}',
]);

To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.

Retrieve details of a volume type

When retrieving a volume type, sometimes you only want to operate on it - say to update or delete it. If this is the case, then there is no need to perform an initial GET request to the API:

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => ['id' => '{userId}', 'password' => '{password}'],
    'scope'   => ['project' => ['id' => '{projectId}']]
]);
$service = $openstack->blockStorageV2();

$volumeType = $service->getVolumeType('{volumeTypeId}');

If, however, you do want to retrieve all the details of a remote volume type from the API, you just call:

$volumeType->retrieve();

which will update the state of the local object. This gives you an element of control over your app’s performance.

To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.

Update a volume type

The first step when updating a volume type is modifying the attributes you want updated. By default, only a volume type’s name can be edited.

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => ['id' => '{userId}', 'password' => '{password}'],
    'scope'   => ['project' => ['id' => '{projectId}']]
]);
$service = $openstack->blockStorageV2();

$volumeType = $service->getVolumeType('{volumeTypeId}');
$volumeType->name = '{newName}';
$volumeType->update();

To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.

Delete volume type

To permanently delete a volume type:

Show auth code
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => ['id' => '{userId}', 'password' => '{password}'],
    'scope'   => ['project' => ['id' => '{projectId}']]
]);
$service = $openstack->blockStorageV2();

$volumeType = $service->getVolumeType('{volumeTypeId}');
$volumeType->delete();

To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.