Skip to content

Commit

Permalink
Merge pull request #796 from BrentHiggins/redfish_discovery_fix
Browse files Browse the repository at this point in the history
Changing redfish identifiers for redfish discovered devices to match RackHD ID
  • Loading branch information
jimturnquist committed Oct 23, 2017
2 parents 94066f0 + 0e24e6b commit e4da732
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% nodes.forEach(function(node, i, arr) { %>

{
"@odata.id": "<%= basepath %>/DCIMCooling/<%=node.identifiers[2]%>/<%=node.identifiers[3]%>/<%=node.identifiers[0]%>-<%= node.id %>"
"@odata.id": "<%= basepath %>/DCIMCooling/<%=node.identifiers[2]%>/<%=node.identifiers[3]%>/<%= node.id %>"
}
<%= ( arr.length > 0 && i < arr.length-1 ) ? ',': '' %>
<% }); %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% nodes.forEach(function(node, i, arr) { %>

{
"@odata.id": "<%= basepath %>/DCIMPower/<%=node.identifiers[2]%>/<%=node.identifiers[3]%>/<%=node.identifiers[0]%>-<%= node.id %>"
"@odata.id": "<%= basepath %>/DCIMPower/<%=node.identifiers[2]%>/<%=node.identifiers[3]%>/<%= node.id %>"
}
<%= ( arr.length > 0 && i < arr.length-1 ) ? ',': '' %>
<% }); %>
Expand Down
6 changes: 1 addition & 5 deletions data/views/redfish-1.0/redfish.1.0.0.chassiscollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
"Members": [
<% nodes.forEach(function(node, i, arr) { %>
{
<% if (node.identifiers && node.identifiers.length > 1 && node.identifiers[1].includes('redfish')) { %>
"@odata.id": "<%= basepath %>/Chassis/<%=node.identifiers[0] %>-<%= node.id %>"
<% } else {%>
"@odata.id": "<%= basepath %>/Chassis/<%= node.id %>"
<% } %>
"@odata.id": "<%= basepath %>/Chassis/<%= node.id %>"
}
<%= ( arr.length > 0 && i < arr.length-1 ) ? ',': '' %>
<% }); %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
"Members": [
<% nodes.forEach(function(node, i, arr) { %>
{
<% if (node.identifiers[1] !== undefined && node.identifiers[1].includes('redfish')) { %>
"@odata.id": "<%= basepath %>/Systems/<%=node.identifiers[0] %>-<%= node.id %>"
<% } else {%>
"@odata.id": "<%= basepath %>/Systems/<%= node.id %>"
<% } %>
}
<%= ( arr.length > 0 && i < arr.length-1 ) ? ',': '' %>
<% }); %>
Expand Down
148 changes: 77 additions & 71 deletions lib/api/redfish-1.0/chassis.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ var dataFactory = function(identifier, dataName) {
}).then(function() {
return ucsPowerPollerData;
});
default:
return nodeApi.getNodeCatalogSourceById(identifier, dataName);
}
};

