Images

Warning

These APIs are proxy calls to the Images v2 Image service. Nova has deprecated all the proxy APIs and users should use the native APIs instead.

More information can be found in the official documentation.

List images

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

$images = $compute->listImages(['status' => 'ACTIVE']);

foreach ($images as $image) {
    /** @var \OpenStack\Compute\v2\Models\Image $image */
}

Each iteration will return an :apiref:Image instance <OpenStack/Compute/v2/Models/Image.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.

Detailed information

By default, only the id, links and name attributes are returned. To return all information for an image, you must enable detailed information, like so:

$images = $service->listImages(true);

Retrieve an image

When retrieving an image, 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 server:

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

$image = $compute->getImage(['id' => '{imageId}']);

// By default, this will return an empty Image object and NOT hit the API.
// This is convenient for when you want to use the object for operations
// that do not require an initial GET request. To retrieve the image's details,
// run the following, which *will* call the API with a GET request:

$image->retrieve();

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

$image->retrieve();

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

Delete an image

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

$image = $compute->getImage(['id' => '{imageId}']);

$image->delete();

Retrieve metadata

This operation will retrieve the existing metadata for an image:

$metadata = $image->getMetadata();

Reset metadata

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

$image = $compute->getImage(['id' => '{imageId}']);

$image->resetMetadata([
    '{key}' => '{value}',
]);

This operation will _replace_ all existing metadata with whatever is provided in the request. Any existing metadata not specified in the request will be deleted.

Merge metadata

This operation will _merge_ specified metadata with what already exists. Existing values will be overriden, new values will be added. Any existing keys that are not specified in the request will remain unaffected.

$image->mergeMetadata([
    'foo' => 'bar',
]);

Retrieve image metadata item

This operation allows you to retrieve the value for a specific metadata item:

$itemValue = $image->getMetadataItem('key');

Delete image metadata item

This operation allows you to remove a specific metadata item:

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

$image = $compute->getImage(['id' => '{imageId}']);

$image->deleteMetadataItem('{key}');