Flavors

List flavors

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}']);

$flavors = $compute->listFlavors();

foreach ($flavors as $flavor) {
}

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 Flavor instance <OpenStack/Compute/v2/Models/Flavor.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 a flavor, you must pass true as the last parameter, like so:

$flavors = $service->listFlavors([], function ($flavor) {
    return $flavor;
}, true);

Retrieve a flavor

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}']);

$flavor = $compute->getFlavor(['id' => '{flavorId}']);

// By default, this will return an empty Flavor 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 flavor's details,
// run the following, which *will* call the API with a GET request:

$flavor->retrieve();

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

When retrieving a flavor, sometimes you only want to operate on it. If this is the case, then there is no need to perform an initial GET request to the server:

// Get an unpopulated object
$flavor = $service->getFlavor(['id' => '{flavorId}']);

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

$flavor->retrieve();

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