forked from pkgcloud/pkgcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
69 lines (59 loc) · 1.78 KB
/
server.js
File metadata and controls
69 lines (59 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* server.js: AWS Server
*
* (C) 2012 Charlie Robbins, Ken Perkins, Ross Kukulinski & the Contributors.
*
*/
var util = require('util'),
base = require('../../core/compute/server'),
_ = require('lodash');
var Server = exports.Server = function Server(client, details) {
base.Server.call(this, client, details);
};
util.inherits(Server, base.Server);
Server.prototype._setProperties = function (details) {
this.id = details.InstanceId || details.instanceId;
this.name = details.name || (details.meta || {}).name;
if (details.State) {
switch (details.State.Name.toUpperCase()) {
case 'PENDING':
this.status = this.STATUS.provisioning;
break;
case 'RUNNING':
this.status = this.STATUS.running;
break;
case 'STOPPING':
case 'STOPPED':
this.status = this.STATUS.stopped;
break;
case 'TERMINATED':
this.status = this.STATUS.terminated;
break;
default:
this.status = this.STATUS.unknown;
break;
}
}
var addresses = { private: [], public: [] };
['PublicIpAddress', 'PublicDnsName'].forEach(function (prop) {
if (typeof details[prop] === 'string') {
addresses.public.push(details[prop]);
}
});
['PrivateIpAddress', 'PrivateDnsName'].forEach(function (prop) {
if (typeof details[prop] === 'string') {
addresses.private.push(details[prop]);
}
});
//
// AWS specific
//
this.imageId = details.ImageId;
this.addresses = details.Addresses = addresses;
this.launchTime = details.LaunchTime;
this.flavorId = details.InstanceType;
this.original = this.amazon = details;
};
Server.prototype.toJSON = function () {
return _.pick(this, ['id', 'name', 'status', 'image', 'addresses', 'launchTime', 'flavor' ]);
};