Skip to content

Commit e292ff6

Browse files
committed
Added reboot server functionality
1 parent 3e38f80 commit e292ff6

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/cloud/digitalocean/freedom-module.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
"message": "string"
4747
}
4848
},
49+
"reboot": {
50+
"type": "method",
51+
"value": [ "string" ],
52+
"ret": [],
53+
"err": {
54+
"errcode": "string",
55+
"message": "string"
56+
}
57+
},
4958
"status": {
5059
"type": "event",
5160
"value": {

src/cloud/digitalocean/provisioner.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const DEFAULT_SIZE: string = '1gb';
2020
const 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

Comments
 (0)