Skip to content

Commit

Permalink
Merge 56e739c into 0f959ef
Browse files Browse the repository at this point in the history
  • Loading branch information
yaolingling authored Nov 23, 2017
2 parents 0f959ef + 56e739c commit b65e5e4
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 75 deletions.
51 changes: 34 additions & 17 deletions lib/jobs/dell-wsman-RAID.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ di.annotate(DellWsmanRAIDFactory, new di.Inject(
'Errors',
'Services.Encryption',
'validator',
'JobUtils.Smb2Client'
'JobUtils.Smb2Client',
'JobUtils.NfsClient'
));

function DellWsmanRAIDFactory(
Expand All @@ -29,7 +30,8 @@ function DellWsmanRAIDFactory(
errors,
encryption,
validator,
Smb2Client
Smb2Client,
NfsClient
) {
var logger = Logger.initialize(DellWsmanRAIDFactory);

Expand Down Expand Up @@ -66,17 +68,34 @@ function DellWsmanRAIDFactory(
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);
});
if(self.dell.shareFolder.shareType === 0){
var nfsClient = new NfsClient(
self.dell.shareFolder.address,
self.dell.shareFolder.shareName,
self.context.mountDir
);
return nfsClient.deleteFile(self.context.graphId + ".xml").then(function(){
return nfsClient.umount();
}).then(function(){
return response;
}).catch(function(error){
logger.error("Errors occur "+ error);
});
}else if (self.dell.shareFolder.shareType === 2){
var smb2Client = new Smb2Client(
self.dell.shareFolder.address,
self.dell.shareFolder.shareName,
self.dell.shareFolder.username,
self.dell.shareFolder.password
);
return smb2Client.deleteFile(self.context.graphId + ".xml").then(function(){
return response;
}).catch(function(error){
logger.error("Errors occur "+ error);
});
}else{
throw new Error('The shareType must be 0 or 2.');
}
}else{
return response;
}
Expand All @@ -89,21 +108,19 @@ function DellWsmanRAIDFactory(
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),
"serverPassword": encryption.decrypt(obm.config.password),
"serverUsername": obm.config.user,
"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
Expand Down
74 changes: 45 additions & 29 deletions lib/jobs/dell-wsman-delete-volume-updateXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ di.annotate(WsmanDeleteVolumeXmlFactory, new di.Inject(
'Util',
'Services.Configuration',
'Errors',
'JobUtils.Smb2Client'
'JobUtils.Smb2Client',
'JobUtils.NfsClient'
));

