forked from RackHD/on-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdell-wsman-powerthermal.js
128 lines (110 loc) · 3.46 KB
/
dell-wsman-powerthermal.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//Copyright 2016, EMC, Inc.
'use strict';
var di = require('di');
module.exports = wsmanPowerThermalToolJobFactory;
di.annotate(wsmanPowerThermalToolJobFactory, new di.Provide('Job.Dell.PowerThermalTool'));
di.annotate(wsmanPowerThermalToolJobFactory, new di.Inject(
'Job.Dell.Wsman.Base',
'JobUtils.WsmanTool',
'Logger',
'Util',
'Assert',
'Errors',
'Promise',
'_',
'Services.Encryption',
'Services.Lookup',
'Constants',
'Services.Waterline',
'Services.Configuration'
));
function wsmanPowerThermalToolJobFactory(
BaseJob,
WsmanTool,
Logger,
util,
assert,
errors,
Promise,
_,
encryption,
lookup,
Constants,
waterline,
configuration
)
{
var logger = Logger.initialize(wsmanPowerThermalToolJobFactory);
/**
*
* @param {Object} options
* @param {Object} context
* @param {String} taskId
* @constructor
*/
function PowerThermalTool(options, context, taskId) {
PowerThermalTool.super_.call(this, logger, options, context, taskId);
this.nodeId = this.context.target;
this.powerCap = options.powerCap;
this.enableCapping= ((options.enableCapping && options.enableCapping === true) ? true:false); //jshint ignore:line
this.dellConfigs = undefined;
}
util.inherits(PowerThermalTool, BaseJob);
/**
* Initialize basic configuration for the job
*
*/
PowerThermalTool.prototype._initJob = function () {
var self = this;
logger.info("initializing power monitoring capping job");
self.dellConfigs = configuration.get('dell');
if (!self.dellConfigs ||
!self.dellConfigs.services.powerThermalMonitoring){
throw new errors.NotFoundError(
'Dell web service configuration is not defined in wsmanConfig.json.');
}
self.powerThermalConfigs=self.dellConfigs.services.powerThermalMonitoring;
self.apiServer=self.powerThermalConfigs.host;
return self.checkOBM('PowerThermal')
.then(function(obm) {
self.oobServerAddress=obm.config.host;
self.userConfig={
"user" : obm.config.user,
"password" : encryption.decrypt(obm.config.password)
};
});
};
PowerThermalTool.prototype._handleSyncRequest = function() {
var self = this;
var apiHost=self.apiServer;
var path=self.powerThermalConfigs.endpoints.powerthermal;
var method='PUT';
if (!self.userConfig){
throw ("No user configuration data provided ");
}
var data= {
"serverAddress": self.oobServerAddress,
"userName" :self.userConfig.user,
"password" :self.userConfig.password,
"powerCap": self.powerCap,
"enableCapping" :self.enableCapping
};
return self.clientRequest(apiHost,path,method,data);
};
/**
* Client Request API
*
*
*/
PowerThermalTool.prototype.clientRequest = function(host, path, method, data) {
var wsman = new WsmanTool(host, {
verifySSL: false,
recvTimeoutMs: 60000
});
return wsman.clientRequest(path, method, data, 'IP is NOT valid or httpStatusCode > 206.')
.then(function(response) {
return response.body;
});
};
return PowerThermalTool;
}