Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion doc/services/compute/v2/servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------

Expand Down Expand Up @@ -302,4 +310,4 @@ Further links
-------------

* Reference docs for Server class
* API docs
* API docs
21 changes: 21 additions & 0 deletions samples/compute/v2/servers/reset_server_state.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => [
'id' => '{userId}',
'password' => '{password}'
],
'scope' => ['project' => ['id' => '{projectId}']]
]);

$compute = $openstack->computeV2(['region' => '{region}']);

$server = $compute->getServer([
'id' => '{serverId}',
]);

$server->resetState();
13 changes: 13 additions & 0 deletions src/Compute/v2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->resetState()
]
];
}

public function rebootServer(): array
{
return [
Expand Down
11 changes: 11 additions & 0 deletions src/Compute/v2/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ public function changePassword(string $newPassword)
]);
}

/**
* Issue a resetState call to the server.
*/
public function resetState()
{
$this->execute($this->api->resetServerState(), [
'id' => $this->id,
'resetState' => ['state' => 'active']
]);
}

/**
* Reboots the server.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Compute/v2/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ public function urlId(string $type): array
]);
}

public function resetState(): 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 [
Expand Down