Skip to content

Commit 40f7ec9

Browse files
authored
Merge pull request #196 from laszlof/add-server-resetstate
Add Server::resetState method
2 parents fa0afa0 + d136797 commit 40f7ec9

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

doc/services/compute/v2/servers.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ This operation will replace the root password for a server.
218218
.. sample:: compute/v2/servers/change_server_password.php
219219
.. refdoc:: OpenStack/Compute/v2/Models/Server.html#method_changePassword
220220

221+
Reset server state
222+
------------------
223+
224+
This operation will reset the state of the server.
225+
226+
.. sample:: compute/v2/servers/reset_server_state.php
227+
.. refdoc:: OpenStack/Compute/v2/Models/Server.html#method_resetState
228+
221229
Reboot server
222230
-------------
223231

@@ -302,4 +310,4 @@ Further links
302310
-------------
303311

304312
* Reference docs for Server class
305-
* API docs
313+
* API docs
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
$openstack = new OpenStack\OpenStack([
6+
'authUrl' => '{authUrl}',
7+
'region' => '{region}',
8+
'user' => [
9+
'id' => '{userId}',
10+
'password' => '{password}'
11+
],
12+
'scope' => ['project' => ['id' => '{projectId}']]
13+
]);
14+
15+
$compute = $openstack->computeV2(['region' => '{region}']);
16+
17+
$server = $compute->getServer([
18+
'id' => '{serverId}',
19+
]);
20+
21+
$server->resetState();

src/Compute/v2/Api.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ public function changeServerPassword(): array
279279
];
280280
}
281281

282+
283+
public function resetServerState(): array
284+
{
285+
return [
286+
'method' => 'POST',
287+
'path' => 'servers/{id}/action',
288+
'params' => [
289+
'id' => $this->params->urlId('server'),
290+
'resetState' => $this->params->resetState()
291+
]
292+
];
293+
}
294+
282295
public function rebootServer(): array
283296
{
284297
return [

src/Compute/v2/Models/Server.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ public function changePassword(string $newPassword)
183183
]);
184184
}
185185

186+
/**
187+
* Issue a resetState call to the server.
188+
*/
189+
public function resetState()
190+
{
191+
$this->execute($this->api->resetServerState(), [
192+
'id' => $this->id,
193+
'resetState' => ['state' => 'active']
194+
]);
195+
}
196+
186197
/**
187198
* Reboots the server.
188199
*

src/Compute/v2/Params.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ public function urlId(string $type): array
1515
]);
1616
}
1717

18+
public function resetState(): array
19+
{
20+
return [
21+
'type' => self::OBJECT_TYPE,
22+
'location' => self::JSON,
23+
'sentAs' => 'os-resetState',
24+
'required' => true,
25+
'properties' => [
26+
'state' => ['type' => self::STRING_TYPE]
27+
]
28+
];
29+
}
30+
1831
public function minDisk(): array
1932
{
2033
return [

0 commit comments

Comments
 (0)