| @@ 802-831 (lines=30) @@ | ||
| 799 | * @param int $id |
|
| 800 | * @return bool |
|
| 801 | */ |
|
| 802 | public function suspend($id, $deleted = false) |
|
| 803 | { |
|
| 804 | $server = Models\Server::withTrashed()->with('node')->findOrFail($id); |
|
| 805 | ||
| 806 | DB::beginTransaction(); |
|
| 807 | ||
| 808 | try { |
|
| 809 | ||
| 810 | // Already suspended, no need to make more requests. |
|
| 811 | if ($server->suspended) { |
|
| 812 | return true; |
|
| 813 | } |
|
| 814 | ||
| 815 | $server->suspended = 1; |
|
| 816 | $server->save(); |
|
| 817 | ||
| 818 | $server->node->guzzleClient([ |
|
| 819 | 'X-Access-Token' => $server->node->daemonSecret, |
|
| 820 | 'X-Access-Server' => $server->uuid, |
|
| 821 | ])->request('POST', '/server/suspend'); |
|
| 822 | ||
| 823 | return DB::commit(); |
|
| 824 | } catch (TransferException $ex) { |
|
| 825 | DB::rollBack(); |
|
| 826 | throw new DisplayException('An error occured while attempting to contact the remote daemon to suspend this server.', $ex); |
|
| 827 | } catch (\Exception $ex) { |
|
| 828 | DB::rollBack(); |
|
| 829 | throw $ex; |
|
| 830 | } |
|
| 831 | } |
|
| 832 | ||
| 833 | /** |
|
| 834 | * Unsuspends a server instance. |
|
| @@ 838-867 (lines=30) @@ | ||
| 835 | * @param int $id |
|
| 836 | * @return bool |
|
| 837 | */ |
|
| 838 | public function unsuspend($id) |
|
| 839 | { |
|
| 840 | $server = Models\Server::with('node')->findOrFail($id); |
|
| 841 | ||
| 842 | DB::beginTransaction(); |
|
| 843 | ||
| 844 | try { |
|
| 845 | ||
| 846 | // Already unsuspended, no need to make more requests. |
|
| 847 | if ($server->suspended === 0) { |
|
| 848 | return true; |
|
| 849 | } |
|
| 850 | ||
| 851 | $server->suspended = 0; |
|
| 852 | $server->save(); |
|
| 853 | ||
| 854 | $server->node->guzzleClient([ |
|
| 855 | 'X-Access-Token' => $server->node->daemonSecret, |
|
| 856 | 'X-Access-Server' => $server->uuid, |
|
| 857 | ])->request('POST', '/server/unsuspend'); |
|
| 858 | ||
| 859 | return DB::commit(); |
|
| 860 | } catch (TransferException $ex) { |
|
| 861 | DB::rollBack(); |
|
| 862 | throw new DisplayException('An error occured while attempting to contact the remote daemon to un-suspend this server.', $ex); |
|
| 863 | } catch (\Exception $ex) { |
|
| 864 | DB::rollBack(); |
|
| 865 | throw $ex; |
|
| 866 | } |
|
| 867 | } |
|
| 868 | ||
| 869 | public function updateSFTPPassword($id, $password) |
|
| 870 | { |
|