Expand Down Expand Up @@ -227,7 +229,6 @@ var listChassis = controller(function(req, res) {
var getChassis = controller(function(req, res) {
var chassisId = req.swagger.params.identifier.value.split('.')[0];
var systemId = req.swagger.params.identifier.value.split('.')[1];
var redfishId = redfish.isRedfish(req.swagger.params.identifier.value);
var options = redfish.makeOptions(req, res, req.swagger.params.identifier.value);
var typeEnum = [
"Rack",
Expand All @@ -250,84 +251,89 @@ var getChassis = controller(function(req, res) {
"Module",
"Component",
"Other" ];
return redfish.getVendorNameById(chassisId)
.then(function(result) {
if (result.vendor === 'Redfish') {
return nodeApi.getNodeById(chassisId)
.then(function(node) {
var catalogSource = req.url.replace(chassisId, node.identifiers[0]);
return dataFactory(chassisId, catalogSource);
});
} else {
return Promise.all([
nodeApi.getNodeById(chassisId),
systemId ? nodeApi.getNodeById(systemId) : null
])
.tap(function (nodes) {
if (!nodes[1]) {
return Promise.each(_getEnclosedSystems(nodes[0]), function (objId) {
return waterline.nodes.findByIdentifier(objId)
.then(function (obj) {
return env.get('config.redfish.computeType', 'Other', obj && obj.sku ? [obj.sku] : null);
})
.then(function (val) {
if (val === 'Blade') {
options.contains = options.contains || [];
options.contains.push(nodes[0].id + '.' + objId);
options.chassisType = 'Enclosure';
}
});
});
} else {
if (_.includes(_getEnclosedSystems(nodes[0]), systemId)) {
options.containedBy = chassisId;
options.chassisType = 'Blade';
}
}
})
.spread(function (chassisNode) {
var systems = _getEnclosedSystems(chassisNode);
var chassisName = chassisNode.name;
if (!_.isEmpty(systems)) {
if (chassisName.indexOf("sys/chassis") !== -1) {
return Promise.props({
systems: Promise.map(systems, nodeApi.getNodeById.bind(nodeApi)),
catData: dataFactory(chassisNode.id, 'catData'),
chassisData: dataFactory(chassisNode.id, 'chassisData')

if (redfishId.isRedfish) {
return redfish.getRedfishCatalog(req, res);
} else {
return Promise.all([
nodeApi.getNodeById(chassisId),
systemId ? nodeApi.getNodeById(systemId) : null
])
.tap(function (nodes) {
if (!nodes[1]) {
return Promise.each(_getEnclosedSystems(nodes[0]), function (objId) {
return waterline.nodes.findByIdentifier(objId)
.then(function (obj) {
return env.get('config.redfish.computeType', 'Other', obj && obj.sku ? [obj.sku] : null);
})
.then(function (val) {
if (val === 'Blade') {
options.contains = options.contains || [];
options.contains.push(nodes[0].id + '.' + objId);
options.chassisType = 'Enclosure';
}
});
});
} else {
if (_.includes(_getEnclosedSystems(nodes[0]), systemId)) {
options.containedBy = chassisId;
options.chassisType = 'Blade';
}
}
})
.spread(function (chassisNode) {
var systems = _getEnclosedSystems(chassisNode);
var chassisName = chassisNode.name;
if (!_.isEmpty(systems)) {
if (chassisName.indexOf("sys/chassis") !== -1) {
return Promise.props({
systems: Promise.map(systems, nodeApi.getNodeById.bind(nodeApi)),
catData: dataFactory(chassisNode.id, 'catData'),
chassisData: dataFactory(chassisNode.id, 'chassisData')
}
else {
return Promise.props({
systems: Promise.map(systems, nodeApi.getNodeById.bind(nodeApi)),
catData: dataFactory(systemId || systems[0], 'catData'),
chassisData: dataFactory(systemId || systems[0], 'chassisData')
});
}

});
}
else {
return Promise.props({
systems: Promise.map(systems, nodeApi.getNodeById.bind(nodeApi)),
catData: dataFactory(systemId || systems[0], 'catData'),
chassisData: dataFactory(systemId || systems[0], 'chassisData')
return {};
})
.then(function (obj) {
if (!_.get(options, 'chassisType')) {
options.chassisType = 'Other';
_.forEach(typeEnum, function (type) {
var re = new RegExp(type, 'g');
var match = obj.catData.chassis.type.match(re);
if (match) {
options.chassisType = match.toString().replace(/ /g, '');
}
});
}

}
return {};
})
.then(function (obj) {
if (!_.get(options, 'chassisType')) {
options.chassisType = 'Other';
_.forEach(typeEnum, function (type) {
var re = new RegExp(type, 'g');
var match = obj.catData.chassis.type.match(re);
if (match) {
options.chassisType = match.toString().replace(/ /g, '');
}
options.obm = ['RackHD'];
options.targetList = [];
_.forEach(obj.systems, function (system) {
options.targetList.push(system.id);
});
}

options.obm = ['RackHD'];
options.targetList = [];
_.forEach(obj.systems, function (system) {
options.targetList.push(system.id);
return redfish.render('redfish.1.0.0.chassis.1.0.0.json',
'Chassis.v1_4_0.json#/definitions/Chassis',
_.merge({}, obj, options));
})
.catch(function (error) {
return redfish.handleError(error, res);
});
return redfish.render('redfish.1.0.0.chassis.1.0.0.json',
'Chassis.v1_4_0.json#/definitions/Chassis',
_.merge({}, obj, options));
})
.catch(function (error) {
return redfish.handleError(error, res);
});
}
}
});
});

var getThermal = controller(function(req, res) {
Expand Down
9 changes: 7 additions & 2 deletions lib/api/redfish-1.0/dcimcooling.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Promise = injector.get('Promise'); // jshint ignore:line
var _ = injector.get('_'); // jshint ignore:line
var controller = injector.get('Http.Services.Swagger').controller;
var waterline = injector.get('Services.Waterline');
var nodeApi = injector.get('Http.Services.Api.Nodes');

var listDCIMCoolingDomain = controller(function (req, res) {
var options = redfish.makeOptions(req, res);
Expand Down Expand Up @@ -70,8 +71,12 @@ var listDCIMCoolingTypeCollection = controller(function (req, res) {
});

var listDCIMCoolingDefault = controller(function (req, res) {
return redfish.getRedfishCatalog(req,res);

var identifier = req.swagger.params.identifier.value;
return nodeApi.getNodeById(identifier)
.then(function(node) {
var catalogSource = req.url.replace(identifier, node.identifiers[0]);
return nodeApi.getNodeCatalogSourceById(identifier, catalogSource);
});
});

module.exports = {
Expand Down
9 changes: 7 additions & 2 deletions lib/api/redfish-1.0/dcimpower.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Promise = injector.get('Promise'); // jshint ignore:line
var _ = injector.get('_'); // jshint ignore:line
var controller = injector.get('Http.Services.Swagger').controller;
var waterline = injector.get('Services.Waterline');
var nodeApi = injector.get('Http.Services.Api.Nodes');

var listDCIMPowerDomain = controller(function (req, res) {
var options = redfish.makeOptions(req, res);
Expand Down Expand Up @@ -74,8 +75,12 @@ var listDCIMPowerTypeCollection = controller(function (req, res) {
});

var listDCIMPowerDefault = controller(function (req, res) {
return redfish.getRedfishCatalog(req,res);

var identifier = req.swagger.params.identifier.value;
return nodeApi.getNodeById(identifier)
.then(function(node) {
var catalogSource = req.url.replace(identifier, node.identifiers[0]);
return nodeApi.getNodeCatalogSourceById(identifier, catalogSource);
});
});


Expand Down
12 changes: 6 additions & 6 deletions lib/api/redfish-1.0/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var dataFactory = function(identifier, dataName) {
}).then(function(data) {
return data[0].sel;
});
default:
default:
return nodeApi.getNodeCatalogSourceById(identifier, dataName);
}
};
Expand Down Expand Up @@ -244,8 +244,7 @@ var listSystems = controller(function(req, res) {
* @param {Object} res
*/
var getSystem = controller(function(req, res) {
var redfishId = redfish.isRedfish(req.swagger.params.identifier.value);
var identifier = redfishId.identifier;
var identifier = req.swagger.params.identifier.value;
var options = redfish.makeOptions(req, res, identifier);
options.systemType = 'Physical';

Expand Down Expand Up @@ -288,9 +287,10 @@ var getSystem = controller(function(req, res) {
}).catch(function(error){
return redfish.handleError(error, res);
});
} else if (redfishId.isRedfish) {
return redfish.getRedfishCatalog(req, res);
}else {
} else if (result.vendor === 'Redfish') {
var catalogSource = req.url.replace(identifier, node.identifiers[0]);
return dataFactory(identifier, catalogSource);
}else {
return Promise.props({
catData: dataFactory(identifier, 'catData'),
chassis: dataFactory(identifier, 'chassis'),
Expand Down
31 changes: 3 additions & 28 deletions lib/services/redfish-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,34 +217,6 @@ function redfishApiServiceFactory(
return Promise.reject(new Errors.NotFoundError ('Message registry not found'));
};

RedfishApiService.prototype.getRedfishCatalog = function (req, res) {
var self = this;
var identifier = req.swagger.params.identifier.value;
var nodeId = identifier.split(['-'])[1];
var extraId = identifier.split(['-'])[0];
if (req.swagger.params.type) {
extraId = extraId.replace(req.swagger.params.type.raw, '');
}
var catalogSource = req.url.replace(req.swagger.params.identifier.value, extraId);
return nodeApi.getNodeCatalogSourceById(nodeId, catalogSource)
.catch(function (error) {
return self.handleError(error, res);
});
};

RedfishApiService.prototype.isRedfish = function (nodeId) {
var isRedfish = false;
var identifier;
var identifierArray = nodeId.split(/-/);
if (identifierArray.length > 1) {
isRedfish = true;
identifier = identifierArray[1];
} else {
identifier = identifierArray[0];
}
return {isRedfish: isRedfish, identifier:identifier};
};


/**
* Get vendor name by id
Expand Down Expand Up @@ -276,6 +248,9 @@ function redfishApiServiceFactory(
} else if (validator.isIP(items[0]) && ucsDnFormat.test(items[1])) {
vendor = 'Cisco';
return false;
} else if (_identifier.indexOf('redfish/v1/') > -1) {
vendor = 'Redfish';
return false;
}
});
return vendor;
Expand Down
9 changes: 3 additions & 6 deletions spec/lib/api/redfish-1.0/chassis-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ describe('Redfish Chassis Root', function () {
this.sandbox.spy(redfish, 'render');
this.sandbox.spy(redfish, 'handleError');
this.sandbox.spy(validator, 'validate');
this.sandbox.stub(redfish, 'getVendorNameById');
this.sandbox.stub(waterline.nodes);
waterline.nodes.findByIdentifier.withArgs('4567efgh4567efgh4567efgh').resolves(enclosure);
waterline.nodes.findByIdentifier.withArgs('1234abcd1234abcd1234abcd').resolves(system);
Expand Down Expand Up @@ -190,6 +191,7 @@ describe('Redfish Chassis Root', function () {
});

it('should return valid chassis and related targets', function() {
redfish.getVendorNameById.resolves({vendor: 'undefined'});
nodeApi.getNodeCatalogSourceById.resolves({
node: '1234abcd1234abcd1234abcd',
source: 'dummysource',
Expand All @@ -215,6 +217,7 @@ describe('Redfish Chassis Root', function () {
});

it('should 404 an invalid chassis object', function() {
redfish.getVendorNameById.resolves({vendor: 'undefined'});
return helper.request().get('/redfish/v1/Chassis/ABCDEFG')
.expect('Content-Type', /^application\/json/)
.expect(404)
Expand All @@ -228,9 +231,6 @@ describe('Redfish Chassis Root', function () {
var ucsPowerThermalPoller;
var ucsFanPoller;

beforeEach('set up mock', function() {
this.sandbox.stub(redfish, 'getVendorNameById');
});

before('/redfish/v1/Chassis/<identifier>/Thermal/', function() {
ucsFanPoller = {
Expand Down Expand Up @@ -468,9 +468,6 @@ describe('Redfish Chassis Root', function () {
var ucsPowerThermalPoller;
var ucsPsuPoller;

beforeEach('set up mock', function() {
this.sandbox.stub(redfish, 'getVendorNameById');
});

before('/redfish/v1/Chassis/<identifier>/Power/', function() {
ucsPowerThermalPoller = {
Expand Down
Loading

0 comments on commit e4da732

Please sign in to comment.