| @@ 859-888 (lines=30) @@ | ||
| 856 | * @param int $id |
|
| 857 | * @return bool |
|
| 858 | */ |
|
| 859 | public function suspend($id, $deleted = false) |
|
| 860 | { |
|
| 861 | $server = Models\Server::withTrashed()->with('node')->findOrFail($id); |
|
| 862 | ||
| 863 | DB::beginTransaction(); |
|
| 864 | ||
| 865 | try { |
|
| 866 | ||
| 867 | // Already suspended, no need to make more requests. |
|
| 868 | if ($server->suspended) { |
|
| 869 | return true; |
|
| 870 | } |
|
| 871 | ||
| 872 | $server->suspended = 1; |
|
| 873 | $server->save(); |
|
| 874 | ||
| 875 | $server->node->guzzleClient([ |
|
| 876 | 'X-Access-Token' => $server->node->daemonSecret, |
|
| 877 | 'X-Access-Server' => $server->uuid, |
|
| 878 | ])->request('POST', '/server/suspend'); |
|
| 879 | ||
| 880 | return DB::commit(); |
|
| 881 | } catch (TransferException $ex) { |
|
| 882 | DB::rollBack(); |
|
| 883 | throw new DisplayException('An error occured while attempting to contact the remote daemon to suspend this server.', $ex); |
|
| 884 | } catch (\Exception $ex) { |
|
| 885 | DB::rollBack(); |
|
| 886 | throw $ex; |
|
| 887 | } |
|
| 888 | } |
|
| 889 | ||
| 890 | /** |
|
| 891 | * Unsuspends a server instance. |
|
| @@ 895-924 (lines=30) @@ | ||
| 892 | * @param int $id |
|
| 893 | * @return bool |
|
| 894 | */ |
|
| 895 | public function unsuspend($id) |
|
| 896 | { |
|
| 897 | $server = Models\Server::with('node')->findOrFail($id); |
|
| 898 | ||
| 899 | DB::beginTransaction(); |
|
| 900 | ||
| 901 | try { |
|
| 902 | ||
| 903 | // Already unsuspended, no need to make more requests. |
|
| 904 | if ($server->suspended === 0) { |
|
| 905 | return true; |
|
| 906 | } |
|
| 907 | ||
| 908 | $server->suspended = 0; |
|
| 909 | $server->save(); |
|
| 910 | ||
| 911 | $server->node->guzzleClient([ |
|
| 912 | 'X-Access-Token' => $server->node->daemonSecret, |
|
| 913 | 'X-Access-Server' => $server->uuid, |
|
| 914 | ])->request('POST', '/server/unsuspend'); |
|
| 915 | ||
| 916 | return DB::commit(); |
|
| 917 | } catch (TransferException $ex) { |
|
| 918 | DB::rollBack(); |
|
| 919 | throw new DisplayException('An error occured while attempting to contact the remote daemon to un-suspend this server.', $ex); |
|
| 920 | } catch (\Exception $ex) { |
|
| 921 | DB::rollBack(); |
|
| 922 | throw $ex; |
|
| 923 | } |
|
| 924 | } |
|
| 925 | ||
| 926 | public function updateSFTPPassword($id, $password) |
|
| 927 | { |
|