Skip to content

Commit 38a0e07

Browse files
committed
[minor] standardizing statuses across services
1 parent 22204d2 commit 38a0e07

7 files changed

Lines changed: 59 additions & 40 deletions

File tree

lib/pkgcloud/amazon/compute/server.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ Server.prototype._setProperties = function (details) {
2121
if (details.instanceState) {
2222
switch (details.instanceState.name.toUpperCase()) {
2323
case 'PENDING':
24-
this.status = 'PROVISIONING';
24+
this.status = this.STATUS.provisioning;
2525
break;
2626
case 'RUNNING':
27-
this.status = 'RUNNING';
27+
this.status = this.STATUS.running;
2828
break;
2929
case 'STOPPING':
3030
case 'STOPPED':
31-
this.status = 'STOPPED';
31+
this.status = this.STATUS.stopped;
3232
break;
3333
case 'TERMINATED':
34-
this.status = 'TERMINATED';
34+
this.status = this.STATUS.terminated;
3535
break;
3636
default:
37-
this.status = 'UNKNOWN';
37+
this.status = this.STATUS.unknown;
3838
break;
3939
}
4040
}

lib/pkgcloud/azure/compute/server.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,26 @@ Server.prototype._setProperties = function (details) {
4747
case 'BUSYROLE':
4848
case 'INITIALIZING':
4949
case 'BUSY':
50-
this.status = 'PROVISIONING';
50+
this.status = this.STATUS.provisioning;
5151
break;
5252
case 'READYROLE':
5353
case 'READY':
54-
this.status = 'RUNNING';
54+
this.status = this.STATUS.running;
5555
break;
5656
case 'STOPPING':
5757
case 'STOPPED':
5858
case 'STOPPINGROLE':
5959
case 'STOPPINGVM':
6060
case 'STOPPEDVM':
61-
this.status = 'STOPPED';
62-
break;
63-
case 'STOPPINGROLE':
64-
case 'STOPPINGVM':
65-
case 'STOPPEDVM':
66-
this.status = 'STOPPED';
61+
this.status = this.STATUS.stopped;
6762
break;
6863
case 'DELETINGVM':
69-
this.status = 'TERMINATED';
64+
this.status = this.STATUS.terminated;
7065
break;
7166
case 'ROLESTATEUNKNOWN':
7267
case 'UNKNOWN':
7368
default:
74-
this.status = 'UNKNOWN';
69+
this.status = this.STATUS.unknown;
7570
break;
7671
}
7772

@@ -81,25 +76,25 @@ Server.prototype._setProperties = function (details) {
8176
case 'DEPLOYING':
8277
case 'PROVISIONING':
8378
case 'RUNNINGTRANSITIONING':
84-
this.status = 'PROVISIONING';
79+
this.status = this.STATUS.provisioning;
8580
break;
8681
case 'RUNNING':
87-
this.status = 'RUNNING';
82+
this.status = this.STATUS.running;
8883
break;
8984
case 'SUSPENDING':
9085
case 'SUSPENDED':
9186
case 'SUSPENDEDTRANSITIONING':
92-
this.status = 'STOPPED';
87+
this.status = this.STATUS.stopped;
9388
break;
9489
case 'DELETING':
95-
this.status = 'TERMINATED';
90+
this.status = this.STATUS.terminated;
9691
break;
9792
default:
98-
this.status = 'UNKNOWN';
93+
this.status = this.STATUS.unknown;
9994
break;
10095
}
10196
} else {
102-
this.status = 'UNKNOWN';
97+
this.status = this.STATUS.unknown;
10398
}
10499

105100
var addresses = { private: [], public: [] };

lib/pkgcloud/common/status.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* status.js: Standardized statuses for different services
3+
*
4+
* (C) 2011-2012 Nodejitsu Inc.
5+
*
6+
*/
7+
8+
exports.compute = {
9+
error: 'ERROR',
10+
provisioning: 'PROVISIONING',
11+
reboot: 'REBOOT',
12+
running: 'RUNNING',
13+
stopped: 'STOPPED',
14+
terminated: 'TERMINATED',
15+
unknown: 'UNKNOWN',
16+
updating: 'UPDATING'
17+
};

lib/pkgcloud/core/compute/server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
var utile = require('utile'),
9-
model = require('../base/model');
9+
model = require('../base/model'),
10+
computeStatus = require('../../common/status').compute;
1011

