Skip to content

Commit 98f5c5b

Browse files
author
Jamie Hannaford
authored
Merge pull request #128 from php-opencloud/gnocchi-sdk
[rfr] Gnocchi Metrics SDK v1
2 parents 30eaeb9 + 7069432 commit 98f5c5b

16 files changed

+2163
-0
lines changed

src/Metric/v1/Gnocchi/Api.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace OpenStack\Metric\v1\Gnocchi;
4+
5+
use OpenStack\Common\Api\AbstractApi;
6+
7+
class Api extends AbstractApi
8+
{
9+
private $pathPrefix = 'v1';
10+
11+
public function __construct()
12+
{
13+
$this->params = new Params();
14+
}
15+
16+
public function getResources(): array
17+
{
18+
return [
19+
'path' => $this->pathPrefix.'/resource/{type}',
20+
'method' => 'GET',
21+
'params' => [
22+
'limit' => $this->params->limit(),
23+
'marker' => $this->params->marker(),
24+
'sort' => $this->params->sort(),
25+
'type' => $this->params->resourceType(),
26+
],
27+
];
28+
}
29+
30+
public function getResource(): array
31+
{
32+
return [
33+
'path' => $this->pathPrefix.'/resource/{type}/{id}',
34+
'method' => 'GET',
35+
'params' => [
36+
'id' => $this->params->idUrl('resource'),
37+
'type' => $this->params->resourceType(),
38+
],
39+
];
40+
}
41+
42+
public function searchResources(): array
43+
{
44+
return [
45+
'path' => $this->pathPrefix.'/search/resource/{type}',
46+
'method' => 'POST',
47+
'params' => [
48+
'limit' => $this->params->limit(),
49+
'marker' => $this->params->marker(),
50+
'sort' => $this->params->sort(),
51+
'type' => $this->params->resourceType(),
52+
'criteria' => $this->params->criteria(),
53+
'contentType' => $this->params->headerContentType(),
54+
],
55+
];
56+
}
57+
58+
public function getResourceTypes(): array
59+
{
60+
return [
61+
'path' => $this->pathPrefix.'/resource_type',
62+
'method' => 'GET',
63+
'params' => [],
64+
];
65+
}
66+
67+
public function getMetric(): array
68+
{
69+
return [
70+
'path' => $this->pathPrefix.'/metric/{id}',
71+
'method' => 'GET',
72+
'params' => [
73+
'id' => $this->params->idUrl('metric'),
74+
],
75+
];
76+
}
77+
78+
public function getMetrics(): array
79+
{
80+
return [
81+
'path' => $this->pathPrefix.'/metric',
82+
'method' => 'GET',
83+
'params' => [
84+
'limit' => $this->params->limit(),
85+
'marker' => $this->params->marker(),
86+
'sort' => $this->params->sort(),
87+
],
88+
];
89+
}
90+
91+
public function getResourceMetrics(): array
92+
{
93+
return [
94+
'path' => $this->pathPrefix.'/resource/generic/{resourceId}/metric',
95+
'method' => 'GET',
96+
'params' => [
97+
'resourceId' => $this->params->idUrl('metric'),
98+
],
99+
];
100+
}
101+
102+
public function getResourceMetric(): array
103+
{
104+
return [
105+
'path' => $this->pathPrefix.'/resource/{type}/{resourceId}/metric/{metric}',
106+
'method' => 'GET',
107+
'params' => [
108+
'resourceId' => $this->params->idUrl('resource'),
109+
'metric' => $this->params->idUrl('metric'),
110+
'type' => $this->params->resourceType(),
111+
],
112+
];
113+
}
114+
115+
public function getResourceMetricMeasures(): array
116+
{
117+
return [
118+
'path' => $this->pathPrefix.'/resource/{type}/{resourceId}/metric/{metric}/measures',
119+
'method' => 'GET',
120+
'params' => [
121+
'resourceId' => $this->params->idUrl('resource'),
122+
'metric' => $this->params->idUrl('metric'),
123+
'type' => $this->params->resourceType(),
124+
'granularity' => $this->params->granularity(),
125+
'aggregation' => $this->params->aggregation(),
126+
'start' => $this->params->measureStart(),
127+
'stop' => $this->params->measureStop()
128+
],
129+
];
130+
}
131+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace OpenStack\Metric\v1\Gnocchi\Models;
4+
5+
use OpenStack\Common\Resource\OperatorResource;
6+
use OpenStack\Common\Resource\Retrievable;
7+
use OpenStack\Metric\v1\Gnocchi\Api;
8+
9+
/**
10+
* @property Api $api
11+
*/
12+
class Metric extends OperatorResource implements Retrievable
13+
{
14+
/** @var string */
15+
public $createdByUserId;
16+
17+
/** @var \OpenStack\Metric\v1\Gnocchi\Models\Resource */
18+
public $resource;
19+
20+
/** @var string */
21+
public $name;
22+
23+
/** @var string */
24+
public $createdByProjectId;
25+
26+
/** @var array */
27+
public $archivePolicy;
28+
29+
/** @var string */
30+
public $id;
31+
32+
/** @var string */
33+
public $unit;
34+
35+
protected $aliases = [
36+
'created_by_user_id' => 'createdByUserId',
37+
'created_by_project_id' => 'createdByProjectId',
38+
'archive_policy' => 'archivePolicy',
39+
];
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function retrieve()
45+
{
46+
$response = $this->executeWithState($this->api->getMetric());
47+
$this->populateFromResponse($response);
48+
}
49+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace OpenStack\Metric\v1\Gnocchi\Models;
4+
5+
use OpenStack\Common\Resource\OperatorResource;
6+
use OpenStack\Common\Resource\Retrievable;
7+
use OpenStack\Metric\v1\Gnocchi\Api;
8+
9+
/**
10+
* @property Api $api
11+
*/
12+
class Resource extends OperatorResource implements Retrievable
13+
{
14+
const RESOURCE_TYPE_GENERIC = 'generic';
15+
const RESOURCE_TYPE_CEPH_ACCOUNT = 'ceph_account';
16+
const RESOURCE_TYPE_HOST = 'host';
17+
const RESOURCE_TYPE_HOST_DISK = 'host_disk';
18+
const RESOURCE_TYPE_HOST_NETWORK_INTERFACE = 'host_network_interface';
19+
const RESOURCE_TYPE_IDENTITY = 'identity';
20+
const RESOURCE_TYPE_IMAGE = 'image';
21+
const RESOURCE_TYPE_INSTANCE = 'instance';
22+
const RESOURCE_TYPE_INSTANCE_DISK = 'instance_disk';
23+
const RESOURCE_TYPE_INSTANCE_NETWORK_INTERFACE = 'instance_network_interface';
24+
const RESOURCE_TYPE_IPMI = 'ipmi';
25+
const RESOURCE_TYPE_NETWORK = 'network';
26+
const RESOURCE_TYPE_STACK = 'stack';
27+
const RESOURCE_TYPE_SWIFT_ACCOUNT = 'swift_account';
28+
const RESOURCE_TYPE_VOLUME = 'volume';
29+
30+
/** @var string */
31+
public $createdByUserId;
32+
33+
/** @var string */
34+
public $startedAt;
35+
36+
/** @var string */
37+
public $displayName;
38+
39+
/** @var string */
40+
public $revisionEnd;
41+
42+
/** @var string */
43+
public $userId;
44+
45+
/** @var string */
46+
public $createdByProjectId;
47+
48+
/** @var string */
49+
public $id;
50+
51+
/** @var array */
52+
public $metrics;
53+
54+
/** @var string */
55+
public $host;
56+
57+
/** @var string */
58+
public $imageRef;
59+
60+
/** @var string */
61+
public $flavorId;
62+
63+
/** @var string */
64+
public $serverGroup;
65+
66+
/** @var string */
67+
public $originalResourceId;
68+
69+
/** @var string */
70+
public $revisionStart;
71+
72+
/** @var string */
73+
public $projectId;
74+
75+
/** @var string */
76+
public $type;
77+
78+
/** @var string */
79+
public $endedAt;
80+
81+
protected $aliases = [
82+
'created_by_user_id' => 'createdByUserId',
83+
'started_at' => 'startedAt',
84+
'display_name' => 'displayName',
85+
'revision_end' => 'revisionEnd',
86+
'user_id' => 'userId',
87+
'created_by_project_id' => 'createdByProjectId',
88+
'image_ref' => 'imageRef',
89+
'flavor_id' => 'flavorId',
90+
'server_group' => 'serverGroup',
91+
'original_resource_id' => 'originalResourceId',
92+
'revision_start' => 'revisionStart',
93+
'project_id' => 'projectId',
94+
'ended_at' => 'endedAt',
95+
];
96+
97+
public function retrieve()
98+
{
99+
$response = $this->execute($this->api->getResource(), ['type' => $this->type, 'id' => $this->id]);
100+
$this->populateFromResponse($response);
101+
}
102+
103+
/**
104+
* @param string $metric
105+
*
106+
* @return Metric
107+
*/
108+
public function getMetric(string $metric): Metric
109+
{
110+
$response = $this->execute(
111+
$this->api->getResourceMetric(),
112+
[
113+
'resourceId' => $this->id,
114+
'metric' => $metric,
115+
'type' => $this->type,
116+
]
117+
);
118+
$metric = $this->model(Metric::class)->populateFromResponse($response);
119+
120+
return $metric;
121+
}
122+
123+
/**
124+
* @param array $options {@see \OpenStack\Metric\v1\Gnocchi\Api::getResourceMetricMeasures}
125+
*
126+
* @return array
127+
*/
128+
public function getMetricMeasures(array $options = []): array
129+
{
130+
$options = array_merge(
131+
$options,
132+
[
133+
'resourceId' => $this->id,
134+
'type' => $this->type,
135+
]
136+
);
137+
138+
$response = $this->execute($this->api->getResourceMetricMeasures(), $options);
139+
140+
return \GuzzleHttp\json_decode($response->getBody());
141+
}
142+
143+
/**
144+
* @param array $options {@see \OpenStack\Metric\v1\Gnocchi\Api::getResourceMetrics}
145+
*
146+
* @return \Generator
147+
*/
148+
public function listResourceMetrics(array $options = []): \Generator
149+
{
150+
$options['resourceId'] = $this->id;
151+
152+
return $this->model(Metric::class)->enumerate($this->api->getResourceMetrics(), $options);
153+
}
154+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace OpenStack\Metric\v1\Gnocchi\Models;
4+
5+
use OpenStack\Common\Resource\OperatorResource;
6+
7+
class ResourceType extends OperatorResource
8+
{
9+
/** @var string */
10+
public $state;
11+
12+
/** @var string */
13+
public $name;
14+
15+
/** @var object */
16+
public $attributes;
17+
}

0 commit comments

Comments
 (0)