-
Notifications
You must be signed in to change notification settings - Fork 77
Enable discovery of UCS Chassis and Servers #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,8 @@ di.annotate(UcsDiscoveryJobFactory, new di.Inject( | |
| 'Services.Waterline', | ||
| 'Services.Encryption', | ||
| '_', | ||
| 'JobUtils.UcsTool' | ||
| 'JobUtils.UcsTool', | ||
| 'Constants' | ||
| )); | ||
|
|
||
| function UcsDiscoveryJobFactory( | ||
|
|
@@ -28,7 +29,8 @@ function UcsDiscoveryJobFactory( | |
| waterline, | ||
| encryption, | ||
| _, | ||
| UcsTool | ||
| UcsTool, | ||
| Constants | ||
| ) { | ||
| var logger = Logger.initialize(UcsDiscoveryJobFactory); | ||
|
|
||
|
|
@@ -77,7 +79,7 @@ function UcsDiscoveryJobFactory( | |
|
|
||
| return self.getRoot() | ||
| .then(function(root) { | ||
| return [ root, self.createRackmounts(root) ]; | ||
| return [ root, self.createRackmounts(root), self.createServers(root) ]; | ||
| }) | ||
| .spread(function() { | ||
| self._done(); | ||
|
|
@@ -140,44 +142,7 @@ function UcsDiscoveryJobFactory( | |
| return res.body; | ||
| }) | ||
| .map(function(data) { | ||
| assert.array(data.macs); | ||
| assert.string(data.name); | ||
| assert.string(data.path); | ||
|
|
||
| var config = Object.assign({}, self.settings); | ||
| obm = { | ||
| config: config, | ||
| service: 'ucs-obm-service' | ||
| }; | ||
| var node = { | ||
| type: 'compute', | ||
| name: data.path, | ||
| identifiers: data.macs, | ||
| obm:[obm], | ||
| relations : [] | ||
| }; | ||
|
|
||
| // Update existing node or create a new one | ||
| return waterline.nodes.needOne({identifiers:data.macs}) | ||
| .then(function(curNode) { | ||
| return waterline.nodes.updateOne( | ||
| { id: curNode.id }, | ||
| node | ||
| ) | ||
| .then(function(data){ | ||
| return data; | ||
| }); | ||
| }) | ||
| .catch(function(error) { | ||
| if (error.name === 'NotFoundError') { | ||
| return waterline.nodes.create(node); | ||
| } | ||
| throw error; | ||
| }) | ||
| .then(function(data){ | ||
| return self.createObms(data.id,obm); | ||
| }); | ||
|
|
||
| self.createNode(data, Constants.NodeTypes.Compute); | ||
| }); | ||
| }else{ | ||
| logger.warning('No rackmount servers found Found'); | ||
|
|
@@ -186,15 +151,114 @@ function UcsDiscoveryJobFactory( | |
| }); | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * @function getRoot | ||
| * @description create obm setting for the node | ||
| * @function createServers | ||
| * @description discovers all the chassis servers in the Cisco UCS | ||
| */ | ||
| UcsDiscoveryJob.prototype.createObms = function (nodeId, obm){ | ||
| return waterline.obms.upsertByNode(nodeId, obm) | ||
| .then(function(n) { | ||
| return n; | ||
| UcsDiscoveryJob.prototype.createServers = function (root) { | ||
| var self = this; | ||
| var username = this.settings.username; | ||
| var password = this.settings.password; | ||
| var ucs = this.settings.ucs; | ||
| var baseurl = | ||
| this.settings.protocol + "://" + this.settings.host + ":" + this.settings.port; | ||
| var url = | ||
| baseurl + "/chassis?host=" + ucs + "&user=" + username + "&password=" + password; | ||
| return Promise.try(function () { | ||
| if (!_.has(root, 'Chassis')) { | ||
| logger.warning('No rackmount servers found Found'); | ||
| return; | ||
| } | ||
| return self.ucs.clientRequest(url) | ||
| .then(function(res) { | ||
| assert.object(res); | ||
| return res.body; | ||
| }) | ||
| .map(function(chassisData) { | ||
| return self.createNode(chassisData, Constants.NodeTypes.Enclosure) | ||
| .spread(function (chassisNode) { | ||
| var chassisId = chassisNode.id; | ||
| var nodeList = []; | ||
| return Promise.map(chassisData.members, function (data) { | ||
| return self.createNode(data, Constants.NodeTypes.Compute) | ||
| .spread(function(newNode) { | ||
| var relations = [{ | ||
| relationType: 'enclosedBy', | ||
| targets: [chassisId] | ||
| }]; | ||
| nodeList.push(newNode.id); | ||
| return self.updateRelations(newNode.id, relations); | ||
| }); | ||
| }) | ||
| .then(function() { | ||
| var chassisRelations = [{ | ||
| relationType: 'encloses', | ||
| targets: nodeList | ||
| }]; | ||
| return self.updateRelations(chassisId, chassisRelations); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| UcsDiscoveryJob.prototype.updateRelations = function(nodeId, relations) { | ||
| // Update existing node with new relations or create one | ||
| return waterline.nodes.needOneById(nodeId) | ||
| .then(function(curNode) { | ||
| relations = _.uniq(relations.concat(curNode.relations), 'relationType'); | ||
| return waterline.nodes.updateOne( | ||
| { id: curNode.id }, | ||
| { relations: relations } | ||
| ); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| UcsDiscoveryJob.prototype.createNode = function(data, type) { | ||
|
|
||
| var self = this; | ||
| var config = Object.assign({}, self.settings); | ||
|
|
||
| assert.string(data.name); | ||
| assert.string(data.path); | ||
|
|
||
| var id; | ||
| if (type === Constants.NodeTypes.Compute) { | ||
| assert.array(data.macs); | ||
| id = data.macs; | ||
| } else { | ||
| id = [config.ucs, data.path]; | ||
| } | ||
|
|
||
| var obm = { | ||
| config: config, | ||
| service: 'ucs-obm-service' | ||
| }; | ||
|
|
||
| var node = { | ||
| type: type, | ||
| name: data.path, | ||
| identifiers: id, | ||
| relations : [] | ||
| }; | ||
|
|
||
| // Update existing node or create a new one | ||
| return waterline.nodes.needOne({identifiers:data.macs}) | ||
| .then(function(curNode) { | ||
| return waterline.nodes.updateOne( | ||
| { id: curNode.id }, | ||
| node | ||
| ); | ||
| }) | ||
| .catch(function(error) { | ||
| if (error.name === 'NotFoundError') { | ||
| return waterline.nodes.create(node); | ||
| } | ||
| throw error; | ||
| }) | ||
| .then(function(data){ | ||
| return [data, waterline.obms.upsertByNode(data.id,obm)]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a bug since this function is private and only used by your job, but may not a good design. This function will return For this comment, either change this or not is OK for me. Just give me two cents here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The node data is needed by the calling function, both promises need to be returned by the function.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @geoff-reid It doesn't look like you ever use the fulfillment value from the obms upsert, so maybe you can just do this instead: That will return a promise that fulfills to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brianparry got my meaning. |
||
| }); | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please confirm whether these macs will always be stored in fixed order for the same ucs server. For example, if the server has mac1 and mac2, if first time it returns
[mac1, mac2], but the second time it is[mac2, mac1]. These two array are not identical but this should be considered to be the same server.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make sure the ucs-service always returns the macs in the same order.