Skip to content

Commit f1bf63e

Browse files
author
Jamie Hannaford
authored
Merge pull request #130 from php-opencloud/minor-fixes
[rfr] Minor improvements
2 parents 1902104 + f6574de commit f1bf63e

File tree

7 files changed

+88
-18
lines changed

7 files changed

+88
-18
lines changed

src/BlockStorage/v2/Api.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function getVolumes(): array
4040
'limit' => $this->params->limit(),
4141
'marker' => $this->params->marker(),
4242
'sort' => $this->params->sort(),
43+
'allTenants' => $this->params->allTenants(),
4344
],
4445
];
4546
}
@@ -50,19 +51,22 @@ public function getVolumesDetail(): array
5051
'method' => 'GET',
5152
'path' => 'volumes/detail',
5253
'params' => [
53-
'limit' => $this->params->limit(),
54-
'marker' => $this->params->marker(),
55-
'sort' => $this->params->sort(),
54+
'limit' => $this->params->limit(),
55+
'marker' => $this->params->marker(),
56+
'sort' => $this->params->sort(),
57+
'allTenants' => $this->params->allTenants(),
5658
],
5759
];
5860
}
5961

6062
public function getVolume(): array
6163
{
6264
return [
63-
'method' => 'GET',
64-
'path' => 'volumes/{id}',
65-
'params' => ['id' => $this->params->idPath()],
65+
'method' => 'GET',
66+
'path' => 'volumes/{id}',
67+
'params' => [
68+
'id' => $this->params->idPath()
69+
]
6670
];
6771
}
6872

src/BlockStorage/v2/Models/Volume.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ class Volume extends OperatorResource implements Creatable, Listable, Updateable
5252
/** @var string */
5353
public $sourceVolumeId;
5454

55+
/** @var string */
56+
public $tenantId;
57+
58+
/** @var string */
59+
public $host;
60+
5561
/** @var array */
5662
public $metadata = [];
5763

@@ -60,11 +66,13 @@ class Volume extends OperatorResource implements Creatable, Listable, Updateable
6066
protected $markerKey = 'id';
6167

6268
protected $aliases = [
63-
'availability_zone' => 'availabilityZone',
64-
'source_volid' => 'sourceVolumeId',
65-
'snapshot_id' => 'snapshotId',
66-
'created_at' => 'createdAt',
67-
'volume_type' => 'volumeTypeName',
69+
'availability_zone' => 'availabilityZone',
70+
'source_volid' => 'sourceVolumeId',
71+
'snapshot_id' => 'snapshotId',
72+
'created_at' => 'createdAt',
73+
'volume_type' => 'volumeTypeName',
74+
'os-vol-tenant-attr:tenant_id' => 'tenantId',
75+
'os-vol-host-attr:host' => 'host'
6876
];
6977

7078
public function populateFromResponse(ResponseInterface $response): self

src/Common/Api/AbstractParams.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,14 @@ public function sortKey(): array
9797
'description' => "Sorts by one or more sets of attribute and sort direction combinations.",
9898
];
9999
}
100+
101+
public function allTenants(): array
102+
{
103+
return [
104+
'type' => self::BOOL_TYPE,
105+
'location' => self::QUERY,
106+
'sentAs' => 'all_tenants',
107+
'description' => '(Admin only) Set this to true to pull volume information from all tenants.',
108+
];
109+
}
100110
}

src/Compute/v2/Api.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getFlavors(): array
4242

4343
public function getFlavorsDetail(): array
4444
{
45-
$op = $this->getAll();
45+
$op = $this->getFlavors();
4646
$op['path'] .= '/detail';
4747
return $op;
4848
}
@@ -103,7 +103,7 @@ public function getImages(): array
103103

