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