forked from RackHD/on-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoop-obm-service.js
62 lines (48 loc) · 1.85 KB
/
noop-obm-service.js
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
// Copyright 2015, EMC, Inc.
'use strict';
var di = require('di'),
util = require('util');
module.exports = noopObmServiceFactory;
di.annotate(noopObmServiceFactory, new di.Provide('noop-obm-service'));
di.annotate(noopObmServiceFactory, new di.Inject('Promise', 'lru-cache', 'OBM.base'));
function noopObmServiceFactory(Promise, lruCache, BaseObmService) {
function NoopObmService() {
BaseObmService.call(this, {});
this.requiredKeys = [];
this.nodePowerStates = NoopObmService.nodePowerStates;
}
util.inherits(NoopObmService, BaseObmService);
NoopObmService.nodePowerStates = lruCache({ max: 100 });
NoopObmService.prototype.reboot = function() {
return Promise.resolve(true);
};
NoopObmService.prototype.powerOn = function(nodeId) {
if (nodeId && nodeId.toString) {
this.nodePowerStates.set(nodeId.toString(), true);
}
return Promise.resolve(true);
};
NoopObmService.prototype.powerOff = function(nodeId) {
if (nodeId && nodeId.toString) {
this.nodePowerStates.set(nodeId.toString(), false);
}
return Promise.resolve(true);
};
NoopObmService.prototype.powerStatus = function(nodeId) {
var result = false;
if (nodeId && nodeId.toString) {
result = this.nodePowerStates.get(nodeId.toString());
// Default noop node states to OFF if we haven't seen this nodeId before.
result = result !== undefined ? result : true;
}
return Promise.resolve(result);
};
NoopObmService.prototype._runInternal = function() {};
NoopObmService.prototype.setBootPxe = function() {
return Promise.resolve(true);
};
NoopObmService.create = function(options) {
return BaseObmService.create(NoopObmService, options);
};
return NoopObmService;
}