Skip to content

Commit 66216f9

Browse files
committed
Added method getResourceMetricMeasures, fixed psr2
1 parent 5f2a461 commit 66216f9

File tree

6 files changed

+61
-25
lines changed

6 files changed

+61
-25
lines changed

src/Metric/v1/Gnocchi/Api.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function getResources(): array
3030
public function getResource(): array
3131
{
3232
return [
33-
'path' => $this->pathPrefix.'/resource/{type}/{id}',
33+
'path' => $this->pathPrefix.'/resource/{type}/{id}',
3434
'method' => 'GET',
3535
'params' => [
3636
'id' => $this->params->idUrl('resource'),
37-
]
37+
],
3838
];
3939
}
4040

@@ -82,32 +82,46 @@ public function getMetrics(): array
8282
'params' => [
8383
'limit' => $this->params->limit(),
8484
'marker' => $this->params->marker(),
85-
'sort' => $this->params->sort()
85+
'sort' => $this->params->sort(),
8686
],
8787
];
8888
}
8989

9090
public function getResourceMetrics(): array
9191
{
9292
return [
93-
'path' => $this->pathPrefix.'/resource/generic/{resourceId}/metric',
93+
'path' => $this->pathPrefix.'/resource/generic/{resourceId}/metric',
9494
'method' => 'GET',
9595
'params' => [
9696
'resourceId' => $this->params->idUrl('metric'),
97-
]
97+
],
9898
];
9999
}
100100

101101
public function getResourceMetric(): array
102102
{
103103
return [
104-
'path' => $this->pathPrefix.'/resource/{type}/{resourceId}/metric/{metric}',
104+
'path' => $this->pathPrefix.'/resource/{type}/{resourceId}/metric/{metric}',
105105
'method' => 'GET',
106106
'params' => [
107107
'resourceId' => $this->params->idUrl('resource'),
108-
'metric' => $this->params->idUrl('metric'),
109-
'type' => $this->params->resourceType(),
110-
]
108+
'metric' => $this->params->idUrl('metric'),
109+
'type' => $this->params->resourceType(),
110+
],
111+
];
112+
}
113+
114+
public function getResourceMetricMeasures(): array
115+
{
116+
return [
117+
'path' => $this->pathPrefix.'/resource/{type}/{resourceId}/metric/{metric}/measures',
118+
'method' => 'GET',
119+
'params' => [
120+
'resourceId' => $this->params->idUrl('resource'),
121+
'metric' => $this->params->idUrl('metric'),
122+
'type' => $this->params->resourceType(),
123+
'granularity' => $this->params->granularity(),
124+
],
111125
];
112126
}
113-
}
127+
}

src/Metric/v1/Gnocchi/Models/Metric.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use OpenStack\Common\Resource\Retrievable;
77
use OpenStack\Metric\v1\Gnocchi\Api;
88

9-
109
/**
1110
* @property Api $api
1211
*/
@@ -47,4 +46,4 @@ public function retrieve()
4746
$response = $this->executeWithState($this->api->getMetric());
4847
$this->populateFromResponse($response);
4948
}
50-
}
49+
}

src/Metric/v1/Gnocchi/Models/Resource.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,37 @@ public function retrieve()
9494
*/
9595
public function getMetric(string $metric): Metric
9696
{
97-
$response = $this->execute($this->api->getResourceMetric(), [
98-
'resourceId' => $this->id,
99-
'metric' => $metric,
100-
'type'=> $this->type
101-
]);
97+
$response = $this->execute(
98+
$this->api->getResourceMetric(),
99+
[
100+
'resourceId' => $this->id,
101+
'metric' => $metric,
102+
'type' => $this->type,
103+
]
104+
);
102105
$metric = $this->model(Metric::class)->populateFromResponse($response);
103106

104107
return $metric;
105108
}
106109

107-
public function getMetricMeasures()
110+
/**
111+
* @param array $options {@see \OpenStack\Metric\v1\Gnocchi\Api::getResourceMetricMeasures}
112+
*
113+
* @return array
114+
*/
115+
public function getMetricMeasures(array $options = []): array
108116
{
117+
$options = array_merge(
118+
$options,
119+
[
120+
'resourceId' => $this->id,
121+
'type' => $this->type,
122+
]
123+
);
109124

125+
$response = $this->execute($this->api->getResourceMetricMeasures(), $options);
126+
127+
return \GuzzleHttp\json_decode($response->getBody());
110128
}
111129

112130
/**
@@ -121,5 +139,3 @@ public function listResourceMetrics(array $options = []): \Generator
121139
return $this->model(Metric::class)->enumerate($this->api->getResourceMetrics(), $options);
122140
}
123141
}
124-
125-

src/Metric/v1/Gnocchi/Models/ResourceType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ class ResourceType extends OperatorResource
1414

1515
/** @var object */
1616
public $attributes;
17-
18-
}
17+
}

src/Metric/v1/Gnocchi/Params.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ public function idUrl($type)
5050
return [
5151
'required' => true,
5252
'location' => self::URL,
53-
'description' => sprintf('The unique ID, or identifier, for the %s', $type)
53+
'description' => sprintf('The unique ID, or identifier, for the %s', $type),
54+
];
55+
}
56+
57+
public function granularity()
58+
{
59+
return [
60+
'location' => self::QUERY,
61+
'type' => self::STRING,
62+
'description' => 'Specify the granularity to retrieve, rather than all the granularities available',
5463
];
5564
}
5665
}

src/Metric/v1/Gnocchi/Service.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use OpenStack\Metric\v1\Gnocchi\Models\Resource;
88
use OpenStack\Metric\v1\Gnocchi\Models\ResourceType;
99

10-
1110
/**
1211
* Gnocci Metric v1 Service class
1312
*
@@ -77,4 +76,4 @@ private function injectGenericType(array &$options)
7776
$options['type'] = Resource::RESOURCE_TYPE_GENERIC;
7877
}
7978
}
80-
}
79+
}

0 commit comments

Comments
 (0)