-
Notifications
You must be signed in to change notification settings - Fork 151
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 #128 from php-opencloud/gnocchi-sdk
[rfr] Gnocchi Metrics SDK v1
- Loading branch information
Showing
16 changed files
with
2,163 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenStack\Metric\v1\Gnocchi; | ||
|
||
use OpenStack\Common\Api\AbstractApi; | ||
|
||
class Api extends AbstractApi | ||
{ | ||
private $pathPrefix = 'v1'; | ||
|
||
public function __construct() | ||
{ | ||
$this->params = new Params(); | ||
} | ||
|
||
public function getResources(): array | ||
{ | ||
return [ | ||
'path' => $this->pathPrefix.'/resource/{type}', | ||
'method' => 'GET', | ||
'params' => [ | ||
'limit' => $this->params->limit(), | ||
'marker' => $this->params->marker(), | ||
'sort' => $this->params->sort(), | ||
'type' => $this->params->resourceType(), | ||
], | ||
]; | ||
} | ||
|
||
public function getResource(): array | ||
{ | ||
return [ | ||
'path' => $this->pathPrefix.'/resource/{type}/{id}', | ||
'method' => 'GET', | ||
'params' => [ | ||
'id' => $this->params->idUrl('resource'), | ||
'type' => $this->params->resourceType(), | ||
], | ||
]; | ||
} | ||
|
||
public function searchResources(): array | ||
{ | ||
return [ | ||
'path' => $this->pathPrefix.'/search/resource/{type}', | ||
'method' => 'POST', | ||
'params' => [ | ||
'limit' => $this->params->limit(), | ||
'marker' => $this->params->marker(), | ||
'sort' => $this->params->sort(), | ||
'type' => $this->params->resourceType(), | ||
'criteria' => $this->params->criteria(), | ||
'contentType' => $this->params->headerContentType(), | ||
], | ||
]; | ||
} | ||
|
||
public function getResourceTypes(): array | ||
{ | ||
return [ | ||
'path' => $this->pathPrefix.'/resource_type', | ||
'method' => 'GET', | ||
'params' => [], | ||
]; | ||
} | ||
|
||
public function getMetric(): array | ||
{ | ||
return [ | ||
'path' => $this->pathPrefix.'/metric/{id}', | ||
'method' => 'GET', | ||
'params' => [ | ||
'id' => $this->params->idUrl('metric'), | ||
], | ||
]; | ||
} | ||
|
||
public function getMetrics(): array | ||
{ | ||
return [ | ||
'path' => $this->pathPrefix.'/metric', | ||
'method' => 'GET', | ||
'params' => [ | ||
'limit' => $this->params->limit(), | ||
'marker' => $this->params->marker(), | ||
'sort' => $this->params->sort(), | ||
], | ||
]; | ||
} | ||
|
||
public function getResourceMetrics(): array | ||
{ | ||
return [ | ||
'path' => $this->pathPrefix.'/resource/generic/{resourceId}/metric', | ||
'method' => 'GET', | ||
'params' => [ | ||
'resourceId' => $this->params->idUrl('metric'), | ||
], | ||
]; | ||
} | ||
|
||
public function getResourceMetric(): array | ||
{ | ||
return [ | ||
'path' => $this->pathPrefix.'/resource/{type}/{resourceId}/metric/{metric}', | ||
'method' => 'GET', | ||
'params' => [ | ||
'resourceId' => $this->params->idUrl('resource'), | ||
'metric' => $this->params->idUrl('metric'), | ||
'type' => $this->params->resourceType(), | ||
], | ||
]; | ||
} | ||
|
||
public function getResourceMetricMeasures(): array | ||
{ | ||
return [ | ||
'path' => $this->pathPrefix.'/resource/{type}/{resourceId}/metric/{metric}/measures', | ||
'method' => 'GET', | ||
'params' => [ | ||
'resourceId' => $this->params->idUrl('resource'), | ||
'metric' => $this->params->idUrl('metric'), | ||
'type' => $this->params->resourceType(), | ||
'granularity' => $this->params->granularity(), | ||
'aggregation' => $this->params->aggregation(), | ||
'start' => $this->params->measureStart(), | ||
'stop' => $this->params->measureStop() | ||
], | ||
]; | ||
} | ||
} |
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,49 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenStack\Metric\v1\Gnocchi\Models; | ||
|
||
use OpenStack\Common\Resource\OperatorResource; | ||
use OpenStack\Common\Resource\Retrievable; | ||
use OpenStack\Metric\v1\Gnocchi\Api; | ||
|
||
/** | ||
* @property Api $api | ||
*/ | ||
class Metric extends OperatorResource implements Retrievable | ||
{ | ||
/** @var string */ | ||
public $createdByUserId; | ||
|
||
/** @var \OpenStack\Metric\v1\Gnocchi\Models\Resource */ | ||
public $resource; | ||
|
||
/** @var string */ | ||
public $name; | ||
|
||
/** @var string */ | ||
public $createdByProjectId; | ||
|
||
/** @var array */ | ||
public $archivePolicy; | ||
|
||
/** @var string */ | ||
public $id; | ||
|
||
/** @var string */ | ||
public $unit; | ||
|
||
protected $aliases = [ | ||
'created_by_user_id' => 'createdByUserId', | ||
'created_by_project_id' => 'createdByProjectId', | ||
'archive_policy' => 'archivePolicy', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function retrieve() | ||
{ | ||
$response = $this->executeWithState($this->api->getMetric()); | ||
$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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenStack\Metric\v1\Gnocchi\Models; | ||
|
||
use OpenStack\Common\Resource\OperatorResource; | ||
use OpenStack\Common\Resource\Retrievable; | ||
use OpenStack\Metric\v1\Gnocchi\Api; | ||
|
||
/** | ||
* @property Api $api | ||
*/ | ||
class Resource extends OperatorResource implements Retrievable | ||
{ | ||
const RESOURCE_TYPE_GENERIC = 'generic'; | ||
const RESOURCE_TYPE_CEPH_ACCOUNT = 'ceph_account'; | ||
const RESOURCE_TYPE_HOST = 'host'; | ||
const RESOURCE_TYPE_HOST_DISK = 'host_disk'; | ||
const RESOURCE_TYPE_HOST_NETWORK_INTERFACE = 'host_network_interface'; | ||
const RESOURCE_TYPE_IDENTITY = 'identity'; | ||
const RESOURCE_TYPE_IMAGE = 'image'; | ||
const RESOURCE_TYPE_INSTANCE = 'instance'; | ||
const RESOURCE_TYPE_INSTANCE_DISK = 'instance_disk'; | ||
const RESOURCE_TYPE_INSTANCE_NETWORK_INTERFACE = 'instance_network_interface'; | ||
const RESOURCE_TYPE_IPMI = 'ipmi'; | ||
const RESOURCE_TYPE_NETWORK = 'network'; | ||
const RESOURCE_TYPE_STACK = 'stack'; | ||
const RESOURCE_TYPE_SWIFT_ACCOUNT = 'swift_account'; | ||
const RESOURCE_TYPE_VOLUME = 'volume'; | ||
|
||
/** @var string */ | ||
public $createdByUserId; | ||
|
||
/** @var string */ | ||
public $startedAt; | ||
|
||
/** @var string */ | ||
public $displayName; | ||
|
||
/** @var string */ | ||
public $revisionEnd; | ||
|
||
/** @var string */ | ||
public $userId; | ||
|
||
/** @var string */ | ||
public $createdByProjectId; | ||
|
||
/** @var string */ | ||
public $id; | ||
|
||
/** @var array */ | ||
public $metrics; | ||
|
||
/** @var string */ | ||
public $host; | ||
|
||
/** @var string */ | ||
public $imageRef; | ||
|
||
/** @var string */ | ||
public $flavorId; | ||
|
||
/** @var string */ | ||
public $serverGroup; | ||
|
||
/** @var string */ | ||
public $originalResourceId; | ||
|
||
/** @var string */ | ||
public $revisionStart; | ||
|
||
/** @var string */ | ||
public $projectId; | ||
|
||
/** @var string */ | ||
public $type; | ||
|
||
/** @var string */ | ||
public $endedAt; | ||
|
||
protected $aliases = [ | ||
'created_by_user_id' => 'createdByUserId', | ||
'started_at' => 'startedAt', | ||
'display_name' => 'displayName', | ||
'revision_end' => 'revisionEnd', | ||
'user_id' => 'userId', | ||
'created_by_project_id' => 'createdByProjectId', | ||
'image_ref' => 'imageRef', | ||
'flavor_id' => 'flavorId', | ||
'server_group' => 'serverGroup', | ||
'original_resource_id' => 'originalResourceId', | ||
'revision_start' => 'revisionStart', | ||
'project_id' => 'projectId', | ||
'ended_at' => 'endedAt', | ||
]; | ||
|
||
public function retrieve() | ||
{ | ||
$response = $this->execute($this->api->getResource(), ['type' => $this->type, 'id' => $this->id]); | ||
$this->populateFromResponse($response); | ||
} | ||
|
||
/** | ||
* @param string $metric | ||
* | ||
* @return Metric | ||
*/ | ||
public function getMetric(string $metric): Metric | ||
{ | ||
$response = $this->execute( | ||
$this->api->getResourceMetric(), | ||
[ | ||
'resourceId' => $this->id, | ||
'metric' => $metric, | ||
'type' => $this->type, | ||
] | ||
); | ||
$metric = $this->model(Metric::class)->populateFromResponse($response); | ||
|
||
return $metric; | ||
} | ||
|
||
/** | ||
* @param array $options {@see \OpenStack\Metric\v1\Gnocchi\Api::getResourceMetricMeasures} | ||
* | ||
* @return array | ||
*/ | ||
public function getMetricMeasures(array $options = []): array | ||
{ | ||
$options = array_merge( | ||
$options, | ||
[ | ||
'resourceId' => $this->id, | ||
'type' => $this->type, | ||
] | ||
); | ||
|
||
$response = $this->execute($this->api->getResourceMetricMeasures(), $options); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody()); | ||
} | ||
|
||
/** | ||
* @param array $options {@see \OpenStack\Metric\v1\Gnocchi\Api::getResourceMetrics} | ||
* | ||
* @return \Generator | ||
*/ | ||
public function listResourceMetrics(array $options = []): \Generator | ||
{ | ||
$options['resourceId'] = $this->id; | ||
|
||
return $this->model(Metric::class)->enumerate($this->api->getResourceMetrics(), $options); | ||
} | ||
} |
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,17 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenStack\Metric\v1\Gnocchi\Models; | ||
|
||
use OpenStack\Common\Resource\OperatorResource; | ||
|
||
class ResourceType extends OperatorResource | ||
{ | ||
/** @var string */ | ||
public $state; | ||
|
||
/** @var string */ | ||
public $name; | ||
|
||
/** @var object */ | ||
public $attributes; | ||
} |
Oops, something went wrong.