Skip to content

Commit

Permalink
Port add & delete volume redfish api
Browse files Browse the repository at this point in the history
  • Loading branch information
yaolingling authored and anhou committed Dec 14, 2017
1 parent 8d6b86d commit c9c5287
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 55 deletions.
18 changes: 15 additions & 3 deletions lib/jobs/dell-wsman-RAID.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,22 @@ function DellWsmanRAIDFactory(

DellWsmanRAIDJob.prototype._handleSyncRequest = function() {
var self = this;
return self.checkOBM('SCP RAID operation')
.then(function(obm){
if(self.options.ipAddress === '' || self.options.username === '' ||
self.options.password === ''){
return self.checkOBM('SCP RAID operation')
.then(function(obm){
return self.doRAIDoperation(obm);
});
}else{
var obm = {
"config": {
"host": self.options.ipAddress,
"user": self.options.username,
"password": self.options.password
}
};
return self.doRAIDoperation(obm);
});
}
};

DellWsmanRAIDJob.prototype._handleSyncResponse = function(response) {
Expand Down
22 changes: 11 additions & 11 deletions lib/jobs/dell-wsman-add-volume-updateXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function WsmanAddVolumeXmlFactory(
if (!self.dell.shareFolder) {
throw new errors.NotFoundError('The shareFolder is not defined in smiConfig.json.');
}
if(self.options.drivers === ""){
throw new errors.NotFoundError('The drivers can not be empty string.');
if(self.options.drives === ""){
throw new errors.NotFoundError('The drives can not be empty string.');
}
self.parseXmlFileForRAID();
};
Expand Down Expand Up @@ -73,7 +73,7 @@ function WsmanAddVolumeXmlFactory(
return client.readFile(fileName).then(function(data){
return self.updateXml(
data,
self.options.drivers,
self.options.drives,
self.options.raidLevel,
self.options.name,
self.options.stripeSize,
Expand All @@ -89,7 +89,7 @@ function WsmanAddVolumeXmlFactory(
});
};

WsmanAddVolumeXmlJob.prototype.updateXml = function(data, drivers, raidLevel, name, stripeSize, writePolicy){
WsmanAddVolumeXmlJob.prototype.updateXml = function(data, drives, raidLevel, name, stripeSize, writePolicy){
var self = this;
var xmlFile = String.fromCharCode.apply(null, new Uint16Array(data));
var doc = new xmldom().parseFromString(xmlFile, 'application/xml');
Expand Down Expand Up @@ -145,25 +145,25 @@ function WsmanAddVolumeXmlFactory(
"textContent": "RAID " + raidLevel
}
];
var driversArray = drivers.split(',');
for(var i = 0; i < driversArray.length; i++){ //jshint ignore:line
var drivesArray = drives.split(',');
for(var i = 0; i < drivesArray.length; i++){ //jshint ignore:line
attributes.push({
"name": 'IncludedPhysicalDiskID',
"textContent": driversArray[i]
"textContent": drivesArray[i]
});
}
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){
index.push(i);
}
if(driversArray.indexOf(fqdd) !== -1){
if(drivesArray.indexOf(fqdd) !== -1){
enclosureIndex.push(i);
}
if(fqdd.split('.')[0] === 'Enclosure'){
insertIndex = i;
}
if(fqdd.indexOf('Disk.Bay') !== -1 && driversArray.indexOf(fqdd) === -1){
if(fqdd.indexOf('Disk.Bay') !== -1 && drivesArray.indexOf(fqdd) === -1){
bayIndex.push(i);
}
}
Expand All @@ -174,8 +174,8 @@ function WsmanAddVolumeXmlFactory(
doc.documentElement.removeChild(components[bayIndex[i]]);
}
var ele = doc.createElement("Component");
var driver = self.options.drivers.split(',')[0];
var fqddName = 'Disk.Virtual:' + driver.slice(driver.lastIndexOf(':')+1, driver.length);
var drive = self.options.drives.split(',')[0];
var fqddName = 'Disk.Virtual:' + drive.slice(drive.lastIndexOf(':')+1, drive.length);
ele.setAttribute('FQDD', fqddName);
doc.insertBefore(ele, components[insertIndex]);
for(var i = 0; i < attributes.length; i++){ //jshint ignore:line
Expand Down
24 changes: 18 additions & 6 deletions lib/jobs/dell-wsman-getXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,22 @@ function WsmanGetComponentFactory(

WsmanGetComponentJob.prototype._handleSyncRequest = function() {
var self = this;
return self.checkOBM('SCP create xml for deleting volume')
.then(function(obm){
if(self.options.ipAddress === '' || self.options.username === '' ||
self.options.password === ''){
return self.checkOBM('SCP create xml for deleting volume')
.then(function(obm){
return self.getComponent(obm);
});
}else{
var obm = {
"config": {
"host": self.options.ipAddress,
"user": self.options.username,
"password": self.options.password
}
};
return self.getComponent(obm);
});
}
};

WsmanGetComponentJob.prototype._handleSyncResponse = function(response) {
Expand All @@ -87,9 +99,9 @@ function WsmanGetComponentFactory(
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 if(self.options.drives !== undefined){
var drive = self.options.drives.split(',')[0];
componentNames = drive.slice(drive.lastIndexOf(':')+1, drive.length);
}else{
throw new Error('Drives or volumeId isn\'t defined.');
}
Expand Down
21 changes: 21 additions & 0 deletions lib/task-data/schemas/dell-wsman-RAID.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
"removeXmlFile": {
"description": "Specify if the xml file is deleted. It's default value is true",
"type": "boolean"
},
"ipAddress": {
"description": "Specify ipAddress for obm setting",
"type": "string"
},
"username": {
"description": "Specify username for obm setting",
"type": "string"
},
"password": {
"description": "Specify password for obm setting",
"type": "string"
}
},
"properties": {
Expand All @@ -17,6 +29,15 @@
},
"removeXmlFile": {
"$ref": "#/definitions/removeXmlFile"
},
"ipAddress": {
"$ref": "#/definitions/ipAddress"
},
"username": {
"$ref": "#/definitions/username"
},
"password": {
"$ref": "#/definitions/password"
}
}
}
31 changes: 26 additions & 5 deletions lib/task-data/schemas/dell-wsman-add-volume-getXml.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
{
"copyright": "Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.",
"definitions": {
"drivers": {
"description": "Specify drivers for adding volume",
"drives": {
"description": "Specify drives for adding volume",
"type": "string"
},
"shutdownType": {
"description": "Specify the type of system shutdown: Graceful(0), Forced(1), default value is 0",
"type": "integer",
"enum": [0,1]
},
"ipAddress": {
"description": "Specify ipAddress for obm setting",
"type": "string"
},
"username": {
"description": "Specify username for obm setting",
"type": "string"
},
"password": {
"description": "Specify password for obm setting",
"type": "string"
}
},
"properties": {
"drivers": {
"$ref": "#/definitions/drivers"
"drives": {
"$ref": "#/definitions/drives"
},
"shutdownType": {
"$ref": "#/definitions/shutdownType"
},
"ipAddress": {
"$ref": "#/definitions/ipAddress"
},
"username": {
"$ref": "#/definitions/username"
},
"password": {
"$ref": "#/definitions/password"
}
},
"required": ["drivers"]
"required": ["drives"]
}
12 changes: 6 additions & 6 deletions lib/task-data/schemas/dell-wsman-add-volume-updateXml.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"copyright": "Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.",
"definitions": {
"drivers": {
"description": "Specify drivers for adding volume",
"drives": {
"description": "Specify drives for adding volume",
"type": "string"
},
"name": {
Expand All @@ -12,7 +12,7 @@
"raidLevel": {
"description": "Specify raidLevel for adding volume. default value: 0",
"type": "integer",
"enum": [0,1,5,6,10]
"enum": [0,1,5,6,10,50]
},
"stripeSize": {
"description": "Specify stripeSize for adding volume, default value: 128",
Expand All @@ -25,8 +25,8 @@
}
},
"properties": {
"drivers": {
"$ref": "#/definitions/drivers"
"drives": {
"$ref": "#/definitions/drives"
},
"name": {
"$ref": "#/definitions/name"
Expand All @@ -41,5 +41,5 @@
"$ref": "#/definitions/writePolicy"
}
},
"required": ["drivers","name"]
"required": ["drives","name"]
}
21 changes: 21 additions & 0 deletions lib/task-data/schemas/dell-wsman-delete-volume.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
"description": "Specify the type of system shutdown: Graceful(0), Forced(1), default value is 0",
"type": "integer",
"enum": [0,1]
},
"ipAddress": {
"description": "Specify ipAddress for obm setting",
"type": "string"
},
"username": {
"description": "Specify username for obm setting",
"type": "string"
},
"password": {
"description": "Specify password for obm setting",
"type": "string"
}
},
"properties": {
Expand All @@ -17,6 +29,15 @@
},
"shutdownType": {
"$ref": "#/definitions/shutdownType"
},
"ipAddress": {
"$ref": "#/definitions/ipAddress"
},
"username": {
"$ref": "#/definitions/username"
},
"password": {
"$ref": "#/definitions/password"
}
},
"required": ["volumeId"]
Expand Down
5 changes: 4 additions & 1 deletion lib/task-data/tasks/dell-wsman-RAID.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module.exports = {
optionsSchema: 'dell-wsman-RAID.json',
options: {
shutdownType: 0,
removeXmlFile: true
removeXmlFile: true,
ipAddress: "",
username: "",
password: ""
},
properties: {}
};
5 changes: 4 additions & 1 deletion lib/task-data/tasks/dell-wsman-add-volume-getXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module.exports = {
implementsTask: "Task.Base.Dell.Wsman.GetXml",
optionsSchema: 'dell-wsman-add-volume-getXml.json',
options: {
shutdownType: 0
shutdownType: 0,
ipAddress: "",
username: "",
password: ""
},
properties: {}
};
5 changes: 4 additions & 1 deletion lib/task-data/tasks/dell-wsman-delete-volume-getXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module.exports = {
implementsTask: "Task.Base.Dell.Wsman.GetXml",
optionsSchema: 'dell-wsman-delete-volume.json',
options: {
shutdownType:0
shutdownType:0,
ipAddress: "",
username: "",
password: ""
},
properties: {}
};
8 changes: 4 additions & 4 deletions spec/lib/jobs/dell-wsman-add-volume-updateXml-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Dell Wsman Add Volume Update XML Job', function(){
"</SystemConfiguration>";
var fileData = Buffer.from(file, 'utf-8');
var options = {
'drivers': 'Disk.Bay.0:Enclosure.Internal.0-0:RAID.Slot.1-1,Disk.Bay.1:Enclosure.Internal.0-0:RAID.Slot.1-1',
'drives': 'Disk.Bay.0:Enclosure.Internal.0-0:RAID.Slot.1-1,Disk.Bay.1:Enclosure.Internal.0-0:RAID.Slot.1-1',
'raidLevel': 'RAID 0',
'name': 'test-raid',
'stripeSize': 128,
Expand Down Expand Up @@ -94,12 +94,12 @@ describe('Dell Wsman Add Volume Update XML Job', function(){
}).to.throw('The shareFolder is not defined in smiConfig.json.');
});

it('Should throw an error: the drivers can not be empty string', function(){
it('Should throw an error: the drives can not be empty string', function(){
configuration.get.returns(configFile);
job.options.drivers = '';
job.options.drives = '';
expect(function(){
job._run();
}).to.throw('The drivers can not be empty string.');
}).to.throw('The drives can not be empty string.');
});

it('Should parse xml file for cifs successfully', function(){
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/jobs/dell-wsman-getXml-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('Dell Wsman GetComponent Job', function(){

it('Should send getComponent request succesfully with drives is defined', function(){
validator.isIP.returns(true);
job.options.drivers = "Disk.Bay.0:Enclosure.Internal.0-0:RAID.Slot.1-1,"
job.options.drives = "Disk.Bay.0:Enclosure.Internal.0-0:RAID.Slot.1-1,"
+"Disk.Bay.1:Enclosure.Internal.0-0:RAID.Slot.1-1";
job.dell = configFile;
var response = {
Expand Down
Loading

0 comments on commit c9c5287

Please sign in to comment.