@@ -20,6 +20,7 @@ const DEFAULT_SIZE: string = '1gb';
2020const STATUS_CODES : { [ k : string ] : string ; } = {
2121 'START' : 'Starting provisioner' ,
2222 'STOP' : 'Stopping cloud server' ,
23+ 'REBOOT' : 'Rebooting cloud server' ,
2324 'OAUTH_INIT' : 'Initializing oauth flow' ,
2425 'OAUTH_ERROR' : 'Error getting oauth token' ,
2526 'OAUTH_COMPLETE' : 'Got oauth token' ,
@@ -157,6 +158,36 @@ class Provisioner {
157158 } ) ;
158159 }
159160
161+ /**
162+ * Reboots a droplet with this name
163+ * @param {String } droplet name, as a string
164+ * @return {Promise.<void> }, resolves after waiting for reboot action
165+ * to complete or rejects if droplet doesn't exist
166+ */
167+ public reboot = ( name : string ) : Promise < void > => {
168+ this . sendStatus_ ( 'REBOOT' ) ;
169+ return this . doOAuth_ ( ) . then ( ( oauthObj : any ) => {
170+ this . state_ . oauth = oauthObj ;
171+ } ) . then ( ( ) => {
172+ return this . getDroplet_ ( name ) ;
173+ } ) . then ( ( resp : any ) => {
174+ this . state_ . cloud = this . state_ . cloud || { } ;
175+ this . state_ . cloud . vm = this . state_ . cloud . vm || resp . droplet ;
176+ // Make sure there are no actions in progress before rebooting
177+ this . sendStatus_ ( 'CLOUD_WAITING_VM' ) ;
178+ return this . waitDigitalOceanActions_ ( ) ;
179+ } ) . then ( ( ) => {
180+ console . log ( 'Rebooting cloud server' ) ;
181+ return this . doRequest_ ( 'POST' , 'droplets/' + this . state_ . cloud . vm . id + '/actions' , JSON . stringify ( {
182+ type : 'reboot' ,
183+ } ) ) ;
184+ } ) . then ( ( unused : any ) => {
185+ // Wait until reboot server is completed
186+ this . sendStatus_ ( 'CLOUD_WAITING_VM' ) ;
187+ return this . waitDigitalOceanActions_ ( ) ;
188+ } ) ;
189+ }
190+
160191 /**
161192 * Finds a droplet with this name
162193 * @param {String } droplet name, as a string
0 commit comments