104104
public function getImagesDetail(): array
105105
{
106-
$op = $this->getAll();
106+
$op = $this->getImages();
107107
$op['path'] .= '/detail';
108108
return $op;
109109
}
@@ -219,6 +219,7 @@ public function getServers(): array
219219
'name' => $this->params->filterName(),
220220
'status' => $this->params->filterStatus('server'),
221221
'host' => $this->params->filterHost(),
222+
'allTenants' => $this->params->allTenants()
222223
],
223224
];
224225
}
@@ -235,7 +236,9 @@ public function getServer(): array
235236
return [
236237
'method' => 'GET',
237238
'path' => 'servers/{id}',
238-
'params' => ['id' => $this->params->urlId('server')]
239+
'params' => [
240+
'id' => $this->params->urlId('server'),
241+
],
239242
];
240243
}
241244

src/Compute/v2/Service.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ public function getServer(array $options = []): Server
7070
/**
7171
* List flavors.
7272
*
73-
* @param array $options {@see \OpenStack\Compute\v2\Api::getFlavors}
74-
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
73+
* @param array $options {@see \OpenStack\Compute\v2\Api::getFlavors}
74+
* @param callable $mapFn A callable function that will be invoked on every iteration of the list.
75+
* @param bool $detailed Set to true to fetch flavors' details.
7576
*
7677
* @return \Generator
7778
*/
78-
public function listFlavors(array $options = [], callable $mapFn = null): \Generator
79+
public function listFlavors(array $options = [], callable $mapFn = null, bool $detailed = false): \Generator
7980
{
80-
return $this->model(Flavor::class)->enumerate($this->api->getFlavors(), $options, $mapFn);
81+
$def = $detailed === true ? $this->api->getFlavorsDetail() : $this->api->getFlavors();
82+
return $this->model(Flavor::class)->enumerate($def, $options, $mapFn);
8183
}
8284

8385
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace OpenStack\Test\Metric\v1\Gnocchi\Models;
4+
5+
use OpenStack\Metric\v1\Gnocchi\Models\Metric;
6+
use OpenStack\Metric\v1\Gnocchi\Api;
7+
use OpenStack\Test\TestCase;
8+
9+
class MetricTest extends TestCase
10+
{
11+
/** @var Metric */
12+
private $metric;
13+
14+
public function setUp()
15+
{
16+
parent::setUp();
17+
18+
$this->rootFixturesDir = dirname(__DIR__);
19+
20+
$this->metric = new Metric($this->client->reveal(), new Api());
21+
$this->metric->id = '000b7bf8-0271-46dd-90aa-cfe89026a55a';
22+
}
23+
24+
public function test_it_retrieves()
25+
{
26+
$this->setupMock('GET', 'v1/metric/000b7bf8-0271-46dd-90aa-cfe89026a55a', null, [], 'metric-get');
27+
$this->metric->retrieve();
28+
29+
$this->assertEquals('000b7bf8-0271-46dd-90aa-cfe89026a55a', $this->metric->id);
30+
$this->assertEquals('storage.objects.outgoing.bytes', $this->metric->name);
31+
}
32+
}

tests/unit/OpenStackTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OpenStack\ObjectStore\v1\Service as ObjectStoreServiceV1;
1616
use OpenStack\BlockStorage\v2\Service as BlockStorageServiceV2;
1717
use OpenStack\Images\v2\Service as ImageServiceV2;
18+
use OpenStack\Metric\v1\Gnocchi\Service as MetricGnocchiV1;
1819

1920
class OpenStackTest extends TestCase
2021
{
@@ -118,6 +119,16 @@ public function test_it_supports_images_v2()
118119
$this->openstack->imagesV2();
119120
}
120121

122+
public function test_it_support_metrics_gnocchi_v1()
123+
{
124+
$this->builder
125+
->createService('Metric\\v1\\Gnocchi', ['catalogName' => 'gnocchi', 'catalogType' => 'metric'])
126+
->shouldBeCalled()
127+
->willReturn($this->service(MetricGnocchiV1::class));
128+
129+
$this->openstack->metricGnocchiV1();
130+
}
131+
121132
private function service($class)
122133
{
123134
return new $class($this->prophesize(ClientInterface::class)->reveal(), new Api());

0 commit comments

Comments
 (0)