File tree Expand file tree Collapse file tree
samples/compute/v2/hypervisors Expand file tree Collapse file tree 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 44
55use OpenStack \BlockStorage \v2 \Models \Volume ;
66use OpenStack \Compute \v2 \Models \Flavor ;
7+ use OpenStack \Compute \v2 \Models \HypervisorStatistic ;
78use OpenStack \Compute \v2 \Models \Image ;
89use OpenStack \Compute \v2 \Models \Keypair ;
910use OpenStack \Compute \v2 \Models \Limit ;
@@ -170,6 +171,7 @@ public function runTests()
170171
171172 // Limits
172173 $ this ->getLimits ();
174+ $ this ->getHypervisorsStatistics ();
173175 } finally {
174176 // Teardown
175177 $ this ->deleteServer ();
@@ -506,6 +508,16 @@ private function deleteKeypair()
506508 $ this ->logStep ('Deleted keypair name {name} ' , ['{name} ' => $ this ->keypairName ]);
507509 }
508510
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+
509521 private function getLimits ()
510522 {
511523 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 55use GuzzleHttp \Psr7 \Response ;
66use OpenStack \Compute \v2 \Api ;
77use OpenStack \Compute \v2 \Models \Flavor ;
8+ use OpenStack \Compute \v2 \Models \HypervisorStatistic ;
89use OpenStack \Compute \v2 \Models \Image ;
910use OpenStack \Compute \v2 \Models \Keypair ;
1011use OpenStack \Compute \v2 \Models \Server ;
@@ -126,4 +127,16 @@ public function test_it_lists_keypairs()
126127 $ this ->assertInstanceOf (Keypair::class, $ keypair );
127128 }
128129 }
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+ }
129142}
You can’t perform that action at this time.
0 commit comments