function WsmanDeleteVolumeXmlFactory(
Expand All @@ -23,7 +24,8 @@ function WsmanDeleteVolumeXmlFactory(
util,
configuration,
errors,
Smb2Client
Smb2Client,
NfsClient
) {
var logger = Logger.initialize(WsmanDeleteVolumeXmlFactory);

Expand All @@ -50,36 +52,29 @@ function WsmanDeleteVolumeXmlFactory(
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;
var client;
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('The shareType must be 0 or 2.');
}
return client.readFile(fileName).then(function(data){
return self.updateXml(data, volumeId);
}).then(function(doc){
return smb2Client.writeFile(fileName, doc);
return client.writeFile(fileName, doc);
}).then(function(){
self._done();
}).catch(function(error){
Expand All @@ -88,5 +83,26 @@ function WsmanDeleteVolumeXmlFactory(
});
};

WsmanDeleteVolumeXmlJob.prototype.updateXml = function(fileData, volumeId){
var xmlFile = String.fromCharCode.apply(null, new Uint16Array(fileData));
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;
};

return WsmanDeleteVolumeXmlJob;
}
16 changes: 14 additions & 2 deletions lib/jobs/dell-wsman-getXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ di.annotate(WsmanGetComponentFactory, new di.Inject(
'Services.Configuration',
'Errors',
'Services.Encryption',
'validator'
'validator',
'JobUtils.NfsClient'
));

function WsmanGetComponentFactory(
Expand All @@ -26,7 +27,8 @@ function WsmanGetComponentFactory(
configuration,
errors,
encryption,
validator
validator,
NfsClient
) {
var logger = Logger.initialize(WsmanGetComponentFactory);

Expand All @@ -47,6 +49,16 @@ function WsmanGetComponentFactory(
if(!self.dell.shareFolder){
throw new errors.NotFoundError('The shareFolder is not defined in smiConfig.json.');
}
if(self.dell.shareFolder.shareType === 0){
var mountDir = '/tmp/' + self.context.graphId;
var nfsClient = new NfsClient(
self.dell.shareFolder.address,
self.dell.shareFolder.shareName,
mountDir
);
self.context.mountDir = mountDir;
return nfsClient.mount();
}
};

WsmanGetComponentJob.prototype._handleSyncRequest = function() {
Expand Down
2 changes: 1 addition & 1 deletion lib/jobs/dell-wsman-inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function DellWsmanInventoryJobFactory(
throw new errors.NotFoundError('Dell Inventory web service is not defined in wsmanConfig.json.');
}

self.wsman = new WsmanTool(self.dellConfigs.gateway, {
self.wsman = new WsmanTool('http://192.168.128.10:46011', {
verifySSL: self.options.verifySSL || false,
recvTimeoutMs: 300000
});
Expand Down
121 changes: 121 additions & 0 deletions lib/utils/job-utils/nfs-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.

'use strict';

var di = require('di'),
XmlDOM = require('xmldom');

module.exports = NfsClientFactory;
di.annotate(NfsClientFactory, new di.Provide('JobUtils.NfsClient'));
di.annotate(NfsClientFactory, new di.Inject(
'Logger',
'Promise',
'fs',
'child_process'
));

function NfsClientFactory(
Logger,
Promise,
fs,
childProcess
){
var logger = Logger.initialize(NfsClientFactory); // jshint ignore:line
var XMLSerializer;
var serializer;

function NfsClient(shareIP, shareName, mountDir){
var self = this;
self.shareIP = shareIP;
self.shareName = shareName;
self.mountDir = mountDir;
XMLSerializer = XmlDOM.XMLSerializer;
serializer = new XMLSerializer();
}

NfsClient.prototype.mount = function(){
var self = this;
return Promise.resolve().then(function(){
childProcess.exec(
'sudo mkdir -p ' + self.mountDir,
function(mkdirError, stdout, stderr){
if(mkdirError){
throw mkdirError;
}
logger.debug('mount stdout: ' + stdout + " stderr: " + stderr);
}
);
}).then(function(){
childProcess.exec(
'mount ' + self.shareIP + ':' + self.shareName + ' ' + self.mountDir,
function(mountError, stdout, stderr){
if(mountError){
throw mountError;
}
logger.debug('mount stdout: ' + stdout + " stderr: " + stderr);
}
);
}).catch(function(error){
logger.error('Error occurs '+ error);
});
};

NfsClient.prototype.umount = function(){
var self = this;
return new Promise(function(resolve, reject){
childProcess.exec(
'umount ' + self.mountDir,
function(umountError, stdout, stderr){
if(umountError){
reject(umountError);
}else{
resolve(stdout);
logger.debug('umount stdout: ' + stdout + " stderr: " + stderr);
}
}
);
});
};

NfsClient.prototype.readFile = function(fileName){
var self = this;
return new Promise(function(resolve, reject){
fs.readFile(self.mountDir + '/' + fileName, (readError, data) => {
if(readError){
reject(readError);
}else{
resolve(data);
}
});
});
};

NfsClient.prototype.writeFile = function(fileName, doc){
var self = this;
return new Promise(function(resolve, reject){
fs.writeFile(self.mountDir + '/' + fileName, serializer.serializeToString(doc), (writeError) => {
if(writeError){
reject(writeError);
}else{
resolve('successfully write file '+ fileName);
}
});
});
};

NfsClient.prototype.deleteFile = function(fileName){
var self = this;
return new Promise(function(resolve, reject){
fs.unlink(self.mountDir + '/' + fileName, (deleteError) => {
if(deleteError){
reject(deleteError);
}else{
resolve('successfully delete file ' + fileName);
}
});
});
};

return NfsClient;
}

Loading

0 comments on commit b65e5e4

Please sign in to comment.