-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,065 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
var di = require('di'); | ||
|
||
module.exports = DellWsmanRAIDFactory; | ||
di.annotate(DellWsmanRAIDFactory, new di.Provide('Job.Dell.Wsman.RAID')); | ||
di.annotate(DellWsmanRAIDFactory, new di.Inject( | ||
'Job.Dell.Wsman.Base', | ||
'JobUtils.WsmanTool', | ||
'Logger', | ||
'Assert', | ||
'Util', | ||
'Services.Configuration', | ||
'Errors', | ||
'Services.Encryption', | ||
'validator', | ||
'JobUtils.Smb2Client' | ||
)); | ||
|
||
function DellWsmanRAIDFactory( | ||
BaseJob, | ||
WsmanTool, | ||
Logger, | ||
assert, | ||
util, | ||
configuration, | ||
errors, | ||
encryption, | ||
validator, | ||
Smb2Client | ||
) { | ||
var logger = Logger.initialize(DellWsmanRAIDFactory); | ||
|
||
function DellWsmanRAIDJob(options, context, taskId) { | ||
DellWsmanRAIDJob.super_.call(this, logger, options, context, taskId); | ||
assert.object(this.options); | ||
this.nodeId = this.context.target; | ||
} | ||
|
||
util.inherits(DellWsmanRAIDJob, BaseJob); | ||
|
||
DellWsmanRAIDJob.prototype._initJob = function () { | ||
var self = this; | ||
self.dell = configuration.get('dell'); | ||
if (!self.dell || !self.dell.services || !self.dell.services.configuration) { | ||
throw new errors.NotFoundError('Dell SCP web service is not defined in smiConfig.json.'); | ||
} | ||
if(!self.dell.shareFolder){ | ||
throw new errors.NotFoundError('The shareFolder is not defined in smiConfig.json'); | ||
} | ||
}; | ||
|
||
DellWsmanRAIDJob.prototype._handleSyncRequest = function() { | ||
var self = this; | ||
return self.checkOBM('SCP RAID operation') | ||
.then(function(obm){ | ||
return self.doRAIDoperation(obm); | ||
}); | ||
}; | ||
|
||
DellWsmanRAIDJob.prototype._handleSyncResponse = function(response) { | ||
var self = this; | ||
var json = JSON.parse(response.body); | ||
logger.info('Status from SCP Microservice for RAID operation: ' + json["status"]); | ||
if (json["status"] === "OK") { | ||
if(self.options.removeXmlFile){ | ||
var smb2Client = new Smb2Client( | ||
self.dell.shareFolder.address, | ||
self.dell.shareFolder.shareName, | ||
self.dell.shareFolder.username, | ||
self.dell.shareFolder.password | ||
); | ||
smb2Client.deleteFile(self.context.graphId + ".xml").then(function(){ | ||
return response; | ||
}).catch(function(error){ | ||
logger.error("Errors occur "+ error); | ||
}); | ||
}else{ | ||
return response; | ||
} | ||
} else { | ||
throw new Error("Failed to do RAID operations"); | ||
} | ||
}; | ||
|
||
DellWsmanRAIDJob.prototype.doRAIDoperation = function(obm) { | ||
if (!validator.isIP(obm.config.host)) { | ||
throw new Error('Invalid ServerIP'); | ||
} | ||
|
||
var self = this; | ||
var data = { | ||
"fileName": self.context.graphId + ".xml", | ||
"serverIP": obm.config.host, | ||
"serverPassword": obm.config.user, | ||
"serverUsername": encryption.decrypt(obm.config.password), | ||
"shareAddress": self.dell.shareFolder.address, | ||
"shareName": self.dell.shareFolder.shareName, | ||
"sharePassword": self.dell.shareFolder.password, | ||
"shareType": self.dell.shareFolder.shareType, | ||
"shutdownType": self.options.shutdownType, | ||
"shareUsername": self.dell.shareFolder.username | ||
}; | ||
|
||
var wsman = new WsmanTool(self.dell.gateway, { | ||
verifySSl: false, | ||
recvTimeoutMs: 60000 | ||
}); | ||
return wsman.clientRequest( | ||
self.dell.services.configuration.import, | ||
"POST", | ||
data | ||
); | ||
}; | ||
|
||
return DellWsmanRAIDJob; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
var di = require('di'), | ||
xmldom = require('xmldom').DOMParser; | ||
module.exports = WsmanDeleteVolumeXmlFactory; | ||
di.annotate(WsmanDeleteVolumeXmlFactory, new di.Provide('Job.Dell.Wsman.Delete.Volume.UpdateXml')); | ||
di.annotate(WsmanDeleteVolumeXmlFactory, new di.Inject( | ||
'Job.Base', | ||
'Logger', | ||
'Assert', | ||
'Util', | ||
'Services.Configuration', | ||
'Errors', | ||
'JobUtils.Smb2Client' | ||
)); | ||
|
||
function WsmanDeleteVolumeXmlFactory( | ||
BaseJob, | ||
Logger, | ||
assert, | ||
util, | ||
configuration, | ||
errors, | ||
Smb2Client | ||
) { | ||
var logger = Logger.initialize(WsmanDeleteVolumeXmlFactory); | ||
|
||
function WsmanDeleteVolumeXmlJob(options, context, taskId) { | ||
WsmanDeleteVolumeXmlJob.super_.call(this, logger, options, context, taskId); | ||
assert.object(this.options); | ||
this.nodeId = this.context.target; | ||
} | ||
|
||
util.inherits(WsmanDeleteVolumeXmlJob, BaseJob); | ||
|
||
WsmanDeleteVolumeXmlJob.prototype._run = function () { | ||
var self = this; | ||
self.dell = configuration.get('dell'); | ||
if (!self.dell.shareFolder) { | ||
throw new errors.NotFoundError('The shareFolder is not defined in smiConfig.json.'); | ||
} | ||
if(self.options.volumeId === ""){ | ||
throw new errors.NotFoundError('The volumeId can not be empty string.'); | ||
} | ||
self.parseXmlFileForRAID(); | ||
}; | ||
|
||
WsmanDeleteVolumeXmlJob.prototype.parseXmlFileForRAID = function(){ | ||
logger.info("Parse xml file for delete volume operation."); | ||
var self = this; | ||
var smb2Client = new Smb2Client( | ||
self.dell.shareFolder.address, | ||
self.dell.shareFolder.shareName, | ||
self.dell.shareFolder.username, | ||
self.dell.shareFolder.password | ||
); | ||
var fileName = self.context.graphId +".xml"; | ||
var volumeId = self.options.volumeId; | ||
return smb2Client.readFile(fileName).then(function(data){ | ||
var xmlFile = String.fromCharCode.apply(null, new Uint16Array(data)); | ||
var doc = new xmldom().parseFromString(xmlFile, 'application/xml'); | ||
var components = doc.getElementsByTagName('Component'); | ||
var deleteIndex = []; | ||
|
||
for(var i = 0; i < components.length; i++){ //jshint ignore:line | ||
var fqdd = components[i].getAttribute('FQDD'); | ||
if(fqdd.split('.')[0] === 'Disk' && fqdd.indexOf('Enclosure') === -1){ | ||
if(fqdd === volumeId){ | ||
components[i].getElementsByTagName('Attribute')[0].childNodes[0].textContent = "Delete"; | ||
}else{ | ||
deleteIndex.push(i); | ||
} | ||
} | ||
} | ||
for(var i = 0; i < deleteIndex.length; i++){ // jshint ignore:line | ||
doc.documentElement.removeChild(components[deleteIndex[i]]); | ||
} | ||
return doc; | ||
}).then(function(doc){ | ||
return smb2Client.writeFile(fileName, doc); | ||
}).then(function(){ | ||
self._done(); | ||
}).catch(function(error){ | ||
logger.error('Error occurs', error); | ||
self._done(error); | ||
}); | ||
}; | ||
|
||
return WsmanDeleteVolumeXmlJob; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
var di = require('di'); | ||
module.exports = WsmanGetComponentFactory; | ||
di.annotate(WsmanGetComponentFactory, new di.Provide('Job.Dell.Wsman.GetXml')); | ||
di.annotate(WsmanGetComponentFactory, new di.Inject( | ||
'Job.Dell.Wsman.Base', | ||
'JobUtils.WsmanTool', | ||
'Logger', | ||
'Assert', | ||
'Util', | ||
'Services.Configuration', | ||
'Errors', | ||
'Services.Encryption', | ||
'validator' | ||
)); | ||
|
||
function WsmanGetComponentFactory( | ||
BaseJob, | ||
WsmanTool, | ||
Logger, | ||
assert, | ||
util, | ||
configuration, | ||
errors, | ||
encryption, | ||
validator | ||
) { | ||
var logger = Logger.initialize(WsmanGetComponentFactory); | ||
|
||
function WsmanGetComponentJob(options, context, taskId) { | ||
WsmanGetComponentJob.super_.call(this, logger, options, context, taskId); | ||
assert.object(this.options); | ||
this.nodeId = this.context.target; | ||
} | ||
|
||
util.inherits(WsmanGetComponentJob, BaseJob); | ||
|
||
WsmanGetComponentJob.prototype._initJob = function () { | ||
var self = this; | ||
self.dell = configuration.get('dell'); | ||
if (!self.dell || !self.dell.services || !self.dell.services.configuration) { | ||
throw new errors.NotFoundError('Dell SCP web service is not defined in smiConfig.json.'); | ||
} | ||
if(!self.dell.shareFolder){ | ||
throw new errors.NotFoundError('The shareFolder is not defined in smiConfig.json.'); | ||
} | ||
}; | ||
|
||
WsmanGetComponentJob.prototype._handleSyncRequest = function() { | ||
var self = this; | ||
return self.checkOBM('SCP create xml for deleting volume') | ||
.then(function(obm){ | ||
return self.getComponent(obm); | ||
}); | ||
}; | ||
|
||
WsmanGetComponentJob.prototype._handleSyncResponse = function(response) { | ||
var json = JSON.parse(response.body); | ||
logger.info('Status from SCP Microservice for getXml: ' + json["status"]); | ||
if (json["status"] === "OK") { | ||
return response; | ||
} else { | ||
throw new Error("Failed to getXml from smi service."); | ||
} | ||
}; | ||
|
||
WsmanGetComponentJob.prototype.getComponent = function(obm) { | ||
if (!validator.isIP(obm.config.host)) { | ||
throw new Error('Invalid ServerIP'); | ||
} | ||
var self = this; | ||
var componentNames = ""; | ||
if(self.options.volumeId !== undefined && self.options.volumeId !== ""){ | ||
componentNames = self.options.volumeId.split(':')[1]; | ||
}else if(self.options.drivers !== undefined){ | ||
var driver = self.options.drivers.split(',')[0]; | ||
componentNames = driver.slice(driver.lastIndexOf(':')+1, driver.length); | ||
}else{ | ||
throw new Error('Drives or volumeId isn\'t defined.'); | ||
} | ||
var data = { | ||
"componentNames": [componentNames], | ||
"fileName": self.context.graphId + ".xml", | ||
"serverIP": obm.config.host, | ||
"serverPassword": obm.config.user, | ||
"serverUsername": encryption.decrypt(obm.config.password), | ||
"shareAddress": self.dell.shareFolder.address, | ||
"shareName": self.dell.shareFolder.shareName, | ||
"sharePassword": self.dell.shareFolder.password, | ||
"shareType": self.dell.shareFolder.shareType, | ||
"shutdownType": self.options.shutdownType, | ||
"shareUsername": self.dell.shareFolder.username | ||
}; | ||
|
||
var wsman = new WsmanTool(self.dell.gateway, { | ||
verifySSl: false, | ||
recvTimeoutMs: 60000 | ||
}); | ||
return wsman.clientRequest( | ||
self.dell.services.configuration.getComponents, | ||
"POST", | ||
data | ||
); | ||
}; | ||
|
||
return WsmanGetComponentJob; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
friendlyName: 'Dell Wsman RAID Base Task', | ||
injectableName: 'Task.Base.Dell.Wsman.RAID', | ||
runJob: 'Job.Dell.Wsman.RAID', | ||
requiredOptions: [ | ||
], | ||
requiredProperties: { | ||
}, | ||
properties: { | ||
} | ||
}; |
15 changes: 15 additions & 0 deletions
15
lib/task-data/base-tasks/dell-wsman-delete-volume-updateXml.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
friendlyName: 'Dell Wsman Delete Volume Xml Base Task', | ||
injectableName: 'Task.Base.Dell.Wsman.Delete.Volume.UpdateXml', | ||
runJob: 'Job.Dell.Wsman.Delete.Volume.UpdateXml', | ||
requiredOptions: [ | ||
], | ||
requiredProperties: { | ||
}, | ||
properties: { | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
friendlyName: 'Dell Wsman GetComponent Base Task', | ||
injectableName: 'Task.Base.Dell.Wsman.GetXml', | ||
runJob: 'Job.Dell.Wsman.GetXml', | ||
requiredOptions: [ | ||
], | ||
requiredProperties: { | ||
}, | ||
properties: { | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
friendlyName: 'Dell Wsman GetComponent Base Task', | ||
injectableName: 'Task.Base.Dell.Wsman.GetXml', | ||
runJob: 'Job.Dell.Wsman.GetXml', | ||
requiredOptions: [ | ||
], | ||
requiredProperties: { | ||
}, | ||
properties: { | ||
} | ||
}; |
Oops, something went wrong.