diff --git a/doc/services/block-storage/v2/snapshots.rst b/doc/services/block-storage/v2/snapshots.rst index db9c9da51..2ad7a5122 100644 --- a/doc/services/block-storage/v2/snapshots.rst +++ b/doc/services/block-storage/v2/snapshots.rst @@ -1,2 +1,24 @@ Snapshots ========= + +List volumes +------------ + +.. sample:: BlockStorage/v2/snapshots/list.php +.. refdoc:: OpenStack/BlockStorage/v2/Service.html#method_listSnapshots + +Each iteration will return a php:class:`Snapshot` instance . + +.. include:: /common/generators.rst + +List volumes sorted +~~~~~~~~~~~~~~~~~~~ + +Possible values for sort_key are: +* display_name + +Possible values for sort_dir are: +* asc +* desc + +.. sample:: BlockStorage/v2/snapshots/list_sorted.php \ No newline at end of file diff --git a/doc/services/images/v2/images.rst b/doc/services/images/v2/images.rst index eacc94f55..0020d758d 100644 --- a/doc/services/images/v2/images.rst +++ b/doc/services/images/v2/images.rst @@ -17,6 +17,18 @@ List images .. include:: /common/generators.rst +List images sorted +----------- + +Possible values for sort_key are: +* name + +Possible values for sort_dir are: +* asc +* desc + +.. sample:: Images/v2/images/list_sorted.php + Show image details ------------------ diff --git a/samples/BlockStorage/v2/snapshots/list_sorted.php b/samples/BlockStorage/v2/snapshots/list_sorted.php new file mode 100644 index 000000000..e00c18aa1 --- /dev/null +++ b/samples/BlockStorage/v2/snapshots/list_sorted.php @@ -0,0 +1,18 @@ + '{authUrl}', + 'region' => '{region}', + 'user' => ['id' => '{userId}', 'password' => '{password}'], + 'scope' => ['project' => ['id' => '{projectId}']] +]); + +$service = $openstack->blockStorageV2(); + +$snapshots = $service->listSnapshots(false, ['sortKey' => '{sortKey}', 'sortDir' => '{sortDir}']); + +foreach ($snapshots as $snapshot) { + /** @var $snapshot \OpenStack\BlockStorage\v2\Models\Snapshot */ +} diff --git a/samples/Images/v2/images/list.php b/samples/Images/v2/images/list.php index 0173cf32f..42a714c6b 100644 --- a/samples/Images/v2/images/list.php +++ b/samples/Images/v2/images/list.php @@ -13,4 +13,5 @@ ->listImages(); foreach ($images as $image) { + /** @var \OpenStack\Images\v2\Models\Image $image */ } diff --git a/samples/Images/v2/images/list_sorted.php b/samples/Images/v2/images/list_sorted.php new file mode 100644 index 000000000..07f85f621 --- /dev/null +++ b/samples/Images/v2/images/list_sorted.php @@ -0,0 +1,16 @@ + '{authUrl}', + 'region' => '{region}', + 'user' => ['id' => '{userId}', 'password' => '{password}'], + 'scope' => ['project' => ['id' => '{projectId}']] +]); + +$images = $openstack->imagesV2()->listImages(['sortKey' => '{sortKey}', 'sortDir' => '{sortDir}']); + +foreach ($images as $image) { + /** @var \OpenStack\Images\v2\Models\Image $image */ +} diff --git a/src/Common/Api/AbstractParams.php b/src/Common/Api/AbstractParams.php index 02546062c..7b7b2c775 100644 --- a/src/Common/Api/AbstractParams.php +++ b/src/Common/Api/AbstractParams.php @@ -85,6 +85,7 @@ public function sortDir(): array return [ 'type' => self::STRING_TYPE, 'location' => self::QUERY, + 'sentAs' => 'sort_dir', 'description' => 'Sorts by one or more sets of attribute and sort direction combinations.', 'enum' => ['asc', 'desc'], ]; @@ -95,6 +96,7 @@ public function sortKey(): array return [ 'type' => self::STRING_TYPE, 'location' => self::QUERY, + 'sentAs' => 'sort_key', 'description' => 'Sorts by one or more sets of attribute and sort direction combinations.', ]; } diff --git a/tests/integration/BlockStorage/v2/CoreTest.php b/tests/integration/BlockStorage/v2/CoreTest.php index 9063e80f3..352e07441 100644 --- a/tests/integration/BlockStorage/v2/CoreTest.php +++ b/tests/integration/BlockStorage/v2/CoreTest.php @@ -1,6 +1,6 @@ volumeTypes(); $this->logger->info('-> Snapshots'); $this->snapshots(); + $this->logger->info('-> Snapshot list'); + $this->snapshotList(); $this->outputTimeTaken(); } public function volumes() { - $this->logStep('-> Volumes tests'); + $this->logStep('Creating volume type'); $volumeType = $this->getService()->createVolumeType(['name' => $this->randomStr()]); $replacements = [ '{description}' => $this->randomStr(), - "'{size}'" => 1, - '{name}' => $this->randomStr(), - '{volumeType}' => $volumeType->id, - '{key1}' => $this->randomStr(), - '{val1}' => $this->randomStr(), + "'{size}'" => 1, + '{name}' => $this->randomStr(), + '{volumeType}' => $volumeType->id, + '{key1}' => $this->randomStr(), + '{val1}' => $this->randomStr(), ]; $this->logStep('Creating volume'); @@ -70,7 +72,7 @@ public function volumes() $replacements += [ '{newName}' => $this->randomStr(), - '{newDescription}' => $this->randomStr() + '{newDescription}' => $this->randomStr(), ]; $this->logStep('Updating volume'); @@ -82,6 +84,7 @@ public function volumes() /** @var \Generator $volumes */ require_once $this->sampleFile($replacements, 'volumes/list.php'); + $volume = $this->getService()->getVolume($volumeId); $volume->waitUntil('available'); $this->logStep('Deleting volume'); @@ -135,8 +138,8 @@ public function snapshots() $volume->waitUntil('available', 60); $replacements = [ - '{volumeId}' => $volume->id, - '{name}' => $this->randomStr(), + '{volumeId}' => $volume->id, + '{name}' => $this->randomStr(), '{description}' => $this->randomStr(), ]; @@ -183,6 +186,9 @@ public function snapshots() $snapshot->waitUntil('available', 60); + $this->logStep('Listing snapshots'); + require_once $this->sampleFile($replacements, 'snapshots/list.php'); + $this->logStep('Deleting snapshot'); require_once $this->sampleFile($replacements, 'snapshots/delete.php'); $snapshot->waitUntilDeleted(); @@ -190,4 +196,58 @@ public function snapshots() $this->logStep('Deleting volume'); $volume->delete(); } + + public function snapshotList() + { + $this->logStep('Creating volume'); + $volume = $this->getService()->createVolume(['name' => $this->randomStr(), 'size' => 1]); + $volume->waitUntil('available', 60); + + $names = ['b' . $this->randomStr(), 'a' . $this->randomStr(), 'd' . $this->randomStr(), 'c' . $this->randomStr()]; + $createdSnapshots = []; + foreach ($names as $name) { + $this->logStep('Creating snapshot ' . $name); + $snapshot = $this->getService()->createSnapshot([ + 'volumeId' => $volume->id, + 'name' => $name, + ]); + + self::assertInstanceOf(Snapshot::class, $snapshot); + + $createdSnapshots[] = $snapshot; + $snapshot->waitUntil('available', 60); + } + + try { + $replacements = [ + '{sortKey}' => 'display_name', + '{sortDir}' => 'asc', + ]; + + $this->logStep('Listing snapshots'); + require_once $this->sampleFile($replacements, 'snapshots/list.php'); + + $this->logStep('Listing snapshots sorted asc'); + /** @var Snapshot $snapshot */ + require_once $this->sampleFile($replacements, 'snapshots/list_sorted.php'); + self::assertInstanceOf(Snapshot::class, $snapshot); + self::assertEquals($names[2], $snapshot->name); + + $this->logStep('Listing snapshots sorted desc'); + $replacements['{sortDir}'] = 'desc'; + /** @var Snapshot $snapshot */ + require_once $this->sampleFile($replacements, 'snapshots/list_sorted.php'); + self::assertInstanceOf(Snapshot::class, $snapshot); + self::assertEquals($names[1], $snapshot->name); + } finally { + foreach ($createdSnapshots as $snapshot) { + $this->logStep('Deleting snapshot ' . $snapshot->name); + $snapshot->delete(); + $snapshot->waitUntilDeleted(); + } + + $this->logStep('Deleting volume'); + $volume->delete(); + } + } } diff --git a/tests/integration/Images/v2/CoreTest.php b/tests/integration/Images/v2/CoreTest.php index bc7f7fbf7..ec3ac642b 100644 --- a/tests/integration/Images/v2/CoreTest.php +++ b/tests/integration/Images/v2/CoreTest.php @@ -1,20 +1,39 @@ service) { + $this->service = Utils::getOpenStack()->imagesV2(); + } + + return $this->service; + } + public function runTests() { $this->startTimer(); + $this->logger->info('-> Images'); $this->images(); + + $this->logger->info('-> Members'); $this->members(); + $this->logger->info('-> Image list'); + $this->imageList(); + $this->outputTimeTaken(); } @@ -97,4 +116,50 @@ public function members() /** @var Image $image */ require_once $this->sampleFile($replacements, 'images/delete.php'); } + + public function imageList() + { + $this->logStep('Creating image'); + + $postfix = $this->randomStr(); + $names = ['b' . $postfix, 'a' . $postfix, 'd' . $postfix, 'c' . $postfix]; + $createdImages = []; + foreach ($names as $name) { + $this->logStep("Creating image $name"); + $image = $this->getService()->createImage([ + 'name' => $name, + ]); + + self::assertInstanceOf(Image::class, $image); + $createdImages[] = $image; + } + + + $this->logStep('Listing images sorted asc'); + + $replacements = [ + '{sortKey}' => 'name', + '{sortDir}' => 'asc', + ]; + + /** @var \OpenStack\Images\v2\Models\Image $image */ + require_once $this->sampleFile($replacements, 'images/list_sorted.php'); + self::assertInstanceOf(Image::class, $image); + self::assertEquals($names[2], $image->name); + + + $this->logStep('Listing images sorted desc'); + + $replacements['{sortDir}'] = 'desc'; + /** @var \OpenStack\Images\v2\Models\Image $image */ + require_once $this->sampleFile($replacements, 'images/list_sorted.php'); + self::assertInstanceOf(Image::class, $image); + self::assertEquals($names[1], $image->name); + + foreach ($createdImages as $image) { + $this->logStep("Deleting image $image->name"); + $image->delete(); + } + } + }