Skip to content

Commit 6abc5b1

Browse files
committed
Added sample code for getting and listing hypervisors
1 parent 0f3d985 commit 6abc5b1

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use OpenStack\Compute\v2\Models\Hypervisor;
4+
5+
require 'vendor/autoload.php';
6+
7+
$openstack = new OpenStack\OpenStack([
8+
'authUrl' => '{authUrl}',
9+
'region' => '{region}',
10+
'user' => [
11+
'id' => '{userId}',
12+
'password' => '{password}'
13+
],
14+
'scope' => ['project' => ['id' => '{projectId}']]
15+
]);
16+
17+
$compute = $openstack->computeV2(['region' => '{region}']);
18+
19+
$hypervisor = $compute->getHypervisor(['id' => '{hypervisorId}']);
20+
21+
// By default, this will return an empty Server object and NOT hit the API.
22+
// This is convenient for when you want to use the object for operations
23+
// that do not require an initial GET request. To retrieve the server's details,
24+
// run the following, which *will* call the API with a GET request:
25+
26+
$hypervisor->retrieve();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use OpenStack\Compute\v2\Models\Hypervisor;
4+
5+
require 'vendor/autoload.php';
6+
7+
$openstack = new OpenStack\OpenStack([
8+
'authUrl' => '{authUrl}',
9+
'region' => '{region}',
10+
'user' => [
11+
'id' => '{userId}',
12+
'password' => '{password}'
13+
],
14+
'scope' => ['project' => ['id' => '{projectId}']]
15+
]);
16+
17+
$compute = $openstack->computeV2(['region' => '{region}']);
18+
19+
$hypervisors = $compute->listHypervisors();
20+
21+
foreach($hypervisors as $hypervisor) {
22+
/**@var Hypervisor $hypervisor*/
23+
}

0 commit comments

Comments
 (0)