File tree Expand file tree Collapse file tree 4 files changed +64
-0
lines changed
samples/compute/v2/hypervisors Expand file tree Collapse file tree 4 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use OpenStack \Compute \v2 \Models \HypervisorStatistic ;
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
+ /** @var HypervisorStatistic $hypervisorStatistics */
20
+ $ hypervisorStatistics = $ compute ->getHypervisorStatistics ();
Original file line number Diff line number Diff line change 4
4
5
5
use OpenStack \BlockStorage \v2 \Models \Volume ;
6
6
use OpenStack \Compute \v2 \Models \Flavor ;
7
+ use OpenStack \Compute \v2 \Models \HypervisorStatistic ;
7
8
use OpenStack \Compute \v2 \Models \Image ;
8
9
use OpenStack \Compute \v2 \Models \Keypair ;
9
10
use OpenStack \Compute \v2 \Models \Limit ;
@@ -170,6 +171,7 @@ public function runTests()
170
171
171
172
// Limits
172
173
$ this ->getLimits ();
174
+ $ this ->getHypervisorsStatistics ();
173
175
} finally {
174
176
// Teardown
175
177
$ this ->deleteServer ();
@@ -506,6 +508,16 @@ private function deleteKeypair()
506
508
$ this ->logStep ('Deleted keypair name {name} ' , ['{name} ' => $ this ->keypairName ]);
507
509
}
508
510
511
+ private function getHypervisorsStatistics ()
512
+ {
513
+ require_once $ this ->sampleFile ([], 'hypervisors/get_hypervisors_statistics.php ' );
514
+
515
+ /**@var HypervisorStatistic $hypervisorStatistics */
516
+ $ this ->assertInstanceOf (HypervisorStatistic::class, $ hypervisorStatistics );
517
+
518
+ $ this ->logStep ('Retrieved hypervisors statistics ' );
519
+ }
520
+
509
521
private function getLimits ()
510
522
{
511
523
require_once $ this ->sampleFile ([], 'limits/get_limits.php ' );
Original file line number Diff line number Diff line change
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "hypervisor_statistics": {
6
+ "count": 1,
7
+ "vcpus_used": 0,
8
+ "local_gb_used": 0,
9
+ "memory_mb": 7980,
10
+ "current_workload": 0,
11
+ "vcpus": 8,
12
+ "running_vms": 0,
13
+ "free_disk_gb": 157,
14
+ "disk_available_least": 140,
15
+ "local_gb": 157,
16
+ "free_ram_mb": 7468,
17
+ "memory_mb_used": 512
18
+ }
19
+ }
Original file line number Diff line number Diff line change 5
5
use GuzzleHttp \Psr7 \Response ;
6
6
use OpenStack \Compute \v2 \Api ;
7
7
use OpenStack \Compute \v2 \Models \Flavor ;
8
+ use OpenStack \Compute \v2 \Models \HypervisorStatistic ;
8
9
use OpenStack \Compute \v2 \Models \Image ;
9
10
use OpenStack \Compute \v2 \Models \Keypair ;
10
11
use OpenStack \Compute \v2 \Models \Server ;
@@ -126,4 +127,16 @@ public function test_it_lists_keypairs()
126
127
$ this ->assertInstanceOf (Keypair::class, $ keypair );
127
128
}
128
129
}
130
+
131
+ public function test_it_gets_hypervisor_statistics ()
132
+ {
133
+ $ this ->client
134
+ ->request ('GET ' , 'os-hypervisors/statistics ' , ['headers ' => []])
135
+ ->shouldBeCalled ()
136
+ ->willReturn ($ this ->getFixture ('hypervisor-get ' ));
137
+
138
+ $ hypervisorStats = $ this ->service ->getHypervisorStatistics ();
139
+
140
+ $ this ->assertInstanceOf (HypervisorStatistic::class, $ hypervisorStats );
141
+ }
129
142
}
You can’t perform that action at this time.
0 commit comments