Images¶
Create image¶
The only required attribute when creating a new image is name
.
<?php
require 'vendor/autoload.php';
$openstack = new OpenStack\OpenStack([
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => ['id' => '{userId}', 'password' => '{password}'],
'scope' => ['project' => ['id' => '{projectId}']]
]);
$service = $openstack->imagesV2();
$image = $service->createImage([
'name' => '{name}',
'tags' => ['{tag1}', '{tag2}'],
'containerFormat' => '{containerFormat}',
'diskFormat' => '{diskFormat}',
'visibility' => '{visibility}',
'minDisk' => 10,
'protected' => true,
'minRam' => 10,
]);
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
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}']]
]);
$images = $openstack->imagesV2()
->listImages();
foreach ($images as $image) {
}
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
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.
Show image details¶
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->imagesV2();
$image = $service->getImage('{imageId}');
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Update 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}']]
]);
$service = $openstack->imagesV2();
$image = $service->getImage('{imageId}');
$image->update([
'minDisk' => 1,
'minRam' => 1,
'name' => '{name}',
'protected' => false,
'visibility' => '{visibility}',
]);
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Delete 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}']]
]);
$openstack->imagesV2()
->getImage('{imageId}')
->delete();
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Reactivate 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}']]
]);
$service = $openstack->imagesV2();
$image = $service->getImage('{imageId}');
$image->reactivate();
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Deactivate image¶
If you try to download a deactivated image, a Forbidden error is returned.
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->imagesV2();
$image = $service->getImage('{imageId}');
$image->deactivate();
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Upload binary data¶
Before you can store binary image data, you must meet the following preconditions:
- The image must exist.
- You must set the disk and container formats in the image.
- The image status must be
queued
. - Your image storage quota must be sufficient.
The size of the data that you want to store must not exceed the size that the Image service allows.
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->imagesV2();
$image = $service->getImage('{imageId}');
$stream = \GuzzleHttp\Psr7\stream_for(fopen('{fileName}', 'r'));
$image->uploadData($stream);
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.
Download binary data¶
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->imagesV2();
$image = $service->getImage('{imageId}');
/** @var \GuzzleHttp\Psr7\Stream $stream */
$stream = $image->downloadData();
To see all the required and optional parameters for this operation, along with their types and descriptions, view the reference documentation.