1112
var Server = exports.Server = function (client, details) {
1213
model.Model.call(this, client, details);
@@ -38,3 +39,5 @@ Server.prototype.resize = function () {
3839
var args = [this].concat(Array.prototype.slice.call(arguments));
3940
this.client.resizeServer.apply(this.client, args);
4041
};
42+
43+
Server.prototype.STATUS = computeStatus;

lib/pkgcloud/joyent/compute/server.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
var utile = require('utile'),
99
compute = require('../../core/compute'),
10-
base = require('../../core/compute/server');
10+
base = require('../../core/compute/server'),
11+
computeStatus = require('../../common/status').compute;
1112

1213
var Server = exports.Server = function Server(client, details) {
1314
base.Server.call(this, client, details);
@@ -22,17 +23,17 @@ Server.prototype._setProperties = function (details) {
2223
if (details.state) {
2324
switch (details.state.toUpperCase()) {
2425
case 'PROVISIONING':
25-
this.status = "PROVISIONING";
26+
this.status = this.STATUS.provisioning;
2627
break;
2728
case 'RUNNING':
28-
this.status = "RUNNING";
29+
this.status = this.STATUS.running;
2930
break;
3031
case 'STOPPING':
3132
case 'STOPPED':
32-
this.status = "STOPPED";
33+
this.status = this.STATUS.stopped;
3334
break;
3435
default:
35-
this.status = "UNKNOWN";
36+
this.status = this.STATUS.unknown;
3637
break;
3738
}
3839
}

lib/pkgcloud/openstack/compute/server.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ Server.prototype._setProperties = function (details) {
2525
switch (details.status.toUpperCase()) {
2626
case 'BUILD':
2727
case 'REBUILD':
28-
this.status = "PROVISIONING";
28+
this.status = this.STATUS.provisioning;
2929
break;
3030
case 'ACTIVE':
31-
this.status = "RUNNING";
31+
this.status = this.STATUS.running;
3232
break;
3333
case 'SUSPENDED':
3434
case 'SHUTOFF':
35-
this.status = "STOPPED";
35+
this.status = this.STATUS.stopped;
3636
break;
3737
case 'REBOOT':
3838
case 'HARD_REBOOT':
39-
this.status = "REBOOT";
39+
this.status = this.STATUS.reboot;
4040
break;
4141
case 'QUEUE_RESIZE':
4242
case 'PREP_RESIZE':
@@ -46,14 +46,14 @@ Server.prototype._setProperties = function (details) {
4646
case 'SHARE_IP_NO_CONFIG':
4747
case 'DELETE_IP':
4848
case 'PASSWORD':
49-
this.status = "UPDATING";
49+
this.status = this.STATUS.updating;
5050
break;
5151
case 'RESCUE':
5252
case 'ERROR':
53-
this.status = 'ERROR';
53+
this.status = this.STATUS.error;
5454
break;
5555
default:
56-
this.status = "UNKNOWN";
56+
this.status = this.STATUS.unknown;
5757
break;
5858
}
5959
}

lib/pkgcloud/rackspace/database/instance.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
var utile = require('utile'),
9-
model = require('../../core/base/model');
9+
model = require('../../core/base/model'),
10+
computeStatus = require('../../common/status').compute;
1011

1112
var Instance = exports.Instance = function Instance(client, details) {
1213
model.Model.call(this, client, details);
@@ -18,6 +19,8 @@ Instance.prototype.refresh = function (callback) {
1819
this.client.getInstance(this, callback);
1920
};
2021

22+
Instance.prototype.STATUS = computeStatus;
23+
2124
Instance.prototype._setProperties = function (details) {
2225
this.id = details.id;
2326
this.name = details.name;
@@ -32,22 +35,22 @@ Instance.prototype._setProperties = function (details) {
3235
case 'BUILD':
3336
case 'REBOOT':
3437
case 'RESIZE':
35-
this.status = "PROVISIONING";
38+
this.status = this.STATUS.provisioning;
3639
break;
3740
case 'RUNNING':
3841
case 'ACTIVE': // Change for keep consistency
39-
this.status = "RUNNING";
42+
this.status = this.STATUS.running;
4043
break;
4144
case 'STOPPING':
4245
case 'STOPPED':
4346
case 'SHUTDOWN':
44-
this.status = "STOPPED";
47+
this.status = this.STATUS.stopped;
4548
break;
4649
case 'FAILED':
47-
this.status = 'FAILED';
50+
this.status = this.STATUS.error;
4851
break;
4952
default:
50-
this.status = "UNKNOWN";
53+
this.status = this.STATUS.unknown;
5154
break;
5255
}
5356
}

0 commit comments

Comments
 (0)