From fe3eb6db7f96a7702a5b53ac921e61b7cc210bcd Mon Sep 17 00:00:00 2001 From: Casper Boone Date: Mon, 28 Aug 2017 14:58:32 +0200 Subject: [PATCH 01/31] Add server console output --- .../v2/servers/get_server_console_output.php | 20 +++++++++++++++++++ src/Compute/v2/Api.php | 13 ++++++++++++ src/Compute/v2/Models/Server.php | 16 +++++++++++++++ src/Compute/v2/Params.php | 9 +++++++++ tests/integration/Compute/v2/CoreTest.php | 11 ++++++++++ .../Fixtures/server-get-console-output.resp | 6 ++++++ tests/unit/Compute/v2/Models/ServerTest.php | 8 ++++++++ 7 files changed, 83 insertions(+) create mode 100644 samples/compute/v2/servers/get_server_console_output.php create mode 100644 tests/unit/Compute/v2/Fixtures/server-get-console-output.resp diff --git a/samples/compute/v2/servers/get_server_console_output.php b/samples/compute/v2/servers/get_server_console_output.php new file mode 100644 index 000000000..e579f367a --- /dev/null +++ b/samples/compute/v2/servers/get_server_console_output.php @@ -0,0 +1,20 @@ + '{authUrl}', + 'region' => '{region}', + 'user' => [ + 'id' => '{userId}', + 'password' => '{password}' + ], + 'scope' => ['project' => ['id' => '{projectId}']] +]); + +$compute = $openstack->computeV2(['region' => '{region}']); + +$server = $compute->getServer(['id' => '{serverId}']); + +/** @var string $consoleOutput */ +$consoleOutput = $server->getConsoleOutput(); diff --git a/src/Compute/v2/Api.php b/src/Compute/v2/Api.php index 8c154290f..68730eb43 100644 --- a/src/Compute/v2/Api.php +++ b/src/Compute/v2/Api.php @@ -372,6 +372,19 @@ public function revertServerResize(): array ]; } + public function getConsoleOutput(): array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'jsonKey' => 'os-getConsoleOutput', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'length' => $this->notRequired($this->params->consoleLogLength()), + ], + ]; + } + public function createServerImage(): array { return [ diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index 44582a2f2..24f0ff7a4 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -246,6 +246,22 @@ public function revertResize() $this->execute($this->api->revertServerResize(), ['revertResize' => null, 'id' => $this->id]); } + /** + * Gets the console output of the server. + * + * @param int $length The number of lines, by default all lines will be returned. + * @return string + */ + public function getConsoleOutput(int $length = -1) + { + $response = $this->execute($this->api->getConsoleOutput(), [ + 'id' => $this->id, + 'length' => $length + ]); + + return Utils::jsonDecode($response)['output']; + } + /** * Gets a VNC console for a server. * diff --git a/src/Compute/v2/Params.php b/src/Compute/v2/Params.php index 68e296106..bdb2cce23 100644 --- a/src/Compute/v2/Params.php +++ b/src/Compute/v2/Params.php @@ -499,6 +499,15 @@ public function consoleType(): array ]; } + public function consoleLogLength(): array + { + return [ + 'type' => self::INT_TYPE, + 'location' => self::JSON, + 'required' => false, + ]; + } + protected function quotaSetLimit($sentAs, $description): array { return [ diff --git a/tests/integration/Compute/v2/CoreTest.php b/tests/integration/Compute/v2/CoreTest.php index 56a561ec0..8229b0ee3 100644 --- a/tests/integration/Compute/v2/CoreTest.php +++ b/tests/integration/Compute/v2/CoreTest.php @@ -703,4 +703,15 @@ private function createInterfaceAttachment() $this->logStep('Create interface attachment for server {serverId}', $replacements); } + + private function getConsoleOutput() + { + $replacements = [ + '{serverId}' => $this->serverId + ]; + + require_once $this->sampleFile($replacements, 'servers/get_server_console_output.php'); + + $this->logStep('Get console output for server {serverId}', $replacements); + } } diff --git a/tests/unit/Compute/v2/Fixtures/server-get-console-output.resp b/tests/unit/Compute/v2/Fixtures/server-get-console-output.resp new file mode 100644 index 000000000..59d595672 --- /dev/null +++ b/tests/unit/Compute/v2/Fixtures/server-get-console-output.resp @@ -0,0 +1,6 @@ +HTTP/1.1 200 Accepted +Content-Type: application/json + +{ + "output": "FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE" +} diff --git a/tests/unit/Compute/v2/Models/ServerTest.php b/tests/unit/Compute/v2/Models/ServerTest.php index f3ad6b095..9d70c8f1c 100644 --- a/tests/unit/Compute/v2/Models/ServerTest.php +++ b/tests/unit/Compute/v2/Models/ServerTest.php @@ -209,6 +209,14 @@ public function test_it_reverts_resizes() $this->assertNull($this->server->revertResize()); } + public function test_it_gets_console_output() + { + $expectedJson = ["os-getConsoleOutput" => ["length" => 3]]; + $this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], 'server-get-console-output'); + + $this->assertEquals("FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE", $this->server->getConsoleOutput(3)); + } + public function test_it_gets_vnc_console() { $type = 'novnc'; From ee5dcf401c9d833c1512778b6a95cbd740ab6645 Mon Sep 17 00:00:00 2001 From: Casper Boone Date: Wed, 30 Aug 2017 18:52:22 +0200 Subject: [PATCH 02/31] Add return type hint --- src/Compute/v2/Models/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index 24f0ff7a4..e9606dbfe 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -252,7 +252,7 @@ public function revertResize() * @param int $length The number of lines, by default all lines will be returned. * @return string */ - public function getConsoleOutput(int $length = -1) + public function getConsoleOutput(int $length = -1): string { $response = $this->execute($this->api->getConsoleOutput(), [ 'id' => $this->id, From f85eb66a5f52e1a682bd61e04a9d2aebaf9d0072 Mon Sep 17 00:00:00 2001 From: Casper Boone Date: Wed, 8 Nov 2017 21:10:01 +0100 Subject: [PATCH 03/31] Change behavior for unspecified number of lines --- src/Compute/v2/Api.php | 12 ++++++++++++ src/Compute/v2/Models/Server.php | 7 +++++-- src/Compute/v2/Params.php | 7 +++++++ tests/unit/Compute/v2/Models/ServerTest.php | 8 ++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Compute/v2/Api.php b/src/Compute/v2/Api.php index 68730eb43..3ebde0722 100644 --- a/src/Compute/v2/Api.php +++ b/src/Compute/v2/Api.php @@ -385,6 +385,18 @@ public function getConsoleOutput(): array ]; } + public function getAllConsoleOutput(): array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'os-getConsoleOutput' => $this->params->emptyObject(), + ], + ]; + } + public function createServerImage(): array { return [ diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index e9606dbfe..54e109604 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -254,9 +254,12 @@ public function revertResize() */ public function getConsoleOutput(int $length = -1): string { - $response = $this->execute($this->api->getConsoleOutput(), [ + $definition = $length == -1 ? $this->api->getAllConsoleOutput() : $this->api->getConsoleOutput(); + + $response = $this->execute($definition, [ + 'os-getConsoleOutput' => new \stdClass(), 'id' => $this->id, - 'length' => $length + 'length' => $length, ]); return Utils::jsonDecode($response)['output']; diff --git a/src/Compute/v2/Params.php b/src/Compute/v2/Params.php index bdb2cce23..33ab8d116 100644 --- a/src/Compute/v2/Params.php +++ b/src/Compute/v2/Params.php @@ -508,6 +508,13 @@ public function consoleLogLength(): array ]; } + public function emptyObject(): array + { + return [ + 'type' => self::OBJECT_TYPE, + ]; + } + protected function quotaSetLimit($sentAs, $description): array { return [ diff --git a/tests/unit/Compute/v2/Models/ServerTest.php b/tests/unit/Compute/v2/Models/ServerTest.php index 9d70c8f1c..f80e90810 100644 --- a/tests/unit/Compute/v2/Models/ServerTest.php +++ b/tests/unit/Compute/v2/Models/ServerTest.php @@ -217,6 +217,14 @@ public function test_it_gets_console_output() $this->assertEquals("FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE", $this->server->getConsoleOutput(3)); } + public function test_it_gets_all_console_output() + { + $expectedJson = ["os-getConsoleOutput" => new \stdClass()]; + $this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], 'server-get-console-output'); + + $this->assertEquals("FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE", $this->server->getConsoleOutput()); + } + public function test_it_gets_vnc_console() { $type = 'novnc'; From 4ce2f04872bf924fad16cdb01c4d3ad8b6107681 Mon Sep 17 00:00:00 2001 From: fdmsantos Date: Thu, 4 Jan 2018 18:31:47 -0400 Subject: [PATCH 04/31] Adding possibility to filter floating ips --- src/Networking/v2/Extensions/Layer3/Api.php | 4 +++- src/Networking/v2/Extensions/Layer3/Service.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Networking/v2/Extensions/Layer3/Api.php b/src/Networking/v2/Extensions/Layer3/Api.php index d7c201017..ff02f0b3e 100644 --- a/src/Networking/v2/Extensions/Layer3/Api.php +++ b/src/Networking/v2/Extensions/Layer3/Api.php @@ -34,7 +34,9 @@ public function getFloatingIps(): array return [ 'method' => 'GET', 'path' => $this->pathPrefix . '/floatingips', - 'params' => [], + 'params' => [ + 'tenantId' => $this->params->queryTenantId(), + ], ]; } diff --git a/src/Networking/v2/Extensions/Layer3/Service.php b/src/Networking/v2/Extensions/Layer3/Service.php index 43ae92b35..9444b4a76 100644 --- a/src/Networking/v2/Extensions/Layer3/Service.php +++ b/src/Networking/v2/Extensions/Layer3/Service.php @@ -42,9 +42,9 @@ public function getFloatingIp($id): FloatingIp /** * @return \Generator */ - public function listFloatingIps(): \Generator + public function listFloatingIps(array $options = []): \Generator { - return $this->floatingIp()->enumerate($this->api->getFloatingIps()); + return $this->floatingIp()->enumerate($this->api->getFloatingIps(),$options); } /** From 74bb76a2a6bea2d7c9414c8f02567b537f6a6661 Mon Sep 17 00:00:00 2001 From: fdmsantos Date: Fri, 5 Jan 2018 07:41:10 -0400 Subject: [PATCH 05/31] Fix PSR-2 Style Error --- src/Networking/v2/Extensions/Layer3/Service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Networking/v2/Extensions/Layer3/Service.php b/src/Networking/v2/Extensions/Layer3/Service.php index 9444b4a76..0aa9827e6 100644 --- a/src/Networking/v2/Extensions/Layer3/Service.php +++ b/src/Networking/v2/Extensions/Layer3/Service.php @@ -44,7 +44,7 @@ public function getFloatingIp($id): FloatingIp */ public function listFloatingIps(array $options = []): \Generator { - return $this->floatingIp()->enumerate($this->api->getFloatingIps(),$options); + return $this->floatingIp()->enumerate($this->api->getFloatingIps(), $options); } /** From b827fbb108ee73abd03e13f45988d2b38524ab7e Mon Sep 17 00:00:00 2001 From: Casper Boone Date: Fri, 5 Jan 2018 20:38:01 +0100 Subject: [PATCH 06/31] Add SSH keypair name to server --- src/Compute/v2/Models/Server.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index bc13edd5f..cc206f62a 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -95,6 +95,9 @@ class Server extends OperatorResource implements /** @var Fault */ public $fault; + /** @var string */ + public $keyName; + protected $resourceKey = 'server'; protected $resourcesKey = 'servers'; protected $markerKey = 'id'; @@ -104,6 +107,7 @@ class Server extends OperatorResource implements 'accessIPv4' => 'ipv4', 'accessIPv6' => 'ipv6', 'tenant_id' => 'tenantId', + 'key_name' => 'keyName', 'user_id' => 'userId', 'security_groups' => 'securityGroups', 'OS-EXT-STS:task_state' => 'taskState', From 30d4a31f5cd6eb296dcaf6ccc6ffc30ca0bfc6aa Mon Sep 17 00:00:00 2001 From: Nicolas MURE Date: Tue, 16 Jan 2018 11:21:05 +0100 Subject: [PATCH 07/31] fix metadata header parsing --- src/ObjectStore/v1/Models/MetadataTrait.php | 6 +++--- tests/unit/ObjectStore/v1/Fixtures/HEAD_Object.resp | 3 ++- tests/unit/ObjectStore/v1/Models/ObjectTest.php | 10 +++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ObjectStore/v1/Models/MetadataTrait.php b/src/ObjectStore/v1/Models/MetadataTrait.php index 2adef7f95..9529dbab4 100644 --- a/src/ObjectStore/v1/Models/MetadataTrait.php +++ b/src/ObjectStore/v1/Models/MetadataTrait.php @@ -11,9 +11,9 @@ public function parseMetadata(ResponseInterface $response): array $metadata = []; foreach ($response->getHeaders() as $header => $value) { - $position = strpos($header, static::METADATA_PREFIX); - if ($position === 0) { - $metadata[ltrim($header, static::METADATA_PREFIX)] = $response->getHeader($header)[0]; + if (0 === strpos($header, static::METADATA_PREFIX)) { + $name = substr($header, strlen(static::METADATA_PREFIX)); + $metadata[$name] = $response->getHeader($header)[0]; } } diff --git a/tests/unit/ObjectStore/v1/Fixtures/HEAD_Object.resp b/tests/unit/ObjectStore/v1/Fixtures/HEAD_Object.resp index 3d15101b0..8351ff703 100644 --- a/tests/unit/ObjectStore/v1/Fixtures/HEAD_Object.resp +++ b/tests/unit/ObjectStore/v1/Fixtures/HEAD_Object.resp @@ -5,6 +5,7 @@ Last-Modified: Thu, 16 Jan 2014 21:12:31 GMT Etag: 451e372e48e0f6b1114fa0724aa79fa1 X-Timestamp: 1389906751.73463 X-Object-Meta-Book: GoodbyeColumbus +X-Object-Meta-Manufacturer: Acme Content-Type: application/octet-stream X-Trans-Id: tx37ea34dcd1ed48ca9bc7d-0052d84b6f -Date: Thu, 16 Jan 2014 21:13:19 GMT \ No newline at end of file +Date: Thu, 16 Jan 2014 21:13:19 GMT diff --git a/tests/unit/ObjectStore/v1/Models/ObjectTest.php b/tests/unit/ObjectStore/v1/Models/ObjectTest.php index 36e3e6895..2dd54a3ea 100644 --- a/tests/unit/ObjectStore/v1/Models/ObjectTest.php +++ b/tests/unit/ObjectStore/v1/Models/ObjectTest.php @@ -66,7 +66,10 @@ public function test_Get_Metadata() { $this->setupMock('HEAD', self::CONTAINER . '/' . self::NAME, null, [], 'HEAD_Object'); - $this->assertEquals(['Book' => 'GoodbyeColumbus'], $this->object->getMetadata()); + $this->assertEquals([ + 'Book' => 'GoodbyeColumbus', + 'Manufacturer' => 'Acme', + ], $this->object->getMetadata()); } public function test_Merge_Metadata() @@ -74,8 +77,9 @@ public function test_Merge_Metadata() $this->setupMock('HEAD', self::CONTAINER . '/' . self::NAME, null, [], 'HEAD_Object'); $headers = [ - 'X-Object-Meta-Author' => 'foo', - 'X-Object-Meta-Book' => 'GoodbyeColumbus', + 'X-Object-Meta-Author' => 'foo', + 'X-Object-Meta-Book' => 'GoodbyeColumbus', + 'X-Object-Meta-Manufacturer' => 'Acme', ]; $this->setupMock('POST', self::CONTAINER . '/' . self::NAME, null, $headers, 'NoContent'); From faa43436c746daebb4bdfcab10f1d4db057cea66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C4=81rti=C5=86=C5=A1=20Jakubovi=C4=8Ds?= Date: Fri, 19 Jan 2018 12:49:10 +0200 Subject: [PATCH 08/31] Add tenantId to postSecurityRules api --- src/Networking/v2/Extensions/SecurityGroups/Api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Networking/v2/Extensions/SecurityGroups/Api.php b/src/Networking/v2/Extensions/SecurityGroups/Api.php index be25b6e5f..0d9b4df7b 100644 --- a/src/Networking/v2/Extensions/SecurityGroups/Api.php +++ b/src/Networking/v2/Extensions/SecurityGroups/Api.php @@ -133,6 +133,7 @@ public function postSecurityRules() 'protocol' => $this->params->protocolJson(), 'remoteGroupId' => $this->params->remoteGroupIdJson(), 'remoteIpPrefix' => $this->params->remoteIpPrefixJson(), + 'tenantId' => $this->params->tenantIdJson(), ], ]; } From 709def49b400d9e843ae419fc1b6cf021690317f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C4=81rti=C5=86=C5=A1=20Jakubovi=C4=8Ds?= Date: Mon, 22 Jan 2018 18:58:45 +0200 Subject: [PATCH 09/31] Fix issue with retrieving FloatingIP --- .../v2/Extensions/Layer3/Models/FloatingIp.php | 4 +++- .../Extensions/Layer3/Models/FloatingIpTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php b/src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php index 6e6371542..a32cf69c7 100644 --- a/src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php +++ b/src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php @@ -70,6 +70,8 @@ public function delete() public function retrieve() { - $this->executeWithState($this->api->getFloatingIp()); + $response = $this->execute($this->api->getFloatingIp(), + ['id' => (string)$this->id]); + $this->populateFromResponse($response); } } diff --git a/tests/unit/Networking/v2/Extensions/Layer3/Models/FloatingIpTest.php b/tests/unit/Networking/v2/Extensions/Layer3/Models/FloatingIpTest.php index f0038042c..fe757adcd 100644 --- a/tests/unit/Networking/v2/Extensions/Layer3/Models/FloatingIpTest.php +++ b/tests/unit/Networking/v2/Extensions/Layer3/Models/FloatingIpTest.php @@ -48,5 +48,21 @@ public function test_it_retrieves() $this->setupMock('GET', 'v2.0/floatingips/id', null, [], 'FloatingIp'); $this->floatingIp->retrieve(); + + $this->assertEquals('376da547-b977-4cfe-9cba-275c80debf57', + $this->floatingIp->floatingNetworkId); + $this->assertEquals('d23abc8d-2991-4a55-ba98-2aaea84cc72f', + $this->floatingIp->routerId); + $this->assertEquals('10.0.0.3', + $this->floatingIp->fixedIpAddress); + $this->assertEquals('172.24.4.228', + $this->floatingIp->floatingIpAddress); + $this->assertEquals('4969c491a3c74ee4af974e6d800c62de', + $this->floatingIp->tenantId); + $this->assertEquals('ACTIVE', $this->floatingIp->status); + $this->assertEquals('ce705c24-c1ef-408a-bda3-7bbd946164ab', + $this->floatingIp->portId); + $this->assertEquals('2f245a7b-796b-4f26-9cf9-9e82d248fda7', + $this->floatingIp->id); } } From 3aaaf5ef7312fdacaa1bea154a8606a7c9dd457e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C4=81rti=C5=86=C5=A1=20Jakubovi=C4=8Ds?= Date: Tue, 23 Jan 2018 12:23:43 +0200 Subject: [PATCH 10/31] Cleaner retrieve function for FloatingIp class --- src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php b/src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php index a32cf69c7..700cbb4b1 100644 --- a/src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php +++ b/src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php @@ -70,8 +70,7 @@ public function delete() public function retrieve() { - $response = $this->execute($this->api->getFloatingIp(), - ['id' => (string)$this->id]); + $response = $this->executeWithState($this->api->getFloatingIp()); $this->populateFromResponse($response); } } From 9be32290a49de2db9664b024e73125ea3218982d Mon Sep 17 00:00:00 2001 From: Frank Laszlo Date: Wed, 24 Jan 2018 13:08:50 -0500 Subject: [PATCH 11/31] Add Server::resetState functionality --- doc/services/compute/v2/servers.rst | 10 ++++++++- .../compute/v2/servers/reset_server_state.php | 21 +++++++++++++++++++ src/Compute/v2/Api.php | 13 ++++++++++++ src/Compute/v2/Models/Server.php | 11 ++++++++++ src/Compute/v2/Params.php | 13 ++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 samples/compute/v2/servers/reset_server_state.php diff --git a/doc/services/compute/v2/servers.rst b/doc/services/compute/v2/servers.rst index 7b208f51a..63a10235b 100644 --- a/doc/services/compute/v2/servers.rst +++ b/doc/services/compute/v2/servers.rst @@ -218,6 +218,14 @@ This operation will replace the root password for a server. .. sample:: compute/v2/servers/change_server_password.php .. refdoc:: OpenStack/Compute/v2/Models/Server.html#method_changePassword +Reset server state +------------------ + +This operation will reset the state of the server. + +.. sample:: compute/v2/servers/reset_server_state.php +.. refdoc:: OpenStack/Compute/v2/Models/Server.html#method_resetState + Reboot server ------------- @@ -302,4 +310,4 @@ Further links ------------- * Reference docs for Server class -* API docs \ No newline at end of file +* API docs diff --git a/samples/compute/v2/servers/reset_server_state.php b/samples/compute/v2/servers/reset_server_state.php new file mode 100644 index 000000000..c16643106 --- /dev/null +++ b/samples/compute/v2/servers/reset_server_state.php @@ -0,0 +1,21 @@ + '{authUrl}', + 'region' => '{region}', + 'user' => [ + 'id' => '{userId}', + 'password' => '{password}' + ], + 'scope' => ['project' => ['id' => '{projectId}']] +]); + +$compute = $openstack->computeV2(['region' => '{region}']); + +$server = $compute->getServer([ + 'id' => '{serverId}', +]); + +$server->resetState(); diff --git a/src/Compute/v2/Api.php b/src/Compute/v2/Api.php index be982b2b4..065fd4ec9 100644 --- a/src/Compute/v2/Api.php +++ b/src/Compute/v2/Api.php @@ -279,6 +279,19 @@ public function changeServerPassword(): array ]; } + + public function resetServerState(): array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'resetState' => $this->params->osResetState() + ] + ]; + } + public function rebootServer(): array { return [ diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index cc206f62a..93d48b42b 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -183,6 +183,17 @@ public function changePassword(string $newPassword) ]); } + /** + * Issue a resetState call to the server. + */ + public function resetState() + { + $response = $this->execute($this->api->resetServerState(), [ + 'id' => $this->id, + 'resetState' => ['state' => 'active'] + ]); + } + /** * Reboots the server. * diff --git a/src/Compute/v2/Params.php b/src/Compute/v2/Params.php index d541c4641..0b5fb49be 100644 --- a/src/Compute/v2/Params.php +++ b/src/Compute/v2/Params.php @@ -15,6 +15,19 @@ public function urlId(string $type): array ]); } + public function osResetState(): array + { + return [ + 'type' => self::OBJECT_TYPE, + 'location' => self::JSON, + 'sentAs' => 'os-resetState', + 'required' => true, + 'properties' => [ + 'state' => ['type' => self::STRING_TYPE] + ] + ]; + } + public function minDisk(): array { return [ From 47a5ce2aa619c21f094f5120dff8df13eb4c1b4b Mon Sep 17 00:00:00 2001 From: Ha Phan Date: Sat, 3 Feb 2018 20:08:19 +0800 Subject: [PATCH 12/31] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 01d40516b..a3022613d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ OpenStack services, and versions of services, are supported. ## Getting help -- Meet us on Slack: https://phpopencloud.slack.com ([Get your invitation](https://slackpass.io/phpopencloud)) +- Meet us on Slack: https://phpopencloud.slack.com ([Get your invitation](https://launchpass.com/phpopencloud)) - Report and issue: https://github.com/php-opencloud/openstack/issues ## Requirements From 9b53613b21daf8b2e6464517c7cc128f5d4f4d1f Mon Sep 17 00:00:00 2001 From: Ha Phan Date: Thu, 7 Dec 2017 22:43:47 +0800 Subject: [PATCH 13/31] Added php7.2 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5ca85ee12..fcea94339 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ language: php sudo: false -dist: precise - cache: directories: - $HOME/.composer/cache @@ -12,6 +10,7 @@ matrix: include: - php: 7.0 - php: 7.1 + - php: 7.2 - php: nightly allow_failures: - php: nightly From 8250877cb498721da9120ca543a24055baa6f147 Mon Sep 17 00:00:00 2001 From: mrwogu Date: Sat, 16 Dec 2017 21:02:16 +0100 Subject: [PATCH 14/31] Renamed model Object to StorageObject --- samples/object_store/v1/objects/create.php | 2 +- .../v1/objects/create_from_stream.php | 2 +- .../v1/objects/create_large_object.php | 2 +- samples/object_store/v1/objects/get.php | 2 +- samples/object_store/v1/objects/list.php | 2 +- src/ObjectStore/v1/Models/Container.php | 22 +++++++++---------- .../Models/{Object.php => StorageObject.php} | 2 +- .../ObjectStore/v1/Models/ContainerTest.php | 6 ++--- .../unit/ObjectStore/v1/Models/ObjectTest.php | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) rename src/ObjectStore/v1/Models/{Object.php => StorageObject.php} (98%) diff --git a/samples/object_store/v1/objects/create.php b/samples/object_store/v1/objects/create.php index 6ab81c092..1541c22ca 100644 --- a/samples/object_store/v1/objects/create.php +++ b/samples/object_store/v1/objects/create.php @@ -17,7 +17,7 @@ 'content' => '{objectContent}', ]; -/** @var \OpenStack\ObjectStore\v1\Models\Object $object */ +/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */ $object = $openstack->objectStoreV1() ->getContainer('{containerName}') ->createObject($options); diff --git a/samples/object_store/v1/objects/create_from_stream.php b/samples/object_store/v1/objects/create_from_stream.php index 5873a3ae8..eed9fa20e 100644 --- a/samples/object_store/v1/objects/create_from_stream.php +++ b/samples/object_store/v1/objects/create_from_stream.php @@ -22,7 +22,7 @@ 'stream' => $stream, ]; -/** @var \OpenStack\ObjectStore\v1\Models\Object $object */ +/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */ $object = $openstack->objectStoreV1() ->getContainer('{containerName}') ->createObject($options); diff --git a/samples/object_store/v1/objects/create_large_object.php b/samples/object_store/v1/objects/create_large_object.php index 87cfc7a79..52f03b3f5 100644 --- a/samples/object_store/v1/objects/create_large_object.php +++ b/samples/object_store/v1/objects/create_large_object.php @@ -27,7 +27,7 @@ $options['segmentContainer'] = 'test_segments'; -/** @var \OpenStack\ObjectStore\v1\Models\Object $object */ +/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */ $object = $openstack->objectStoreV1() ->getContainer('test') ->createLargeObject($options); diff --git a/samples/object_store/v1/objects/get.php b/samples/object_store/v1/objects/get.php index 3789bdaba..b7b42f3a5 100644 --- a/samples/object_store/v1/objects/get.php +++ b/samples/object_store/v1/objects/get.php @@ -12,7 +12,7 @@ 'scope' => ['project' => ['id' => '{projectId}']] ]); -/** @var \OpenStack\ObjectStore\v1\Models\Object $object */ +/** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */ $object = $openstack->objectStoreV1() ->getContainer('{containerName}') ->getObject('{objectName}'); diff --git a/samples/object_store/v1/objects/list.php b/samples/object_store/v1/objects/list.php index fa7daef55..8d08cf0d4 100644 --- a/samples/object_store/v1/objects/list.php +++ b/samples/object_store/v1/objects/list.php @@ -16,5 +16,5 @@ ->getContainer('{containerName}'); foreach ($container->listObjects() as $object) { - /** @var \OpenStack\ObjectStore\v1\Models\Object $object */ + /** @var \OpenStack\ObjectStore\v1\Models\StorageObject $object */ } diff --git a/src/ObjectStore/v1/Models/Container.php b/src/ObjectStore/v1/Models/Container.php index 527045466..31414a94a 100644 --- a/src/ObjectStore/v1/Models/Container.php +++ b/src/ObjectStore/v1/Models/Container.php @@ -61,7 +61,7 @@ public function populateFromResponse(ResponseInterface $response): self public function listObjects(array $options = [], callable $mapFn = null): \Generator { $options = array_merge($options, ['name' => $this->name, 'format' => 'json']); - return $this->model(Object::class)->enumerate($this->api->getContainer(), $options, $mapFn); + return $this->model(StorageObject::class)->enumerate($this->api->getContainer(), $options, $mapFn); } /** @@ -136,17 +136,17 @@ public function getMetadata(): array } /** - * Retrieves an Object and populates its `name` and `containerName` properties according to the name provided and + * Retrieves an StorageObject and populates its `name` and `containerName` properties according to the name provided and * the name of this container. A HTTP call will not be executed by default - you need to call - * {@see Object::retrieve} or {@see Object::download} on the returned Object object to do that. + * {@see StorageObject::retrieve} or {@see StorageObject::download} on the returned StorageObject object to do that. * * @param string $name The name of the object * - * @return Object + * @return StorageObject */ - public function getObject($name): Object + public function getObject($name): StorageObject { - return $this->model(Object::class, ['containerName' => $this->name, 'name' => $name]); + return $this->model(StorageObject::class, ['containerName' => $this->name, 'name' => $name]); } /** @@ -179,9 +179,9 @@ public function objectExists(string $name): bool * * @return Object */ - public function createObject(array $data): Object + public function createObject(array $data): StorageObject { - return $this->model(Object::class)->create($data + ['containerName' => $this->name]); + return $this->model(StorageObject::class)->create($data + ['containerName' => $this->name]); } /** @@ -195,9 +195,9 @@ public function createObject(array $data): Object * @param string $data['segmentPrefix'] The prefix that will come before each segment. If omitted, a default * is used: name/timestamp/filesize * - * @return Object + * @return StorageObject */ - public function createLargeObject(array $data): Object + public function createLargeObject(array $data): StorageObject { /** @var \Psr\Http\Message\StreamInterface $stream */ $stream = $data['stream']; @@ -218,7 +218,7 @@ public function createLargeObject(array $data): Object $count = 0; while (!$stream->eof() && $count < round($stream->getSize() / $segmentSize)) { - $promises[] = $this->model(Object::class)->createAsync([ + $promises[] = $this->model(StorageObject::class)->createAsync([ 'name' => sprintf("%s/%d", $segmentPrefix, ++$count), 'stream' => new LimitStream($stream, $segmentSize, ($count - 1) * $segmentSize), 'containerName' => $segmentContainer, diff --git a/src/ObjectStore/v1/Models/Object.php b/src/ObjectStore/v1/Models/StorageObject.php similarity index 98% rename from src/ObjectStore/v1/Models/Object.php rename to src/ObjectStore/v1/Models/StorageObject.php index 2f2558170..ca9302be6 100644 --- a/src/ObjectStore/v1/Models/Object.php +++ b/src/ObjectStore/v1/Models/StorageObject.php @@ -14,7 +14,7 @@ /** * @property \OpenStack\ObjectStore\v1\Api $api */ -class Object extends OperatorResource implements Creatable, Deletable, HasMetadata +class StorageObject extends OperatorResource implements Creatable, Deletable, HasMetadata { use MetadataTrait; diff --git a/tests/unit/ObjectStore/v1/Models/ContainerTest.php b/tests/unit/ObjectStore/v1/Models/ContainerTest.php index 6e83b8a4a..78fe4c655 100644 --- a/tests/unit/ObjectStore/v1/Models/ContainerTest.php +++ b/tests/unit/ObjectStore/v1/Models/ContainerTest.php @@ -8,7 +8,7 @@ use OpenStack\Common\Error\BadResponseError; use OpenStack\ObjectStore\v1\Api; use OpenStack\ObjectStore\v1\Models\Container; -use OpenStack\ObjectStore\v1\Models\Object; +use OpenStack\ObjectStore\v1\Models\StorageObject; use OpenStack\Test\TestCase; use Prophecy\Argument; @@ -95,7 +95,7 @@ public function test_It_Gets_Object() { $object = $this->container->getObject('foo.txt'); - $this->assertInstanceOf(Object::class, $object); + $this->assertInstanceOf(StorageObject::class, $object); $this->assertEquals('foo.txt', $object->name); } @@ -135,7 +135,7 @@ public function test_it_lists_objects() ->willReturn($this->getFixture('GET_Container')); foreach ($this->container->listObjects(['limit' => 2]) as $object) { - $this->assertInstanceOf(Object::class, $object); + $this->assertInstanceOf(StorageObject::class, $object); } } diff --git a/tests/unit/ObjectStore/v1/Models/ObjectTest.php b/tests/unit/ObjectStore/v1/Models/ObjectTest.php index 2dd54a3ea..85202b82a 100644 --- a/tests/unit/ObjectStore/v1/Models/ObjectTest.php +++ b/tests/unit/ObjectStore/v1/Models/ObjectTest.php @@ -5,7 +5,7 @@ use function GuzzleHttp\Psr7\uri_for; use GuzzleHttp\Psr7\Stream; use OpenStack\ObjectStore\v1\Api; -use OpenStack\ObjectStore\v1\Models\Object; +use OpenStack\ObjectStore\v1\Models\StorageObject; use OpenStack\Test\TestCase; class ObjectTest extends TestCase @@ -21,7 +21,7 @@ public function setUp() $this->rootFixturesDir = dirname(__DIR__); - $this->object = new Object($this->client->reveal(), new Api()); + $this->object = new StorageObject($this->client->reveal(), new Api()); $this->object->containerName = self::CONTAINER; $this->object->name = self::NAME; } From 3b5e574f9ee99994a7660e1f0e8b923ed7ebcd8b Mon Sep 17 00:00:00 2001 From: mrwogu Date: Sat, 16 Dec 2017 21:14:56 +0100 Subject: [PATCH 15/31] Updated php-cs-fixer to 2.9.0 Speechless --- .travis.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fcea94339..de1ef134a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_install: before_script: - composer install --prefer-source - vendor/bin/parallel-lint --exclude vendor . - - vendor/bin/php-cs-fixer fix --dry-run --diff --level psr2 . + - vendor/bin/php-cs-fixer fix --dry-run --diff --rules=@PSR2 . - phpenv config-add ./xdebug.ini after_script: diff --git a/composer.json b/composer.json index 6b699598a..a73b3b9b0 100644 --- a/composer.json +++ b/composer.json @@ -49,6 +49,6 @@ "psr/log": "~1.0", "satooshi/php-coveralls": "~1.0", "jakub-onderka/php-parallel-lint": "0.*", - "friendsofphp/php-cs-fixer": "^1.0" + "friendsofphp/php-cs-fixer": "^2.9" } } From 3b618fc5f56488c65db79a9e21642e62fd58bf96 Mon Sep 17 00:00:00 2001 From: mrwogu Date: Sat, 16 Dec 2017 21:16:31 +0100 Subject: [PATCH 16/31] Fixed PSR2 php-cs-fixer rules --- src/Common/Api/Parameter.php | 9 +++++++-- src/Common/Error/Builder.php | 14 ++++++++++---- src/Common/Service/Builder.php | 3 ++- src/Common/Transport/JsonSerializer.php | 3 ++- src/Identity/v2/Models/Catalog.php | 5 ++++- src/Identity/v3/Models/Catalog.php | 5 ++++- src/Identity/v3/Service.php | 9 +++++++-- tests/integration/Compute/v2/CoreTest.php | 3 ++- 8 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/Common/Api/Parameter.php b/src/Common/Api/Parameter.php index 15ab83697..136ff0161 100644 --- a/src/Common/Api/Parameter.php +++ b/src/Common/Api/Parameter.php @@ -207,7 +207,9 @@ private function validateEnums($userValues) { if (!empty($this->enum) && $this->type == 'string' && !in_array($userValues, $this->enum)) { throw new \Exception(sprintf( - 'The only permitted values are %s. You provided %s', implode(', ', $this->enum), print_r($userValues, true) + 'The only permitted values are %s. You provided %s', + implode(', ', $this->enum), + print_r($userValues, true) )); } } @@ -217,7 +219,10 @@ private function validateType($userValues) if (!$this->hasCorrectType($userValues)) { throw new \Exception(sprintf( 'The key provided "%s" has the wrong value type. You provided %s (%s) but was expecting %s', - $this->name, print_r($userValues, true), gettype($userValues), $this->type + $this->name, + print_r($userValues, true), + gettype($userValues), + $this->type )); } } diff --git a/src/Common/Error/Builder.php b/src/Common/Error/Builder.php index 304e54ebf..ad693b7c2 100644 --- a/src/Common/Error/Builder.php +++ b/src/Common/Error/Builder.php @@ -116,8 +116,11 @@ public function httpError(RequestInterface $request, ResponseInterface $response { $message = $this->header('HTTP Error'); - $message .= sprintf("The remote server returned a \"%d %s\" error for the following transaction:\n\n", - $response->getStatusCode(), $response->getReasonPhrase()); + $message .= sprintf( + "The remote server returned a \"%d %s\" error for the following transaction:\n\n", + $response->getStatusCode(), + $response->getReasonPhrase() + ); $message .= $this->header('Request'); $message .= trim($this->str($request)) . PHP_EOL . PHP_EOL; @@ -163,8 +166,11 @@ public function userInputError(string $expectedType, $userValue, string $further { $message = $this->header('User Input Error'); - $message .= sprintf("%s was expected, but the following value was passed in:\n\n%s\n", - $expectedType, print_r($userValue, true)); + $message .= sprintf( + "%s was expected, but the following value was passed in:\n\n%s\n", + $expectedType, + print_r($userValue, true) + ); $message .= "Please ensure that the value adheres to the expectation above. "; diff --git a/src/Common/Service/Builder.php b/src/Common/Service/Builder.php index ee7b5442e..f1c1d155a 100644 --- a/src/Common/Service/Builder.php +++ b/src/Common/Service/Builder.php @@ -166,7 +166,8 @@ private function mergeOptions(array $serviceOptions): array if (!isset($options['identityService']) || !($options['identityService'] instanceof IdentityService)) { throw new \InvalidArgumentException(sprintf( - '"identityService" must be specified and implement %s', IdentityService::class + '"identityService" must be specified and implement %s', + IdentityService::class )); } diff --git a/src/Common/Transport/JsonSerializer.php b/src/Common/Transport/JsonSerializer.php index 24a62a316..826d396c4 100644 --- a/src/Common/Transport/JsonSerializer.php +++ b/src/Common/Transport/JsonSerializer.php @@ -101,7 +101,8 @@ private function serializeObjectValue($value) } elseif (!($value instanceof \stdClass)) { throw new \InvalidArgumentException(sprintf( 'When an object value is provided, it must either be \stdClass or implement the Serializable ' - . 'interface, you provided %s', print_r($value, true) + . 'interface, you provided %s', + print_r($value, true) )); } } diff --git a/src/Identity/v2/Models/Catalog.php b/src/Identity/v2/Models/Catalog.php index 6081507ae..f2cd02c26 100644 --- a/src/Identity/v2/Models/Catalog.php +++ b/src/Identity/v2/Models/Catalog.php @@ -61,7 +61,10 @@ public function getServiceUrl( throw new \RuntimeException(sprintf( "Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s", - $serviceName, $serviceType, $region, $urlType + $serviceName, + $serviceType, + $region, + $urlType )); } } diff --git a/src/Identity/v3/Models/Catalog.php b/src/Identity/v3/Models/Catalog.php index 9fc1a7f9c..55b39c4a4 100644 --- a/src/Identity/v3/Models/Catalog.php +++ b/src/Identity/v3/Models/Catalog.php @@ -56,7 +56,10 @@ public function getServiceUrl(string $name, string $type, string $region, string throw new \RuntimeException(sprintf( "Endpoint URL could not be found in the catalog for this service.\nName: %s\nType: %s\nRegion: %s\nURL type: %s", - $name, $type, $region, $urlType + $name, + $type, + $region, + $urlType )); } } diff --git a/src/Identity/v3/Service.php b/src/Identity/v3/Service.php index 4fca56262..b29261cd1 100644 --- a/src/Identity/v3/Service.php +++ b/src/Identity/v3/Service.php @@ -50,8 +50,13 @@ public function authenticate(array $options): array return [$token, $baseUrl]; } - throw new \RuntimeException(sprintf("No service found with type [%s] name [%s] region [%s] interface [%s]", - $type, $name, $region, $interface)); + throw new \RuntimeException(sprintf( + "No service found with type [%s] name [%s] region [%s] interface [%s]", + $type, + $name, + $region, + $interface + )); } /** diff --git a/tests/integration/Compute/v2/CoreTest.php b/tests/integration/Compute/v2/CoreTest.php index ae4c644cd..eb829b730 100644 --- a/tests/integration/Compute/v2/CoreTest.php +++ b/tests/integration/Compute/v2/CoreTest.php @@ -672,7 +672,8 @@ private function attachVolumeToServer() $this->volume->waitUntil('in-use'); - $this->logStep('Attached volume {volumeId} to server {serverId} with volume attachment id {volumeAttachmentId}', + $this->logStep( + 'Attached volume {volumeId} to server {serverId} with volume attachment id {volumeAttachmentId}', array_merge($replacements, ['{volumeAttachmentId}' => $volumeAttachment->id]) ); } From dc927f4afe54247c597c0fac6f1a121d863024d9 Mon Sep 17 00:00:00 2001 From: mrwogu Date: Sat, 16 Dec 2017 21:25:02 +0100 Subject: [PATCH 17/31] Updated PHPUnit to 6.5 (stable) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a73b3b9b0..d68c7c304 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "justinrainbow/json-schema": "~5.2" }, "require-dev": { - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "^6.5", "sami/sami": "dev-master", "psr/log": "~1.0", "satooshi/php-coveralls": "~1.0", From a5916e85e55f4262b29752a704b0b46c1ae4ea75 Mon Sep 17 00:00:00 2001 From: mrwogu Date: Sat, 16 Dec 2017 22:07:47 +0100 Subject: [PATCH 18/31] Updated tests to use new version PHPUnit --- tests/integration/TestCase.php | 2 +- tests/unit/Common/Api/OperationTest.php | 2 +- tests/unit/Common/Api/ParameterTest.php | 2 +- tests/unit/Common/Error/BuilderTest.php | 2 +- tests/unit/Common/JsonPathTest.php | 2 +- tests/unit/Common/Transport/JsonSerializerTest.php | 2 +- tests/unit/TestCase.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/integration/TestCase.php b/tests/integration/TestCase.php index cebb19538..f382e3015 100644 --- a/tests/integration/TestCase.php +++ b/tests/integration/TestCase.php @@ -5,7 +5,7 @@ use OpenStack\Common\Resource\Deletable; use Psr\Log\LoggerInterface; -abstract class TestCase extends \PHPUnit_Framework_TestCase implements TestInterface +abstract class TestCase extends \PHPUnit\Framework\TestCase implements TestInterface { protected $logger; private $startPoint; diff --git a/tests/unit/Common/Api/OperationTest.php b/tests/unit/Common/Api/OperationTest.php index 36adf3bd5..68e0eaa96 100644 --- a/tests/unit/Common/Api/OperationTest.php +++ b/tests/unit/Common/Api/OperationTest.php @@ -6,7 +6,7 @@ use OpenStack\Common\Api\Parameter; use OpenStack\Test\Fixtures\ComputeV2Api; -class OperationTest extends \PHPUnit_Framework_TestCase +class OperationTest extends \PHPUnit\Framework\TestCase { private $operation; diff --git a/tests/unit/Common/Api/ParameterTest.php b/tests/unit/Common/Api/ParameterTest.php index 79aaa118c..320d25bea 100644 --- a/tests/unit/Common/Api/ParameterTest.php +++ b/tests/unit/Common/Api/ParameterTest.php @@ -5,7 +5,7 @@ use OpenStack\Common\Api\Parameter; use OpenStack\Test\Fixtures\ComputeV2Api; -class ParameterTest extends \PHPUnit_Framework_TestCase +class ParameterTest extends \PHPUnit\Framework\TestCase { private $param; private $data; diff --git a/tests/unit/Common/Error/BuilderTest.php b/tests/unit/Common/Error/BuilderTest.php index 0c91e6973..191fbd23e 100644 --- a/tests/unit/Common/Error/BuilderTest.php +++ b/tests/unit/Common/Error/BuilderTest.php @@ -13,7 +13,7 @@ use OpenStack\Common\Error\Builder; use OpenStack\Common\Error\UserInputError; -class BuilderTest extends \PHPUnit_Framework_TestCase +class BuilderTest extends \PHPUnit\Framework\TestCase { private $builder; private $client; diff --git a/tests/unit/Common/JsonPathTest.php b/tests/unit/Common/JsonPathTest.php index 5648e3275..42edb91ce 100644 --- a/tests/unit/Common/JsonPathTest.php +++ b/tests/unit/Common/JsonPathTest.php @@ -4,7 +4,7 @@ use OpenStack\Common\JsonPath; -class JsonPathTest extends \PHPUnit_Framework_TestCase +class JsonPathTest extends \PHPUnit\Framework\TestCase { private $jsonPath; diff --git a/tests/unit/Common/Transport/JsonSerializerTest.php b/tests/unit/Common/Transport/JsonSerializerTest.php index 652c72192..50a54e5af 100644 --- a/tests/unit/Common/Transport/JsonSerializerTest.php +++ b/tests/unit/Common/Transport/JsonSerializerTest.php @@ -8,7 +8,7 @@ use OpenStack\Common\Resource\OperatorResource; use OpenStack\Common\Transport\JsonSerializer; -class JsonSerializerTest extends \PHPUnit_Framework_TestCase +class JsonSerializerTest extends \PHPUnit\Framework\TestCase { /** @var JsonSerializer */ private $serializer; diff --git a/tests/unit/TestCase.php b/tests/unit/TestCase.php index 3a372dd0e..30f14879e 100644 --- a/tests/unit/TestCase.php +++ b/tests/unit/TestCase.php @@ -8,7 +8,7 @@ use GuzzleHttp\Psr7\Response; use Prophecy\Argument; -abstract class TestCase extends \PHPUnit_Framework_TestCase +abstract class TestCase extends \PHPUnit\Framework\TestCase { /** @var \Prophecy\Prophecy\ObjectProphecy */ protected $client; From c747738680546396d3e76dd777c37a1a7c170e5e Mon Sep 17 00:00:00 2001 From: mrwogu Date: Tue, 19 Dec 2017 14:40:01 +0100 Subject: [PATCH 19/31] Fixed PHPUnit tests --- tests/unit/Common/Api/OperatorTraitTest.php | 8 +++++++- tests/unit/Common/Error/BuilderTest.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/unit/Common/Api/OperatorTraitTest.php b/tests/unit/Common/Api/OperatorTraitTest.php index c0589141a..7c913123c 100644 --- a/tests/unit/Common/Api/OperatorTraitTest.php +++ b/tests/unit/Common/Api/OperatorTraitTest.php @@ -28,7 +28,7 @@ public function setUp() $this->def = [ 'method' => 'GET', - 'path' => 'test', + 'path' => 'test', 'params' => [], ]; @@ -48,6 +48,8 @@ public function test_it_sends_a_request_when_operations_are_executed() $this->client->request('GET', 'test', ['headers' => []])->willReturn(new Response()); $this->operator->execute($this->def, []); + + self::assertTrue(true); } public function test_it_sends_a_request_when_async_operations_are_executed() @@ -55,6 +57,8 @@ public function test_it_sends_a_request_when_async_operations_are_executed() $this->client->requestAsync('GET', 'test', ['headers' => []])->willReturn(new Promise()); $this->operator->executeAsync($this->def, []); + + self::assertTrue(true); } public function test_it_wraps_sequential_ops_in_promise_when_async_is_appended_to_method_name() @@ -90,10 +94,12 @@ public function test_it_returns_a_model_instance() { $this->assertInstanceOf(ResourceInterface::class, $this->operator->model(TestResource::class)); } + public function test_it_populates_models_from_response() { $this->assertInstanceOf(ResourceInterface::class, $this->operator->model(TestResource::class, new Response(200))); } + public function test_it_populates_models_from_arrays() { $data = ['flavor' => [], 'image' => []]; diff --git a/tests/unit/Common/Error/BuilderTest.php b/tests/unit/Common/Error/BuilderTest.php index 191fbd23e..f5710a1bf 100644 --- a/tests/unit/Common/Error/BuilderTest.php +++ b/tests/unit/Common/Error/BuilderTest.php @@ -18,7 +18,7 @@ class BuilderTest extends \PHPUnit\Framework\TestCase private $builder; private $client; - public function __construct() + public function setUp() { $this->client = $this->prophesize(ClientInterface::class); $this->builder = new Builder($this->client->reveal()); From 546ff446866e691847b338a296578c349652b2fd Mon Sep 17 00:00:00 2001 From: mrwogu Date: Tue, 19 Dec 2017 20:30:04 +0100 Subject: [PATCH 20/31] Removed return type for two methods in AbstractResource --- src/Common/Resource/AbstractResource.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Common/Resource/AbstractResource.php b/src/Common/Resource/AbstractResource.php index a3f2f51a0..1adaf2b5e 100644 --- a/src/Common/Resource/AbstractResource.php +++ b/src/Common/Resource/AbstractResource.php @@ -42,7 +42,7 @@ abstract class AbstractResource implements ResourceInterface, Serializable * * @return AbstractResource */ - public function populateFromResponse(ResponseInterface $response): self + public function populateFromResponse(ResponseInterface $response) { if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) { $json = Utils::jsonDecode($response); @@ -61,7 +61,7 @@ public function populateFromResponse(ResponseInterface $response): self * * @return mixed|void */ - public function populateFromArray(array $array): self + public function populateFromArray(array $array) { $aliases = $this->getAliases(); From d21c534884eaac2f85863dc2b83748d0bb54914f Mon Sep 17 00:00:00 2001 From: mrwogu Date: Sat, 6 Jan 2018 16:04:09 +0100 Subject: [PATCH 21/31] Updated docks & readme --- README.md | 4 ++++ doc/services/object-store/v1/objects.rst | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 01d40516b..930630f71 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ OpenStack services, and versions of services, are supported. * [Contributing guide](/CONTRIBUTING.md) * [Code of Conduct](/CODE_OF_CONDUCT.md) +## Backward incompatibility + +Due to new [object typehint](https://wiki.php.net/rfc/object-typehint) since PHP 7.2, class `OpenStack\ObjectStore\v1\Models\Object` had to be renamed to `OpenStack\ObjectStore\v1\Models\StorageObject` + ## Getting help - Meet us on Slack: https://phpopencloud.slack.com ([Get your invitation](https://slackpass.io/phpopencloud)) diff --git a/doc/services/object-store/v1/objects.rst b/doc/services/object-store/v1/objects.rst index f2a2ff886..b958a03c7 100644 --- a/doc/services/object-store/v1/objects.rst +++ b/doc/services/object-store/v1/objects.rst @@ -27,7 +27,7 @@ Download an object ------------------ .. sample:: object_store/v1/objects/download.php -.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_download +.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_download As you will notice, a Stream_ object is returned by this call. For more information about dealing with streams, please consult `Guzzle's docs`_. @@ -88,19 +88,19 @@ Copy object ----------- .. sample:: object_store/v1/objects/copy.php -.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_copy +.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_copy Delete object ------------- .. sample:: object_store/v1/objects/delete.php -.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_delete +.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_delete Get metadata ------------ .. sample:: object_store/v1/objects/get_metadata.php -.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_getMetadata +.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_getMetadata The returned value will be a standard associative array, or hash, containing arbitrary key/value pairs. These will correspond to the values set either when the object was created, or when a previous ``mergeMetadata`` or @@ -110,7 +110,7 @@ Replace all metadata with new values ------------------------------------ .. sample:: object_store/v1/objects/reset_metadata.php -.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_resetMetadata +.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_resetMetadata In order to replace all existing metadata with a set of new values, you can use this operation. Any existing metadata items which not specified in the new set will be removed. For example, say an account has the following metadata @@ -140,7 +140,7 @@ Merge new metadata values with existing --------------------------------------- .. sample:: object_store/v1/objects/merge_metadata.php -.. refdoc:: OpenStack/ObjectStore/v1/Models/Object.html#method_mergeMetadata +.. refdoc:: OpenStack/ObjectStore/v1/Models/StorageObject.html#method_mergeMetadata In order to merge a set of new metadata values with the existing metadata set, you can use this operation. Any existing metadata items which are not specified in the new set will be preserved. For example, say an account has the following From fbddef50aed3753f21ac40db16b9ae0e5d7fa33a Mon Sep 17 00:00:00 2001 From: mrwogu Date: Sat, 27 Jan 2018 18:01:13 +0100 Subject: [PATCH 22/31] Fixed code to PSR2 compatibility --- .../Layer3/Models/FloatingIpTest.php | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/tests/unit/Networking/v2/Extensions/Layer3/Models/FloatingIpTest.php b/tests/unit/Networking/v2/Extensions/Layer3/Models/FloatingIpTest.php index fe757adcd..f7e5e51f9 100644 --- a/tests/unit/Networking/v2/Extensions/Layer3/Models/FloatingIpTest.php +++ b/tests/unit/Networking/v2/Extensions/Layer3/Models/FloatingIpTest.php @@ -49,20 +49,34 @@ public function test_it_retrieves() $this->floatingIp->retrieve(); - $this->assertEquals('376da547-b977-4cfe-9cba-275c80debf57', - $this->floatingIp->floatingNetworkId); - $this->assertEquals('d23abc8d-2991-4a55-ba98-2aaea84cc72f', - $this->floatingIp->routerId); - $this->assertEquals('10.0.0.3', - $this->floatingIp->fixedIpAddress); - $this->assertEquals('172.24.4.228', - $this->floatingIp->floatingIpAddress); - $this->assertEquals('4969c491a3c74ee4af974e6d800c62de', - $this->floatingIp->tenantId); + $this->assertEquals( + '376da547-b977-4cfe-9cba-275c80debf57', + $this->floatingIp->floatingNetworkId + ); + $this->assertEquals( + 'd23abc8d-2991-4a55-ba98-2aaea84cc72f', + $this->floatingIp->routerId + ); + $this->assertEquals( + '10.0.0.3', + $this->floatingIp->fixedIpAddress + ); + $this->assertEquals( + '172.24.4.228', + $this->floatingIp->floatingIpAddress + ); + $this->assertEquals( + '4969c491a3c74ee4af974e6d800c62de', + $this->floatingIp->tenantId + ); $this->assertEquals('ACTIVE', $this->floatingIp->status); - $this->assertEquals('ce705c24-c1ef-408a-bda3-7bbd946164ab', - $this->floatingIp->portId); - $this->assertEquals('2f245a7b-796b-4f26-9cf9-9e82d248fda7', - $this->floatingIp->id); + $this->assertEquals( + 'ce705c24-c1ef-408a-bda3-7bbd946164ab', + $this->floatingIp->portId + ); + $this->assertEquals( + '2f245a7b-796b-4f26-9cf9-9e82d248fda7', + $this->floatingIp->id + ); } } From f837c8e1ce882b8666be735a4987fbda90450945 Mon Sep 17 00:00:00 2001 From: mrwogu Date: Sun, 28 Jan 2018 08:50:41 +0100 Subject: [PATCH 23/31] Fixed: Count returns 1 on StdClass object --- src/Common/JsonSchema/JsonPatch.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Common/JsonSchema/JsonPatch.php b/src/Common/JsonSchema/JsonPatch.php index eb6c6e0ad..ca69f7928 100644 --- a/src/Common/JsonSchema/JsonPatch.php +++ b/src/Common/JsonSchema/JsonPatch.php @@ -78,7 +78,8 @@ protected function handleObject(\stdClass $srcStruct, \stdClass $desStruct, stri protected function shouldPartiallyReplace(\stdClass $o1, \stdClass $o2): bool { - return count(array_diff_key((array) $o1, (array) $o2)) < count($o1); + // NOTE: count(stdClass) always returns 1 + return count(array_diff_key((array) $o1, (array) $o2)) < 1; } protected function arrayDiff(array $a1, array $a2): array From cdfcd5e4c356bc3461680af57c22db5576d4c690 Mon Sep 17 00:00:00 2001 From: Ha Phan Date: Thu, 7 Dec 2017 22:43:47 +0800 Subject: [PATCH 24/31] Added php7.2 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5ca85ee12..fcea94339 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ language: php sudo: false -dist: precise - cache: directories: - $HOME/.composer/cache @@ -12,6 +10,7 @@ matrix: include: - php: 7.0 - php: 7.1 + - php: 7.2 - php: nightly allow_failures: - php: nightly From 5e03d16b8a701e7d43b45d1301dbc1591d1bbb9d Mon Sep 17 00:00:00 2001 From: Ha Phan Date: Sat, 3 Feb 2018 20:08:19 +0800 Subject: [PATCH 25/31] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 930630f71..a528b81a2 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Due to new [object typehint](https://wiki.php.net/rfc/object-typehint) since PHP ## Getting help -- Meet us on Slack: https://phpopencloud.slack.com ([Get your invitation](https://slackpass.io/phpopencloud)) +- Meet us on Slack: https://phpopencloud.slack.com ([Get your invitation](https://launchpass.com/phpopencloud)) - Report and issue: https://github.com/php-opencloud/openstack/issues ## Requirements From 78441f11bc6ae9bf2095a8387db73ba508cca8a1 Mon Sep 17 00:00:00 2001 From: Ha Phan Date: Mon, 5 Feb 2018 11:28:02 +0800 Subject: [PATCH 26/31] Added php_cs config --- .php_cs.dist | 19 +++++++++++++++++++ .travis.yml | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .php_cs.dist diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 000000000..7ae8c4001 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,19 @@ +setRules( + [ + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'protected_to_private' => false + ] + ) + ->setUsingCache(false) + ->setRiskyAllowed(true) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__.'/src') + ->append([__FILE__]) + ); diff --git a/.travis.yml b/.travis.yml index de1ef134a..b657775a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_install: before_script: - composer install --prefer-source - vendor/bin/parallel-lint --exclude vendor . - - vendor/bin/php-cs-fixer fix --dry-run --diff --rules=@PSR2 . + - vendor/bin/php-cs-fixer fix --dry-run --diff . - phpenv config-add ./xdebug.ini after_script: From a29d6341aa26d5a79aa324987d0e9d65469befc4 Mon Sep 17 00:00:00 2001 From: Ha Phan Date: Mon, 5 Feb 2018 11:28:36 +0800 Subject: [PATCH 27/31] Updated BC breaks notice and version guidance --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a528b81a2..e0460b579 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,22 @@ OpenStack services, and versions of services, are supported. * [Official documentation](http://docs.os.php-opencloud.com/) * [Reference documentation](http://refdocs.os.php-opencloud.com) -* [Developer support](https://developer.rackspace.com/) -* [Mailing list](https://groups.google.com/forum/#!forum/php-opencloud) * [Contributing guide](/CONTRIBUTING.md) * [Code of Conduct](/CODE_OF_CONDUCT.md) ## Backward incompatibility -Due to new [object typehint](https://wiki.php.net/rfc/object-typehint) since PHP 7.2, class `OpenStack\ObjectStore\v1\Models\Object` had to be renamed to `OpenStack\ObjectStore\v1\Models\StorageObject` +Due to new [object typehint](https://wiki.php.net/rfc/object-typehint) since PHP 7.2, `Object` is a reserved keyword +thus class `OpenStack\ObjectStore\v1\Models\Object` had to be renamed to +`OpenStack\ObjectStore\v1\Models\StorageObject`. See [#184](https://github.com/php-opencloud/openstack/pull/184) for +details. + +### Version Guidance + +| Version | Status | PHP Version | Life span | +| --------- | --------------------------- | ------------- | ----------------------- | +| `^2.0` | Maintained (Bug fixes only) | `^=7.0,<7.2` | March 2016 - March 2018 | +| `^3.0` | Latest | `^7.0` | March 2018 - March 2020 | ## Getting help From b6ed2cdaee0dbc06a4583ea5471e67ddc2786546 Mon Sep 17 00:00:00 2001 From: Ha Phan Date: Mon, 5 Feb 2018 11:37:12 +0800 Subject: [PATCH 28/31] Added strict mode, increase assertion count instead of assert true --- phpunit.xml.dist | 2 +- tests/unit/Common/Api/OperatorTraitTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cf698d5bb..2493eb9ea 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + diff --git a/tests/unit/Common/Api/OperatorTraitTest.php b/tests/unit/Common/Api/OperatorTraitTest.php index 7c913123c..813eddcdb 100644 --- a/tests/unit/Common/Api/OperatorTraitTest.php +++ b/tests/unit/Common/Api/OperatorTraitTest.php @@ -28,7 +28,7 @@ public function setUp() $this->def = [ 'method' => 'GET', - 'path' => 'test', + 'path' => 'test', 'params' => [], ]; @@ -49,7 +49,7 @@ public function test_it_sends_a_request_when_operations_are_executed() $this->operator->execute($this->def, []); - self::assertTrue(true); + $this->addToAssertionCount(1); } public function test_it_sends_a_request_when_async_operations_are_executed() @@ -58,7 +58,7 @@ public function test_it_sends_a_request_when_async_operations_are_executed() $this->operator->executeAsync($this->def, []); - self::assertTrue(true); + $this->addToAssertionCount(1); } public function test_it_wraps_sequential_ops_in_promise_when_async_is_appended_to_method_name() From 756a8f8d838cdfbac229f50d7902faab864f72fd Mon Sep 17 00:00:00 2001 From: Ha Phan Date: Mon, 5 Feb 2018 11:40:24 +0800 Subject: [PATCH 29/31] Updated php-cs-fixer --- .php_cs.dist | 2 +- .travis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 7ae8c4001..fa9348700 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -15,5 +15,5 @@ return PhpCsFixer\Config::create() ->setFinder( PhpCsFixer\Finder::create() ->in(__DIR__.'/src') - ->append([__FILE__]) + ->append([__FILE__, __DIR__.'/samples']) ); diff --git a/.travis.yml b/.travis.yml index b657775a3..b95c4d7d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_install: before_script: - composer install --prefer-source - vendor/bin/parallel-lint --exclude vendor . - - vendor/bin/php-cs-fixer fix --dry-run --diff . + - vendor/bin/php-cs-fixer fix --dry-run --diff - phpenv config-add ./xdebug.ini after_script: From 3c4bedf74ecf03edd586c83e72573689843f690a Mon Sep 17 00:00:00 2001 From: Ha Phan Date: Mon, 5 Feb 2018 14:02:16 +0800 Subject: [PATCH 30/31] Updated Travis --- .travis.yml | 1 + README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b95c4d7d4..4fa1b0111 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ before_install: - cat $HOME/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/conf.d/xdebug.ini > ./xdebug.ini - phpenv config-rm xdebug.ini || true - composer self-update + - if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi; before_script: - composer install --prefer-source diff --git a/README.md b/README.md index e0460b579..62b0e9abd 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ details. | Version | Status | PHP Version | Life span | | --------- | --------------------------- | ------------- | ----------------------- | -| `^2.0` | Maintained (Bug fixes only) | `^=7.0,<7.2` | March 2016 - March 2018 | +| `^2.0` | Maintained (Bug fixes only) | `>=7.0,<7.2` | March 2016 - March 2018 | | `^3.0` | Latest | `^7.0` | March 2018 - March 2020 | ## Getting help From d136797fc62f60c660859581112778be8b6d6e10 Mon Sep 17 00:00:00 2001 From: Frank Laszlo Date: Mon, 5 Feb 2018 08:50:25 -0500 Subject: [PATCH 31/31] fixes --- src/Compute/v2/Api.php | 4 ++-- src/Compute/v2/Models/Server.php | 2 +- src/Compute/v2/Params.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compute/v2/Api.php b/src/Compute/v2/Api.php index 065fd4ec9..2baf7ba41 100644 --- a/src/Compute/v2/Api.php +++ b/src/Compute/v2/Api.php @@ -279,7 +279,7 @@ public function changeServerPassword(): array ]; } - + public function resetServerState(): array { return [ @@ -287,7 +287,7 @@ public function resetServerState(): array 'path' => 'servers/{id}/action', 'params' => [ 'id' => $this->params->urlId('server'), - 'resetState' => $this->params->osResetState() + 'resetState' => $this->params->resetState() ] ]; } diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index 93d48b42b..8f8e98c30 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -188,7 +188,7 @@ public function changePassword(string $newPassword) */ public function resetState() { - $response = $this->execute($this->api->resetServerState(), [ + $this->execute($this->api->resetServerState(), [ 'id' => $this->id, 'resetState' => ['state' => 'active'] ]); diff --git a/src/Compute/v2/Params.php b/src/Compute/v2/Params.php index 0b5fb49be..00af11c3f 100644 --- a/src/Compute/v2/Params.php +++ b/src/Compute/v2/Params.php @@ -15,7 +15,7 @@ public function urlId(string $type): array ]); } - public function osResetState(): array + public function resetState(): array { return [ 'type' => self::OBJECT_TYPE,