@@ -205,7 +205,7 @@ public function create(array $data)
205205 'uuidShort ' => $ uuid ->generateShort ('servers ' , 'uuidShort ' , $ generatedUuid ),
206206 'node ' => $ data ['node ' ],
207207 'name ' => $ data ['name ' ],
208- 'active ' => 1 ,
208+ 'suspended ' => 0 ,
209209 'owner ' => $ user ->id ,
210210 'memory ' => $ data ['memory ' ],
211211 'swap ' => $ data ['swap ' ],
@@ -728,9 +728,31 @@ public function toggleInstall($id)
728728 */
729729 public function suspend ($ id )
730730 {
731- // @TODO: Implement logic; not doing it now since that is outside of the
732- // scope of this API brance.
733- return true ;
731+ $ server = Models \Server::findOrFail ($ id );
732+ $ node = Models \Node::findOrFail ($ server ->node );
733+
734+ DB ::beginTransaction ();
735+
736+ try {
737+ $ server ->suspended = 1 ;
738+ $ server ->save ();
739+
740+ $ client = Models \Node::guzzleRequest ($ server ->node );
741+ $ client ->request ('POST ' , '/server/suspend ' , [
742+ 'headers ' => [
743+ 'X-Access-Token ' => $ node ->daemonSecret ,
744+ 'X-Access-Server ' => $ server ->uuid
745+ ]
746+ ]);
747+
748+ return DB ::commit ();
749+ } catch (\GuzzleHttp \Exception \TransferException $ ex ) {
750+ DB ::rollBack ();
751+ throw new DisplayException ('An error occured while attempting to suspend this server. ' , $ ex );
752+ } catch (\Exception $ ex ) {
753+ DB ::rollBack ();
754+ throw $ ex ;
755+ }
734756 }
735757
736758 /**
@@ -740,9 +762,31 @@ public function suspend($id)
740762 */
741763 public function unsuspend ($ id )
742764 {
743- // @TODO: Implement logic; not doing it now since that is outside of the
744- // scope of this API brance.
745- return true ;
765+ $ server = Models \Server::findOrFail ($ id );
766+ $ node = Models \Node::findOrFail ($ server ->node );
767+
768+ DB ::beginTransaction ();
769+
770+ try {
771+ $ server ->suspended = 0 ;
772+ $ server ->save ();
773+
774+ $ client = Models \Node::guzzleRequest ($ server ->node );
775+ $ client ->request ('POST ' , '/server/unsuspend ' , [
776+ 'headers ' => [
777+ 'X-Access-Token ' => $ node ->daemonSecret ,
778+ 'X-Access-Server ' => $ server ->uuid
779+ ]
780+ ]);
781+
782+ return DB ::commit ();
783+ } catch (\GuzzleHttp \Exception \TransferException $ ex ) {
784+ DB ::rollBack ();
785+ throw new DisplayException ('An error occured while attempting to un-suspend this server. ' , $ ex );
786+ } catch (\Exception $ ex ) {
787+ DB ::rollBack ();
788+ throw $ ex ;
789+ }
746790 }
747791
748792 public function updateSFTPPassword ($ id , $ password )
0 commit comments