Add support for suspension
This commit is contained in:
parent
3ca7e4d578
commit
38eae88bd0
9 changed files with 223 additions and 25 deletions
|
@ -728,9 +728,31 @@ class ServerRepository
|
|||
*/
|
||||
public function suspend($id)
|
||||
{
|
||||
// @TODO: Implement logic; not doing it now since that is outside of the
|
||||
// scope of this API brance.
|
||||
return true;
|
||||
$server = Models\Server::findOrFail($id);
|
||||
$node = Models\Node::findOrFail($server->node);
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$server->suspended = 1;
|
||||
$server->save();
|
||||
|
||||
$client = Models\Node::guzzleRequest($server->node);
|
||||
$client->request('POST', '/server/suspend', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
'X-Access-Server' => $server->uuid
|
||||
]
|
||||
]);
|
||||
|
||||
return DB::commit();
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('An error occured while attempting to suspend this server.', $ex);
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -740,9 +762,31 @@ class ServerRepository
|
|||
*/
|
||||
public function unsuspend($id)
|
||||
{
|
||||
// @TODO: Implement logic; not doing it now since that is outside of the
|
||||
// scope of this API brance.
|
||||
return true;
|
||||
$server = Models\Server::findOrFail($id);
|
||||
$node = Models\Node::findOrFail($server->node);
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$server->suspended = 0;
|
||||
$server->save();
|
||||
|
||||
$client = Models\Node::guzzleRequest($server->node);
|
||||
$client->request('POST', '/server/unsuspend', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
'X-Access-Server' => $server->uuid
|
||||
]
|
||||
]);
|
||||
|
||||
return DB::commit();
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('An error occured while attempting to un-suspend this server.', $ex);
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateSFTPPassword($id, $password)
|
||||
|
|
Reference in a new issue