-
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
17 changed files
with
611 additions
and
16 deletions.
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
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,162 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
var di = require('di'), | ||
xmldom = require('xmldom').DOMParser; | ||
|
||
module.exports = WsmanAddHotspareUpdateXmlFactory; | ||
|
||
di.annotate(WsmanAddHotspareUpdateXmlFactory, new di.Provide('Job.Dell.Wsman.Add.Hotspare.UpdateXml')); | ||
di.annotate(WsmanAddHotspareUpdateXmlFactory, new di.Inject( | ||
'Job.Base', | ||
'Logger', | ||
'Assert', | ||
'Util', | ||
'Services.Configuration', | ||
'Errors', | ||
'JobUtils.Smb2Client', | ||
'JobUtils.NfsClient', | ||
'Promise', | ||
'_' | ||
)); | ||
|
||
function WsmanAddHotspareUpdateXmlFactory( | ||
BaseJob, | ||
Logger, | ||
assert, | ||
util, | ||
configuration, | ||
errors, | ||
Smb2Client, | ||
NfsClient, | ||
Promise, | ||
_ | ||
) { | ||
var logger = Logger.initialize(WsmanAddHotspareUpdateXmlFactory); | ||
|
||
function WsmanAddHotspareUpdateXmlJob(options, context, taskId) { | ||
WsmanAddHotspareUpdateXmlJob.super_.call(this, logger, options, context, taskId); | ||
} | ||
|
||
util.inherits(WsmanAddHotspareUpdateXmlJob, BaseJob); | ||
|
||
WsmanAddHotspareUpdateXmlJob.prototype._run = function() { | ||
var self = this; | ||
if(!self.options.driveId) { | ||
throw new errors.NotFoundError('The driveId should not be empty.'); | ||
} | ||
self.dell = configuration.get('dell'); | ||
if(!self.dell || !self.dell.shareFolder) { | ||
throw new errors.NotFoundError('Share folder is not defined in smiConfig.json'); | ||
} | ||
return self.updateXmlForRaid(); | ||
}; | ||
|
||
WsmanAddHotspareUpdateXmlJob.prototype.updateXmlForRaid = function() { | ||
var self = this; | ||
var fileName = self.context.graphId + '.xml'; | ||
var client; | ||
return Promise.try(function() { | ||
if(self.dell.shareFolder.shareType === 0) { | ||
client = new NfsClient( | ||
self.dell.shareFolder.address, | ||
self.dell.shareFolder.shareName, | ||
self.context.mountDir | ||
); | ||
} else if(self.dell.shareFolder.shareType === 2) { | ||
client = new Smb2Client( | ||
self.dell.shareFolder.address, | ||
self.dell.shareFolder.shareName, | ||
self.dell.shareFolder.username, | ||
self.dell.shareFolder.password | ||
); | ||
} else { | ||
throw new Error('Invalid shareType in smiConfig.json. The shareType should be 0 or 2.'); | ||
} | ||
return client.readFile(fileName); | ||
}) | ||
.then(function(data) { | ||
return self.updateXml(data); | ||
}) | ||
.then(function(doc) { | ||
return client.writeFile(fileName, doc); | ||
}) | ||
.then(function() { | ||
self._done(); | ||
}) | ||
.catch(function(err) { | ||
logger.error('An error occurred while updating component xml.', { error: err }); | ||
self._done(err); | ||
}); | ||
}; | ||
|
||
WsmanAddHotspareUpdateXmlJob.prototype.updateXml = function(data) { | ||
var self = this; | ||
var xmlFile = String.fromCharCode.apply(null, new Uint16Array(data)); | ||
var doc = new xmldom().parseFromString(xmlFile, 'application/xml'); | ||
if(self.options.hotspareType === 'dhs') { | ||
self.UpdateVolumeElement(doc); | ||
} else { | ||
self.UpdateDiskElement(doc); | ||
} | ||
return doc; | ||
}; | ||
|
||
/* | ||
* Dedicated hotspare should be added into corresponding volume | ||
*/ | ||
WsmanAddHotspareUpdateXmlJob.prototype.UpdateVolumeElement = function(doc) { | ||
var self = this; | ||
if(!self.options.volumeId) { | ||
throw new errors.NotFoundError('The volumeId should not be empty.'); | ||
} | ||
var components = doc.getElementsByTagName('Component'); | ||
_.forEach(components, function(component) { | ||
var volumeFQDD = component.getAttribute('FQDD'); | ||
if(volumeFQDD === self.options.volumeId) { | ||
var newNode = doc.createElement('Attribute'); | ||
newNode.setAttribute('Name', 'RAIDdedicatedSpare'); | ||
newNode.textContent = self.options.driveId; | ||
component.appendChild(newNode); | ||
var breakLineChild = doc.createTextNode('\n'); | ||
component.appendChild(breakLineChild); | ||
return false; | ||
} | ||
}); | ||
return doc; | ||
}; | ||
|
||
/* | ||
* Update hotspare status of specified drive | ||
*/ | ||
WsmanAddHotspareUpdateXmlJob.prototype.UpdateDiskElement = function(doc) { | ||
var self = this; | ||
var components = doc.getElementsByTagName('Component'); | ||
_.forEach(components, function(component) { | ||
var diskFQDD = component.getAttribute('FQDD'); | ||
if(diskFQDD === self.options.driveId) { | ||
var newDriveNode = doc.createElement('Component'); | ||
newDriveNode.setAttribute('FQDD', diskFQDD); | ||
var statusChild = doc.createElement('Attribute'); | ||
statusChild.setAttribute('Name', 'RAIDHotSpareStatus'); | ||
statusChild.textContent = 'Global'; | ||
var stateChild = doc.createElement('Attribute'); | ||
stateChild.setAttribute('Name', 'RAIDPDState'); | ||
stateChild.textContent = 'Ready'; | ||
var breakLineChild = doc.createTextNode('\n'); | ||
newDriveNode.appendChild(breakLineChild); | ||
newDriveNode.appendChild(statusChild); | ||
breakLineChild = doc.createTextNode('\n'); | ||
newDriveNode.appendChild(breakLineChild); | ||
newDriveNode.appendChild(stateChild); | ||
breakLineChild = doc.createTextNode('\n'); | ||
newDriveNode.appendChild(breakLineChild); | ||
doc.replaceChild(newDriveNode, component); | ||
return false; | ||
} | ||
}); | ||
}; | ||
|
||
return WsmanAddHotspareUpdateXmlJob; | ||
} |
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
12 changes: 12 additions & 0 deletions
12
lib/task-data/base-tasks/dell-wsman-add-hotspare-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,12 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
friendlyName: "Dell Wsman Add Hotspare UpdateXml Base Task", | ||
injectableName: "Task.Base.Dell.Wsman.Add.Hotspare.UpdateXml", | ||
runJob: 'Job.Dell.Wsman.Add.Hotspare.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,23 @@ | ||
{ | ||
"copyright": "Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.", | ||
"definitions": { | ||
"driveId": { | ||
"description": "Specify drive id to be added as hot spare", | ||
"type": "string" | ||
}, | ||
"shutdownType": { | ||
"description": "Specify the type of system shutdown: Graceful(0), Forced(1), default value is 0", | ||
"type": "integer", | ||
"enum": [0, 1] | ||
} | ||
}, | ||
"properties": { | ||
"driveId": { | ||
"$ref": "#/definitions/driveId" | ||
}, | ||
"shutdownType": { | ||
"$ref": "#/definitions/shutdownType" | ||
} | ||
}, | ||
"required": ["driveId"] | ||
} |
30 changes: 30 additions & 0 deletions
30
lib/task-data/schemas/dell-wsman-add-hotspare-updatexml.json
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,30 @@ | ||
{ | ||
"copyright": "Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.", | ||
"definitions": { | ||
"volumeId": { | ||
"description": "Specify volume id for adding hot spare", | ||
"type": "string" | ||
}, | ||
"driveId": { | ||
"description": "Specify drive id to be added as hot spare", | ||
"type": "string" | ||
}, | ||
"hotspareType": { | ||
"description": "Specify hotspare type for the drive", | ||
"type": "string", | ||
"enum": ["ghs", "dhs"] | ||
} | ||
}, | ||
"properties": { | ||
"volumeId": { | ||
"$ref": "#/definitions/volumeId" | ||
}, | ||
"driveId": { | ||
"$ref": "#/definitions/driveId" | ||
}, | ||
"hotspareType": { | ||
"$ref": "#/definitions/hotspareType" | ||
} | ||
}, | ||
"required": ["driveId", "hotspareType"] | ||
} |
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
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,14 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
friendlyName: "Dell Wsman GetXml for Add Hotspare", | ||
injectableName: "Task.Dell.Wsman.Add.Hotspare.GetXml", | ||
implementsTask: "Task.Base.Dell.Wsman.GetXml", | ||
optionsSchema: 'dell-wsman-add-hotspare-getxml.json', | ||
options: { | ||
shutdownType: 0 | ||
}, | ||
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,12 @@ | ||
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
friendlyName: "Dell Wsman UpdateXml for Add Hotspare", | ||
injectableName: "Task.Dell.Wsman.Add.Hotspare.UpdateXml", | ||
implementsTask: "Task.Base.Dell.Wsman.Add.Hotspare.UpdateXml", | ||
optionsSchema: 'dell-wsman-add-hotspare-updatexml.json', | ||
options: {}, | ||
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
Oops, something went wrong.