-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from nexcess/os-host-readonly
[rtr] Hypervisor RO Access
- Loading branch information
Showing
13 changed files
with
434 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ | |
.test/ | ||
coverage/ | ||
vendor/ | ||
|
||
*.pyc | ||
|
||
phpunit.xml | ||
coverage.xml | ||
composer.lock | ||
env_test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use OpenStack\Compute\v2\Models\Hypervisor; | ||
|
||
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}']); | ||
|
||
$hypervisor = $compute->getHypervisor(['id' => '{hypervisorId}']); | ||
|
||
// By default, this will return an empty Server 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 server's details, | ||
// run the following, which *will* call the API with a GET request: | ||
|
||
$hypervisor->retrieve(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use OpenStack\Compute\v2\Models\Hypervisor; | ||
|
||
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}']); | ||
|
||
$hypervisors = $compute->listHypervisors(); | ||
|
||
foreach ($hypervisors as $hypervisor) { | ||
/**@var Hypervisor $hypervisor*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenStack\Compute\v2\Models; | ||
|
||
use OpenStack\Common\Resource\Listable; | ||
use OpenStack\Common\Resource\Retrievable; | ||
use OpenStack\Common\Resource\OperatorResource; | ||
|
||
/** | ||
* @property \OpenStack\Compute\v2\Api $api | ||
*/ | ||
class Hypervisor extends OperatorResource implements | ||
Retrievable, | ||
Listable | ||
{ | ||
/** @var int */ | ||
public $id; | ||
|
||
/** @var string */ | ||
public $status; | ||
|
||
/** @var string */ | ||
public $state; | ||
|
||
/** @var string */ | ||
public $host_ip; | ||
|
||
/** @var int */ | ||
public $free_disk_gb; | ||
|
||
/** @var int */ | ||
public $free_ram_mb; | ||
|
||
/** @var string */ | ||
public $hypervisor_hostname; | ||
|
||
/** @var string */ | ||
public $hypervisor_type; | ||
|
||
/** @var string */ | ||
public $hypervisor_version; | ||
|
||
/** @var int */ | ||
public $local_gb; | ||
|
||
/** @var int */ | ||
public $local_gb_used; | ||
|
||
/** @var int */ | ||
public $memory_mb; | ||
|
||
/** @var int */ | ||
public $memory_mb_used; | ||
|
||
/** @var int */ | ||
public $running_vms; | ||
|
||
/** @var int */ | ||
public $vcpus; | ||
|
||
/** @var int */ | ||
public $vcpus_used; | ||
|
||
/** @var array */ | ||
public $service; | ||
|
||
protected $resourceKey = 'hypervisor'; | ||
protected $resourcesKey = 'hypervisors'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function retrieve() | ||
{ | ||
$response = $this->execute($this->api->getHypervisor(), ['id' => (string) $this->id]); | ||
$this->populateFromResponse($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/unit/Compute/v2/Fixtures/hypervisor-statistic-get.resp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
|
||
{ | ||
"hypervisor_statistics": { | ||
"count": 1, | ||
"vcpus_used": 0, | ||
"local_gb_used": 0, | ||
"memory_mb": 7980, | ||
"current_workload": 0, | ||
"vcpus": 8, | ||
"running_vms": 0, | ||
"free_disk_gb": 157, | ||
"disk_available_least": 140, | ||
"local_gb": 157, | ||
"free_ram_mb": 7468, | ||
"memory_mb_used": 512 | ||
} | ||
} |
Oops, something went wrong.