Volumes — php-opencloud 1.12.1 documentation

# Volumes

## Create a volume

To create a volume, you must specify its size (in gigabytes). All other parameters are optional:

    // Create instance of OpenCloud\Volume\Resource\Volume
    $volume = $service->volume();

    $volume->create(array(
        'size'                => 200,
        'volume_type'         => $service->volumeType('<volume_type_id>'),
        'display_name'        => 'My Volume',
        'display_description' => 'Used for large object storage'
    ));

Get the executable PHP script for this example

## List volumes

    $volumes = $service->volumeList();

    foreach ($volumes as $volume) {
        /** @param $volumeType OpenCloud\Volume\Resource\Volume */
    }

Get the executable PHP script for this example

## Get details on a single volume

If you specify an ID on the `volume()` method, it retrieves information on the specified volume:

    $volume = $dallas->volume('<volume_id>');
    echo $volume->size;

Get the executable PHP script for this example

## To delete a volume

    $volume->delete();

Get the executable PHP script for this example

## Attach a volume to a server

    // retrieve server
    $computeService = $client->computeService('{catalogName}', '{region}');
    $server = $computeService->server('{serverId}');

    // attach volume
    $server->attachVolume($volume, '{mountPoint}')

The `{mountPoint}` is the location on the server on which to mount the volume (usually `/dev/xvhdd` or similar). You can also supply `'auto'` as the mount point, in which case the mount point will be automatically selected for you. `auto` is the default value for `{mountPoint}`, so you do not actually need to supply anything for that parameter.

## Detach a volume from a server

    $server->detachVolume($volume);