From aaa36bad9b05b2d8af26c2faf636991cf2761855 Mon Sep 17 00:00:00 2001 From: Chris Smit Date: Wed, 30 Aug 2017 09:15:13 -0400 Subject: [PATCH 01/15] add suspend/resume methods --- src/Compute/v2/Api.php | 24 ++++++++++++++++++++++++ src/Compute/v2/Models/Server.php | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/Compute/v2/Api.php b/src/Compute/v2/Api.php index 6ef4d24f..7e9279a2 100644 --- a/src/Compute/v2/Api.php +++ b/src/Compute/v2/Api.php @@ -316,6 +316,30 @@ public function stopServer() : array ]; } + public function suspendServer() : array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'suspend' => $this->params->nullAction() + ], + ]; + } + + public function resumeServer() : array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'resume' => $this->params->nullAction() + ], + ]; + } + public function rebuildServer(): array { return [ diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index 3155d397..4c3e125e 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -193,6 +193,28 @@ public function stop() ]); } + /** + * Suspend server + */ + public function suspend() + { + $this->execute($this->api->suspendServer(), [ + 'id' => $this->id, + 'suspend' => null + ]); + } + + /** + * Resume server + */ + public function resume() + { + $this->execute($this->api->resumeServer(), [ + 'id' => $this->id, + 'resume' => null + ]); + } + /** * Rebuilds the server. * From dd815f75c2972b892b6723768c1f8a40189c7b22 Mon Sep 17 00:00:00 2001 From: Chris Smit Date: Wed, 30 Aug 2017 10:00:09 -0400 Subject: [PATCH 02/15] add tests --- tests/integration/Compute/v2/CoreTest.php | 26 +++++++++++++++++++++ tests/unit/Compute/v2/Models/ServerTest.php | 18 ++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tests/integration/Compute/v2/CoreTest.php b/tests/integration/Compute/v2/CoreTest.php index 2bf2e4b0..0d3368e6 100644 --- a/tests/integration/Compute/v2/CoreTest.php +++ b/tests/integration/Compute/v2/CoreTest.php @@ -145,6 +145,8 @@ public function runTests() //$this->changeServerPassword(); $this->stopServer(); $this->startServer(); + $this->suspendServer(); + $this->resumeServer(); $this->resizeServer(); $this->confirmServerResize(); $this->rebuildServer(); @@ -399,6 +401,30 @@ private function startServer() $this->logStep('Started server {serverId}', $replacements); } + private function suspendServer() + { + $replacements = ['{serverId}' => $this->serverId]; + + /** @var $server \OpenStack\Compute\v2\Models\Server */ + require_once $this->sampleFile($replacements, 'servers/suspend_server.php'); + + $server->waitUntilActive(false); + + $this->logStep('Suspended server {serverId}', $replacements); + } + + private function resumeServer() + { + $replacements = ['{serverId}' => $this->serverId]; + + /** @var $server \OpenStack\Compute\v2\Models\Server */ + require_once $this->sampleFile($replacements, 'servers/resume_server.php'); + + $server->waitUntilActive(false); + + $this->logStep('Resumed server {serverId}', $replacements); + } + private function createFlavor() { $replacements = [ diff --git a/tests/unit/Compute/v2/Models/ServerTest.php b/tests/unit/Compute/v2/Models/ServerTest.php index 605becbe..3185e9af 100644 --- a/tests/unit/Compute/v2/Models/ServerTest.php +++ b/tests/unit/Compute/v2/Models/ServerTest.php @@ -185,6 +185,24 @@ public function test_it_stops() $this->assertNull($this->server->stop()); } + public function test_it_suspends() + { + $expectedJson = ['suspend' => null]; + + $this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], new Response(202)); + + $this->assertNull($this->server->suspend()); + } + + public function test_it_resumes() + { + $expectedJson = ['resume' => null]; + + $this->setupMock('POST', 'servers/serverId/action', $expectedJson, [], new Response(202)); + + $this->assertNull($this->server->resume()); + } + public function test_it_resizes() { $expectedJson = ['resize' => ['flavorRef' => 'flavorId']]; From 42cb570ac05459970e3b4802d27c72108112c2ab Mon Sep 17 00:00:00 2001 From: Chris Smit Date: Wed, 30 Aug 2017 10:15:31 -0400 Subject: [PATCH 03/15] add sample files for integration tests --- samples/compute/v2/servers/resume_server.php | 21 +++++++++++++++++++ samples/compute/v2/servers/suspend_server.php | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 samples/compute/v2/servers/resume_server.php create mode 100644 samples/compute/v2/servers/suspend_server.php diff --git a/samples/compute/v2/servers/resume_server.php b/samples/compute/v2/servers/resume_server.php new file mode 100644 index 00000000..e155f86a --- /dev/null +++ b/samples/compute/v2/servers/resume_server.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->resume(); diff --git a/samples/compute/v2/servers/suspend_server.php b/samples/compute/v2/servers/suspend_server.php new file mode 100644 index 00000000..42b80016 --- /dev/null +++ b/samples/compute/v2/servers/suspend_server.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->suspend(); From 929fead1167271e15cb3607a5962c3417bc20a42 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Thu, 31 Aug 2017 10:15:02 -0400 Subject: [PATCH 04/15] Stubbing out net IP availability integration --- src/Networking/v2/Api.php | 21 +++++++ .../v2/Models/NetworkIpAvailability.php | 62 +++++++++++++++++++ src/Networking/v2/Service.php | 28 +++++++++ 3 files changed, 111 insertions(+) create mode 100644 src/Networking/v2/Models/NetworkIpAvailability.php diff --git a/src/Networking/v2/Api.php b/src/Networking/v2/Api.php index 6329ab2a..96228e56 100644 --- a/src/Networking/v2/Api.php +++ b/src/Networking/v2/Api.php @@ -700,4 +700,25 @@ public function deleteLoadBalancerHealthMonitor() : array ] ]; } + + public function getNetworkIpAvailability() : array + { + return [ + 'method' => 'GET', + 'path' => $this->pathPrefix . '/network-ip-availability/{id}', + 'params' => ['id' => $this->params->idPath()], + ]; + } + + public function getNetworkIpAvailabilities(): array + { + return [ + 'method' => 'GET', + 'path' => $this->pathPrefix . '/network-ip-availabilities', + 'params' => [ + 'tenantId' => $this->params->queryTenantId() + ], + ]; + } + } diff --git a/src/Networking/v2/Models/NetworkIpAvailability.php b/src/Networking/v2/Models/NetworkIpAvailability.php new file mode 100644 index 00000000..dbc886a2 --- /dev/null +++ b/src/Networking/v2/Models/NetworkIpAvailability.php @@ -0,0 +1,62 @@ + 'networkId', + 'network_name' => 'networkName', + 'tenant_id' => 'tenantId', + 'project_id' => 'projectId', + 'total_ips' => 'totalIps', + 'used_ips' => 'usedIps', + 'subnet_ip_availability' => 'subnetIpAvailability' + ]; + + protected $resourceKey = 'network_ip_availability'; + protected $resourcesKey = 'network_ip_availabilities'; + protected $markerKey = 'network_id'; + + /** + * {@inheritDoc} + */ + public function retrieve() + { + $response = $this->execute($this->api->getNetworkIpAvailability(), ['newtork_id' => (string)$this->networkId]); + $this->populateFromResponse($response); + } +} diff --git a/src/Networking/v2/Service.php b/src/Networking/v2/Service.php index 68afdc46..60ef75c8 100644 --- a/src/Networking/v2/Service.php +++ b/src/Networking/v2/Service.php @@ -9,6 +9,7 @@ use OpenStack\Networking\v2\Models\LoadBalancerMember; use OpenStack\Networking\v2\Models\LoadBalancerPool; use OpenStack\Networking\v2\Models\Network; +use OpenStack\Networking\v2\Models\NetworkIpAvailability; use OpenStack\Networking\v2\Models\Pool; use OpenStack\Networking\v2\Models\Port; use OpenStack\Networking\v2\Models\Quota; @@ -383,4 +384,31 @@ public function createLoadBalancerHealthMonitor(array $options): LoadBalancerHea { return $this->model(LoadBalancerHealthMonitor::class)->create($options); } + + /** + * Retrieve a network IP availability object without calling the remote API. Any values provided in the array will populate the + * empty object, allowing you greater control without the expense of network transactions. To call the remote API + * and have the response populate the object, call {@see NetworkIpAvailabilities::retrieve}. + * + * @param string $network_id + * + * @return NetworkIpAvailability + */ + public function getNetworkIpAvailability(string $network_id): NetworkIpAvailability + { + return $this->model(NetworkIpAvailability::class, ['network_id' => $network_id]); + } + + /** + * List network IP availability(es) + * + * @param array $options {@see \OpenStack\Networking\v2\Api::getNetworkIpAvailabilities() + * + * @return \Generator + */ + public function listNetworkIpAvailabilities(array $options = []): \Generator + { + return $this->model(NetworkIpAvailability::class)->enumerate($this->api->getNetworkIpAvailabilities(), $options); + } + } From 36941ca415caac73cf61f49ff6b85d91509ed5c7 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Sun, 3 Sep 2017 08:25:50 -0400 Subject: [PATCH 05/15] Stubbing out volume ops --- src/BlockStorage/v2/Api.php | 14 ++++++++++++++ src/BlockStorage/v2/Models/Volume.php | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/BlockStorage/v2/Api.php b/src/BlockStorage/v2/Api.php index 9f49e8f4..215c9f52 100644 --- a/src/BlockStorage/v2/Api.php +++ b/src/BlockStorage/v2/Api.php @@ -302,4 +302,18 @@ public function putQuotaSet(): array ] ]; } + + public function extendVolume(): array + { + return [ + 'method' => 'POST', + 'path' => 'volumes/{id}/action', + 'jsonKey' => 'os-extend', + 'params' => [ + 'id' => $this->params->idPath(), + 'new_size' => $this->params->name('size'), + ], + ]; + } + } diff --git a/src/BlockStorage/v2/Models/Volume.php b/src/BlockStorage/v2/Models/Volume.php index 2b170827..0918da36 100644 --- a/src/BlockStorage/v2/Models/Volume.php +++ b/src/BlockStorage/v2/Models/Volume.php @@ -135,4 +135,14 @@ public function parseMetadata(ResponseInterface $response): array $json = Utils::jsonDecode($response); return isset($json['metadata']) ? $json['metadata'] : []; } + + public function extend(int $size_in_gb) + { + $response = $this->execute($this->api->extendVolume(), [ + 'id' => $this->id, + 'size' => $new_size, + ]); + + $this->populateFromResponse($response); + } } From d5784f6dfe2af09783a68d2a84357846220ec40e Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Mon, 4 Sep 2017 22:25:28 -0400 Subject: [PATCH 06/15] Adding in the shelving functions --- src/Compute/v2/Api.php | 36 ++++++++++++++++++++++++++++++++ src/Compute/v2/Models/Server.php | 33 +++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/src/Compute/v2/Api.php b/src/Compute/v2/Api.php index 6ef4d24f..c5e3c8d7 100644 --- a/src/Compute/v2/Api.php +++ b/src/Compute/v2/Api.php @@ -316,6 +316,42 @@ public function stopServer() : array ]; } + public function shelveServer() : array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'shelve' => $this->params->nullAction() + ], + ]; + } + + public function shelveOffloadServer() : array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'shelveOffload' => $this->params->nullAction() + ], + ]; + } + + public function unshelveServer() : array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'unshelve' => $this->params->nullAction() + ], + ]; + } + public function rebuildServer(): array { return [ diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index 3155d397..948aed8f 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -193,6 +193,39 @@ public function stop() ]); } + /** + * Shelves server + */ + public function shelve() + { + $this->execute($this->api->shelveServer(), [ + 'id' => $this->id, + 'shelve' => null + ]); + } + + /** + * Shelf-offloads server + */ + public function shelveOffload() + { + $this->execute($this->api->shelveOffloadServer(), [ + 'id' => $this->id, + 'shelveOffload' => null + ]); + } + + /** + * Unshelves server + */ + public function unshelve() + { + $this->execute($this->api->unshelveServer(), [ + 'id' => $this->id, + 'unshelve' => null + ]); + } + /** * Rebuilds the server. * From 601bdac866d31b00ade0e643f6f4e58c586252bd Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Mon, 4 Sep 2017 23:09:23 -0400 Subject: [PATCH 07/15] Adding in vol functions for extend --- src/BlockStorage/v2/Api.php | 2 +- src/BlockStorage/v2/Models/Volume.php | 2 +- src/BlockStorage/v2/Params.php | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/BlockStorage/v2/Api.php b/src/BlockStorage/v2/Api.php index 215c9f52..e6547960 100644 --- a/src/BlockStorage/v2/Api.php +++ b/src/BlockStorage/v2/Api.php @@ -311,7 +311,7 @@ public function extendVolume(): array 'jsonKey' => 'os-extend', 'params' => [ 'id' => $this->params->idPath(), - 'new_size' => $this->params->name('size'), + 'new_size' => $this->params->size(), ], ]; } diff --git a/src/BlockStorage/v2/Models/Volume.php b/src/BlockStorage/v2/Models/Volume.php index 0918da36..18b16508 100644 --- a/src/BlockStorage/v2/Models/Volume.php +++ b/src/BlockStorage/v2/Models/Volume.php @@ -140,7 +140,7 @@ public function extend(int $size_in_gb) { $response = $this->execute($this->api->extendVolume(), [ 'id' => $this->id, - 'size' => $new_size, + 'new_size' => $size_in_gb ]); $this->populateFromResponse($response); diff --git a/src/BlockStorage/v2/Params.php b/src/BlockStorage/v2/Params.php index 000fa4e0..42952693 100644 --- a/src/BlockStorage/v2/Params.php +++ b/src/BlockStorage/v2/Params.php @@ -159,7 +159,7 @@ public function snapshotName(): array 'location' => self::JSON, ]; } - + protected function quotaSetLimit($sentAs, $description): array { return [ @@ -224,4 +224,13 @@ public function quotaSetVolumesIscsi(): array { return $this->quotaSetLimit('volumes_iscsi', 'The number of allowed volumes iscsi'); } + + public function nullAction(): array + { + return [ + 'type' => self::NULL_TYPE, + 'location' => self::JSON, + 'required' => true + ]; + } } From b2d95e14d1506246182ce5e2b542cb705afaf6b8 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 5 Sep 2017 22:38:41 -0400 Subject: [PATCH 08/15] console log integration --- src/Compute/v2/Api.php | 13 +++++++++++++ src/Compute/v2/Models/Server.php | 12 ++++++++++++ src/Compute/v2/Params.php | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/src/Compute/v2/Api.php b/src/Compute/v2/Api.php index bfee6d8c..c44a7d97 100644 --- a/src/Compute/v2/Api.php +++ b/src/Compute/v2/Api.php @@ -498,6 +498,19 @@ public function getRDPConsole(): array ]; } + public function getConsoleLog(): array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'jsonKey' => 'os-getConsoleOutput', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'length' => $this->params->consoleLogLength() + ] + ]; + } + public function getAddresses(): array { return [ diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index b80c826e..96d2c6cf 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -346,6 +346,18 @@ public function getSerialConsole($type = Enum::CONSOLE_SERIAL): array return Utils::jsonDecode($response)['console']; } + /** + * Get the console log. + * + * @param int $length Number of lines of console log to grab. + * + * @return string - the console log output + */ + public function getConsoleLog(int $length = 50): string { + $response = $this->execute($this->api->getConsoleLog(), ['id' => $this->id, 'length' => $length]); + return Utils::jsonDecode($response)['output']; + } + /** * Creates an image for the current server. * diff --git a/src/Compute/v2/Params.php b/src/Compute/v2/Params.php index b65df14f..29f0982e 100644 --- a/src/Compute/v2/Params.php +++ b/src/Compute/v2/Params.php @@ -548,4 +548,13 @@ public function quotaSetLimitServerGroupMembers(): array { return $this->quotaSetLimit('server_group_members', 'The number of allowed members for each server group.'); } + + public function consoleLogLength(): array + { + return [ + 'type' => self::INT_TYPE, + 'location' => self::JSON, + 'description' => 'Specifies the length of console log to grab', + ]; + } } From 7eb5d7972e97c3f6296d00fdba42ff44cdb9ebf7 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 5 Sep 2017 23:26:27 -0400 Subject: [PATCH 09/15] Finishing up net-ip-availabilities --- src/Networking/v2/Api.php | 6 +++--- src/Networking/v2/Models/NetworkIpAvailability.php | 6 +++--- src/Networking/v2/Service.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Networking/v2/Api.php b/src/Networking/v2/Api.php index 96228e56..d22c53b5 100644 --- a/src/Networking/v2/Api.php +++ b/src/Networking/v2/Api.php @@ -705,8 +705,8 @@ public function getNetworkIpAvailability() : array { return [ 'method' => 'GET', - 'path' => $this->pathPrefix . '/network-ip-availability/{id}', - 'params' => ['id' => $this->params->idPath()], + 'path' => $this->pathPrefix . '/network-ip-availabilities/{id}', + 'params' => ['id' => $this->params->urlId('network')], ]; } @@ -717,7 +717,7 @@ public function getNetworkIpAvailabilities(): array 'path' => $this->pathPrefix . '/network-ip-availabilities', 'params' => [ 'tenantId' => $this->params->queryTenantId() - ], + ] ]; } diff --git a/src/Networking/v2/Models/NetworkIpAvailability.php b/src/Networking/v2/Models/NetworkIpAvailability.php index dbc886a2..4e97ba4c 100644 --- a/src/Networking/v2/Models/NetworkIpAvailability.php +++ b/src/Networking/v2/Models/NetworkIpAvailability.php @@ -17,7 +17,7 @@ class NetworkIpAvailability extends OperatorResource implements Listable, Retrie use HasWaiterTrait; /** @var string */ - public $networkId; + public $id; /** @var string */ public $networkName; @@ -38,7 +38,7 @@ class NetworkIpAvailability extends OperatorResource implements Listable, Retrie public $subnetIpAvailability; protected $aliases = [ - 'network_id' => 'networkId', + 'network_id' => 'id', 'network_name' => 'networkName', 'tenant_id' => 'tenantId', 'project_id' => 'projectId', @@ -56,7 +56,7 @@ class NetworkIpAvailability extends OperatorResource implements Listable, Retrie */ public function retrieve() { - $response = $this->execute($this->api->getNetworkIpAvailability(), ['newtork_id' => (string)$this->networkId]); + $response = $this->execute($this->api->getNetworkIpAvailability(), ['id' => (string)$this->id]); $this->populateFromResponse($response); } } diff --git a/src/Networking/v2/Service.php b/src/Networking/v2/Service.php index 60ef75c8..a9b580d2 100644 --- a/src/Networking/v2/Service.php +++ b/src/Networking/v2/Service.php @@ -390,13 +390,13 @@ public function createLoadBalancerHealthMonitor(array $options): LoadBalancerHea * empty object, allowing you greater control without the expense of network transactions. To call the remote API * and have the response populate the object, call {@see NetworkIpAvailabilities::retrieve}. * - * @param string $network_id + * @param string $id * * @return NetworkIpAvailability */ - public function getNetworkIpAvailability(string $network_id): NetworkIpAvailability + public function getNetworkIpAvailability(string $id): NetworkIpAvailability { - return $this->model(NetworkIpAvailability::class, ['network_id' => $network_id]); + return $this->model(NetworkIpAvailability::class, ['id' => $id]); } /** From 21462e4bfebc6b8db994fe03ae42a1bd51f7b105 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 6 Sep 2017 00:04:16 -0400 Subject: [PATCH 10/15] Removing marker --- src/Networking/v2/Models/NetworkIpAvailability.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Networking/v2/Models/NetworkIpAvailability.php b/src/Networking/v2/Models/NetworkIpAvailability.php index 4e97ba4c..3fd20be2 100644 --- a/src/Networking/v2/Models/NetworkIpAvailability.php +++ b/src/Networking/v2/Models/NetworkIpAvailability.php @@ -49,7 +49,6 @@ class NetworkIpAvailability extends OperatorResource implements Listable, Retrie protected $resourceKey = 'network_ip_availability'; protected $resourcesKey = 'network_ip_availabilities'; - protected $markerKey = 'network_id'; /** * {@inheritDoc} From 0a294dacd318333b923111dbc9bd88933475fd8a Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 6 Sep 2017 20:34:59 -0400 Subject: [PATCH 11/15] Adding lock/unlock --- src/Compute/v2/Api.php | 24 ++++++++++++++++++++++++ src/Compute/v2/Models/Server.php | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/Compute/v2/Api.php b/src/Compute/v2/Api.php index c44a7d97..aec3b26b 100644 --- a/src/Compute/v2/Api.php +++ b/src/Compute/v2/Api.php @@ -376,6 +376,30 @@ public function unshelveServer() : array ]; } + public function lockServer() : array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'lock' => $this->params->nullAction() + ], + ]; + } + + public function unlockServer() : array + { + return [ + 'method' => 'POST', + 'path' => 'servers/{id}/action', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'unlock' => $this->params->nullAction() + ], + ]; + } + public function rebuildServer(): array { return [ diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index 96d2c6cf..d1c46cc3 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -248,6 +248,28 @@ public function resume() ]); } + /** + * Locks server + */ + public function lock() + { + $this->execute($this->api->lockServer(), [ + 'id' => $this->id, + 'lock' => null + ]); + } + + /** + * Unlocks server + */ + public function unlock() + { + $this->execute($this->api->unlockServer(), [ + 'id' => $this->id, + 'unlock' => null + ]); + } + /** * Rebuilds the server. * From 32538768a485ca019df917c57769117abd8f301a Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 6 Sep 2017 22:41:34 -0400 Subject: [PATCH 12/15] Adding in reset status --- src/BlockStorage/v2/Api.php | 13 +++++++++++++ src/BlockStorage/v2/Models/Volume.php | 13 ++++++++++--- src/BlockStorage/v2/Params.php | 10 ++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/BlockStorage/v2/Api.php b/src/BlockStorage/v2/Api.php index e6547960..1cb3a597 100644 --- a/src/BlockStorage/v2/Api.php +++ b/src/BlockStorage/v2/Api.php @@ -316,4 +316,17 @@ public function extendVolume(): array ]; } + public function resetVolumeStatus(): array + { + return [ + 'method' => 'POST', + 'path' => 'volumes/{id}/action', + 'jsonKey' => 'os-reset_status', + 'params' => [ + 'id' => $this->params->idPath(), + 'status' => $this->params->status() + ], + ]; + } + } diff --git a/src/BlockStorage/v2/Models/Volume.php b/src/BlockStorage/v2/Models/Volume.php index 18b16508..161e988d 100644 --- a/src/BlockStorage/v2/Models/Volume.php +++ b/src/BlockStorage/v2/Models/Volume.php @@ -110,6 +110,14 @@ public function delete() $this->executeWithState($this->api->deleteVolume()); } + public function resetStatus(string $status) { + $response = $this->execute($this->api->resetVolumeStatus(), [ + 'id' => $this->id, + 'status' => $status + ]); + $this->populateFromResponse($response); + } + public function getMetadata(): array { $response = $this->executeWithState($this->api->getVolumeMetadata()); @@ -139,10 +147,9 @@ public function parseMetadata(ResponseInterface $response): array public function extend(int $size_in_gb) { $response = $this->execute($this->api->extendVolume(), [ - 'id' => $this->id, - 'new_size' => $size_in_gb + 'id' => $this->id, + 'new_size' => $size_in_gb ]); - $this->populateFromResponse($response); } } diff --git a/src/BlockStorage/v2/Params.php b/src/BlockStorage/v2/Params.php index 42952693..3baa9c8a 100644 --- a/src/BlockStorage/v2/Params.php +++ b/src/BlockStorage/v2/Params.php @@ -233,4 +233,14 @@ public function nullAction(): array 'required' => true ]; } + + public function status(): array + { + return [ + 'type' => self::STRING_TYPE, + 'location' => self::JSON, + 'required' => true, + 'description' => 'The new status of the volume', + ]; + } } From 1005aa9a643e2dd022ffe6585ea4e0cde620a489 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 6 Sep 2017 22:57:22 -0400 Subject: [PATCH 13/15] Adding in Storage ENUMs --- src/BlockStorage/Enum.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/BlockStorage/Enum.php diff --git a/src/BlockStorage/Enum.php b/src/BlockStorage/Enum.php new file mode 100644 index 00000000..31e4c709 --- /dev/null +++ b/src/BlockStorage/Enum.php @@ -0,0 +1,33 @@ + Date: Sat, 9 Sep 2017 16:38:14 -0400 Subject: [PATCH 14/15] Adding in instance actions --- src/Compute/v2/Api.php | 24 +++++++++++++ src/Compute/v2/Models/InstanceAction.php | 44 ++++++++++++++++++++++++ src/Compute/v2/Models/Server.php | 23 +++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/Compute/v2/Models/InstanceAction.php diff --git a/src/Compute/v2/Api.php b/src/Compute/v2/Api.php index aec3b26b..3b21e48e 100644 --- a/src/Compute/v2/Api.php +++ b/src/Compute/v2/Api.php @@ -874,4 +874,28 @@ public function putQuotaSet(): array ] ]; } + + public function getInstanceActions(): array + { + return [ + 'method' => 'GET', + 'path' => 'servers/{id}/os-instance-actions', + 'params' => [ + 'id' => $this->params->urlId('server') + ] + ]; + } + + public function getInstanceAction(): array + { + return [ + 'method' => 'GET', + 'path' => 'servers/{id}/os-instance-actions/{requestId}', + 'params' => [ + 'id' => $this->params->urlId('server'), + 'requestId' => $this->params->urlId('request') + ] + ]; + } + } diff --git a/src/Compute/v2/Models/InstanceAction.php b/src/Compute/v2/Models/InstanceAction.php new file mode 100644 index 00000000..52e889ca --- /dev/null +++ b/src/Compute/v2/Models/InstanceAction.php @@ -0,0 +1,44 @@ + 'instanceUuid', + 'project_id' => 'projectId', + 'request_id' => 'requestId', + 'start_time' => 'startTime', + 'user_id' => 'userId' + ]; + +} diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index d1c46cc3..e4c9a770 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -563,4 +563,27 @@ public function detachVolume(string $attachmentId) { $this->execute($this->api->deleteVolumeAttachments(), ['id' => $this->id, 'attachmentId' => $attachmentId]); } + + /** + * Get a Generator for the instance actions + * + * @return \Generator + */ + public function listInstanceActions(): \Generator + { + return $this->model(InstanceAction::class)->enumerate($this->api->getInstanceActions(), ['id' => $this->id]); + } + + /** + * Get a specific instance action + * + * @string The request ID of the instance action + * @return InstanceAction + */ + public function getInstanceAction(string $requestId): InstanceAction + { + $response = $this->execute($this->api->getInstanceAction(), ['id' => $this->id, 'requestId' => $requestId]); + + return $this->model(InstanceAction::class)->populateFromResponse($response); + } } From 48113971894371e5e79030bb7e613e4a32baee2a Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Sat, 9 Sep 2017 16:41:52 -0400 Subject: [PATCH 15/15] Fixing CS --- src/BlockStorage/v2/Api.php | 1 - src/BlockStorage/v2/Models/Volume.php | 3 ++- src/Compute/v2/Models/Server.php | 3 ++- src/Networking/v2/Api.php | 1 - src/Networking/v2/Service.php | 1 - 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/BlockStorage/v2/Api.php b/src/BlockStorage/v2/Api.php index 1cb3a597..fe297493 100644 --- a/src/BlockStorage/v2/Api.php +++ b/src/BlockStorage/v2/Api.php @@ -328,5 +328,4 @@ public function resetVolumeStatus(): array ], ]; } - } diff --git a/src/BlockStorage/v2/Models/Volume.php b/src/BlockStorage/v2/Models/Volume.php index 161e988d..e180db8a 100644 --- a/src/BlockStorage/v2/Models/Volume.php +++ b/src/BlockStorage/v2/Models/Volume.php @@ -110,7 +110,8 @@ public function delete() $this->executeWithState($this->api->deleteVolume()); } - public function resetStatus(string $status) { + public function resetStatus(string $status) + { $response = $this->execute($this->api->resetVolumeStatus(), [ 'id' => $this->id, 'status' => $status diff --git a/src/Compute/v2/Models/Server.php b/src/Compute/v2/Models/Server.php index e4c9a770..4894dd82 100644 --- a/src/Compute/v2/Models/Server.php +++ b/src/Compute/v2/Models/Server.php @@ -375,7 +375,8 @@ public function getSerialConsole($type = Enum::CONSOLE_SERIAL): array * * @return string - the console log output */ - public function getConsoleLog(int $length = 50): string { + public function getConsoleLog(int $length = 50): string + { $response = $this->execute($this->api->getConsoleLog(), ['id' => $this->id, 'length' => $length]); return Utils::jsonDecode($response)['output']; } diff --git a/src/Networking/v2/Api.php b/src/Networking/v2/Api.php index d22c53b5..0ac5c23d 100644 --- a/src/Networking/v2/Api.php +++ b/src/Networking/v2/Api.php @@ -720,5 +720,4 @@ public function getNetworkIpAvailabilities(): array ] ]; } - } diff --git a/src/Networking/v2/Service.php b/src/Networking/v2/Service.php index a9b580d2..526e928e 100644 --- a/src/Networking/v2/Service.php +++ b/src/Networking/v2/Service.php @@ -410,5 +410,4 @@ public function listNetworkIpAvailabilities(array $options = []): \Generator { return $this->model(NetworkIpAvailability::class)->enumerate($this->api->getNetworkIpAvailabilities(), $options); } - }