Images¶
List images¶
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}']]
]);
$compute = $openstack->computeV2(['region' => '{region}']);
$images = $compute->listImages(['status' => 'ACTIVE']);
foreach ($images as $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.
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
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:
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}']]
]);
$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();
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
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¶
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}']]
]);
$compute = $openstack->computeV2(['region' => '{region}']);
$image = $compute->getImage(['id' => '{imageId}']);
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Retrieve metadata¶
This operation will retrieve the existing metadata for an image:
$metadata = $image->getMetadata();
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Reset metadata¶
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}']]
]);
$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.
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
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',
]);
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Retrieve image metadata item¶
This operation allows you to retrieve the value for a specific metadata item:
$itemValue = $image->getMetadataItem('key');
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Delete image metadata item¶
This operation allows you to remove a specific metadata item:
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}']]
]);
$compute = $openstack->computeV2(['region' => '{region}']);
$image = $compute->getImage(['id' => '{imageId}']);
$image->deleteMetadataItem('key');
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.