Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/api/1.1/northbound/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ function nodesRouterFactory (
var obms = Promise.map(waterline.obms.find({node: node.id}), function(obm) {
return _.pick(obm.toJSON(), 'service', 'config');
});
var sshSettings = waterline.ibms.findByNode(node.id, 'ssh-ibm-service');
return Promise.all([obms, sshSettings])
.spread(function(obms, sshSettings) {

var ibms = Promise.map(waterline.ibms.find({node: node.id}), function(ibm) {
return _.pick(ibm.toJSON(), 'service', 'config');
});

return Promise.all([obms, ibms])
.spread(function(obms, ibms) {
node.obmSettings = obms;
if (sshSettings) {
node.sshSettings = {
host: sshSettings.config.host,
user: sshSettings.config.user,
password: 'REDACTED'
};
} else {
delete node.sshSettings;
}

_.forEach(ibms, function(ibm) {
var settingKey = ibm.service.split('-')[0] + 'Settings';
node[settingKey] = ibm.config;
});
return node;
});
}
Expand Down
23 changes: 17 additions & 6 deletions lib/services/nodes-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ function nodeApiServiceFactory(

NodeApiService.prototype.postNode = function(body) {
//for api-v1.1 back-compatibility, the input obm can be either via obms or obmSettings
var nodeBody = _.omit(body, ['obms', 'obmSettings']);
var nodeBody = _.omit(body, ['obms', 'obmSettings', 'snmpSettings']);
var obmBody = body.obms || body.obmSettings || null;
var snmpBody = body.snmpSettings || null;

return Promise.resolve()
.then(function() {
Expand All @@ -276,26 +277,36 @@ function nodeApiServiceFactory(
return waterline.obms.upsertByNode(node.id, obm);
});
}
}).tap(function(node) {
if (snmpBody) {
var snmpIbm = {
"service": "snmp-ibm-service",
"config": snmpBody
};
return waterline.ibms.upsertByNode(node.id, snmpIbm);
}
}).then(function(node) {
return [node, waterline.ibms.findByNode(node.id, 'snmp-ibm-service')];
}).spread(function(node, snmpSettings) {
if(node.type === Constants.NodeTypes.Switch &&
node.snmpSettings && node.autoDiscover) {
snmpSettings && node.autoDiscover) {
return workflowApiService.createAndRunGraph(
{
name: 'Graph.Switch.Discovery',
options: {
defaults: _.assign(node.snmpSettings, { nodeId: node.id })
defaults: _.assign(snmpSettings, { nodeId: node.id })
}
},
node.id
);
}
else if(node.type === Constants.NodeTypes.Pdu &&
node.snmpSettings && node.autoDiscover) {
snmpSettings && node.autoDiscover) {
return workflowApiService.createAndRunGraph(
{
name: 'Graph.PDU.Discovery',
options: {
defaults: _.assign(node.snmpSettings, { nodeId: node.id })
defaults: _.assign(snmpSettings, { nodeId: node.id })
}
},
node.id
Expand Down Expand Up @@ -449,7 +460,7 @@ function nodeApiServiceFactory(
return waterline.nodes.getNodeById(id)
.then(function (node) {
if (node) {
return waterline.ibms.findAllByNode(id, false);
return waterline.ibms.findAllByNode(id, false, {service: 'ssh-ibm-service'});
}
});
};
Expand Down
30 changes: 26 additions & 4 deletions spec/lib/api/1.1/nodes-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ describe('Http.Api.Nodes v1.1', function () {
lookupService = helper.injector.get('Services.Lookup');
lookupService.ipAddressToMacAddress = sinon.stub().resolves();
lookupService.ipAddressToNodeId = sinon.stub().resolves();

waterline.ibms.find.resolves([]);
});

after('stop HTTP server', function () {
Expand Down Expand Up @@ -440,6 +442,16 @@ describe('Http.Api.Nodes v1.1', function () {
host: '1.2.3.4',
user: 'myuser',
password: 'mypass'
},
toJSON: function () {
return {
service: 'ssh-ibm-service',
config: {
host: '1.2.3.4',
user: 'myuser',
password: 'REDACTED'
}
};
}
};
var serializedSshSettings = {
Expand All @@ -450,7 +462,7 @@ describe('Http.Api.Nodes v1.1', function () {

it('should return a list of the node\'s ssh settings', function () {
nodesApiService.getNodeById.resolves(sshNode);
waterline.ibms.findByNode.resolves(sshNode.sshSettings);
waterline.ibms.find.resolves([sshNode.sshSettings]);

return helper.request().get('/api/1.1/nodes/1234/ssh')
.expect('Content-Type', /^application\/json/)
Expand All @@ -467,7 +479,7 @@ describe('Http.Api.Nodes v1.1', function () {

it('should return a 404 if the node has no ssh settings', function () {
nodesApiService.getNodeById.resolves({ id: node.id, toJSON: function () { return; }});
waterline.ibms.findByNode.rejects(new Errors.NotFoundError('Not Found'));
waterline.ibms.find.rejects(new Errors.NotFoundError('Not Found'));

return helper.request().get('/api/1.1/nodes/1234/ssh')
.expect('Content-Type', /^application\/json/)
Expand Down Expand Up @@ -498,6 +510,16 @@ describe('Http.Api.Nodes v1.1', function () {
host: '5.5.5.5',
user: 'myuser2',
password: 'mypassword2'
},
toJSON: function () {
return {
service: 'ssh-ibm-service',
config: {
host: '5.5.5.5',
user: 'myuser2',
password: 'REDACTED'
}
};
}
};
var nodeWithIbm = {
Expand Down Expand Up @@ -530,7 +552,7 @@ describe('Http.Api.Nodes v1.1', function () {
it('should replace existing settings with a new set of ssh settings', function () {
waterline.nodes.needByIdentifier.resolves(existingNode);
waterline.ibms.upsertByNode.resolves(nodeWithIbm);
waterline.ibms.findByNode.resolves(modelSshSettings);
waterline.ibms.find.resolves([modelSshSettings]);
return helper.request().post('/api/1.1/nodes/1234abcd1234abcd1234abcd/ssh')
.send(updatedSshSettings)
.expect('Content-Type', /^application\/json/)
Expand All @@ -550,7 +572,7 @@ describe('Http.Api.Nodes v1.1', function () {
updated.sshSettings = updatedSshSettings;
waterline.nodes.needByIdentifier.resolves(existingNode);
waterline.ibms.upsertByNode.resolves(nodeWithIbm);
waterline.ibms.findByNode.resolves(modelSshSettings);
waterline.ibms.find.resolves([modelSshSettings]);
return helper.request().post('/api/1.1/nodes/1234abcd1234abcd1234abcd/ssh')
.send(updatedSshSettings)
.expect('Content-Type', /^application\/json/)
Expand Down
19 changes: 16 additions & 3 deletions spec/lib/services/nodes-api-service-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe("Http.Services.Api.Nodes", function () {
var _;
var eventsProtocol;
var Promise;
var findByNode;
var upsertByNodeIbm;

before("Http.Services.Api.Nodes before", function() {
helper.setupInjector([
Expand Down Expand Up @@ -56,6 +58,10 @@ describe("Http.Services.Api.Nodes", function () {
findAllByNode: function() {},
upsertByNode: function() {}
};
waterline.ibms = {
findByNode: function() {},
upsertByNode: function() {}
};
this.sandbox = sinon.sandbox.create();
});

Expand Down Expand Up @@ -99,6 +105,8 @@ describe("Http.Services.Api.Nodes", function () {
workflowApiService, 'findActiveGraphForTarget');
findAllByNode = this.sandbox.stub(waterline.obms, 'findAllByNode');
upsertByNode = this.sandbox.stub(waterline.obms, 'upsertByNode');
upsertByNodeIbm = this.sandbox.stub(waterline.ibms, 'upsertByNode');
findByNode = this.sandbox.stub(waterline.ibms, 'findByNode');
this.sandbox.stub(eventsProtocol, 'publishNodeEvent').resolves({});

});
Expand Down Expand Up @@ -166,11 +174,14 @@ describe("Http.Services.Api.Nodes", function () {
};

waterline.nodes.create.resolves(switchNode);
waterline.ibms.upsertByNode.resolves({});
waterline.ibms.findByNode.resolves(switchNode.snmpSettings);
this.sandbox.stub(workflowApiService, 'createAndRunGraph').resolves({});

return nodeApiService.postNode(switchNode)
.then(function() {
expect(waterline.obms.upsertByNode).to.not.be.called;
expect(waterline.ibms.upsertByNode).to.have.been.calledOnce;
expect(waterline.ibms.findByNode).to.have.been.calledOnce;
expect(workflowApiService.createAndRunGraph).to.have.been.calledOnce;
expect(workflowApiService.createAndRunGraph).to.have.been.calledWith(
{
Expand Down Expand Up @@ -214,7 +225,7 @@ describe("Http.Services.Api.Nodes", function () {

return nodeApiService.postNode(mgmtNode)
.then(function() {
expect(waterline.obms.upsertByNode).to.be.calledOne;
expect(waterline.obms.upsertByNode).to.be.calledOnce;
expect(waterline.obms.upsertByNode)
.to.be.calledWith(mgmtNode.id, mgmtNode.obms[0]);
expect(workflowApiService.createAndRunGraph).to.have.been.calledOnce;
Expand All @@ -240,11 +251,13 @@ describe("Http.Services.Api.Nodes", function () {
type: 'pdu'
};
waterline.nodes.create.resolves(pduNode);
waterline.ibms.upsertByNode.resolves({});
waterline.ibms.findByNode.resolves(pduNode.snmpSettings);
this.sandbox.stub(workflowApiService, 'createAndRunGraph').resolves({});

return nodeApiService.postNode(pduNode)
.then(function() {
expect(waterline.obms.upsertByNode).to.not.be.called;
expect(waterline.ibms.upsertByNode).to.have.been.calledOnce;
expect(workflowApiService.createAndRunGraph).to.have.been.calledOnce;
expect(workflowApiService.createAndRunGraph).to.have.been.calledWith(
{
Expand Down
16 changes: 8 additions & 8 deletions static/schemas/2.0/node.2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
"type": "object"
}
},
"snmpSettings": {
"description": "SNMP settings",
"type": "object"
},
"bootSettings": {
"description": "Default ipxe profile settings",
"type": "object"
Expand All @@ -37,16 +33,20 @@
"description": "Node relations",
"type": "array"
},
"sshSettings": {
"description": "SSH settings",
"type": "object"
},
"tags": {
"type": "array",
"items": {
"type": "string",
"uniqueItems": true
}
},
"identifiers": {
"description": "Node Macs",
"type": "array",
"items": {
"type": "string",
"uniqueItems": true
}
}
},
"additionalProperties": false
Expand Down