forked from RackHD/on-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdell-wsman-base-job.js
136 lines (122 loc) · 3.97 KB
/
dell-wsman-base-job.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
129
130
131
132
133
134
135
136
// Copyright 2017, DELL, Inc.
'use strict';
var di = require('di');
module.exports = DellWsmanBaseJobFactory;
di.annotate(DellWsmanBaseJobFactory, new di.Provide('Job.Dell.Wsman.Base'));
di.annotate(DellWsmanBaseJobFactory, new di.Inject(
'Job.Base',
'Promise',
'Assert',
'Util',
'Services.Waterline',
'Services.Configuration',
'_',
'Errors'
));
function DellWsmanBaseJobFactory(
BaseJob,
Promise,
assert,
util,
waterline,
configuration,
_,
errors
) {
/**
* @param {Object} options task options object
* @param {Object} context graph context object
* @param {String} taskId running task identifier
* @constructor
*/
function DellWsmanBaseJob(logger, options, context, taskId) {
var self = this;
assert.func(self._initJob);
DellWsmanBaseJob.super_.call(self,
logger,
options,
context,
taskId);
self.logger = logger;
assert.object(self.options);
self.nodeId = self.context.target;
}
util.inherits(DellWsmanBaseJob, BaseJob);
/**
* @memberOf DellWsmanBaseJob
*/
DellWsmanBaseJob.prototype._run = function () {
var self = this;
return Promise.try(function() {
return self._initJob();
})
.then(function() {
if(_.isFunction(self._handleSyncRequest)) {
return self._handleSyncRequest()
.then(function(response) {
if(_.isFunction(self._handleSyncResponse)) {
return self._handleSyncResponse(response);
}
})
.then(function() {
return self._done();
});
} else if(_.isFunction(self._handleAsyncRequest)) {
return self._handleAsyncRequest();
} else {
return self._done();
}
})
.catch(function(err) {
return self._done(err);
});
};
DellWsmanBaseJob.prototype.getIpAddress = function(obm){
var self = this;
if(_.has(obm, 'config.host')) {
return Promise.resolve(obm.config.host);
} else {
return waterline.catalogs.findLatestCatalogOfSource(self.nodeId, 'DeviceSummary')
.then(function(catalog){
if (!_.isEmpty(catalog)) {
return catalog.data.id;
} else {
return waterline.catalogs.findLatestCatalogOfSource(self.nodeId, 'bmc')
.then(function(catalog){
if (!_.isEmpty(catalog)) {
return catalog.data['Ip Address'];
} else {
return undefined;
}
});
}
});
}
};
DellWsmanBaseJob.prototype.checkOBM = function(jobDesc) {
assert.string(jobDesc);
var self = this;
self.logger.info('checkOBM: Self.nodeID: ' + self.nodeId);
return waterline.nodes.findByIdentifier(self.nodeId)
.then(function(result) {
self.nodeType = result.type;
if (self.nodeType !== 'compute') {
self.logger.info(jobDesc + ' is not applicable to node type ' + self.nodeType);
return self.cancel();
}
return waterline.obms.findByNode(self.nodeId, 'dell-wsman-obm-service', true);
}).then(function(obm) {
if (!obm) {
throw new errors.NotFoundError('Failed to find Wsman obm settings');
}
return obm;
});
};
/*
* Print the result for RestAPI Response
*/
DellWsmanBaseJob.prototype.printResult = function (result) {
this.logger.debug(JSON.stringify(result, null, 4));
};
return DellWsmanBaseJob;
}