{"action":"created","comment":{"url":"https://api.github.com/repos/RackHD/on-http/pulls/comments/51198988","id":51198988,"diff_hunk":"@@ -0,0 +1,226 @@\n+// Copyright 2016, EMC, Inc.\n+\n+'use strict';\n+\n+var injector = require('../../../index.js').injector;\n+var redfish = injector.get('Http.Api.Services.Redfish');\n+var _ = injector.get('_');\n+var waterline = injector.get('Services.Waterline');\n+var Promise = injector.get('Promise');\n+var Errors = injector.get('Errors');\n+var taskProtocol = injector.get('Protocol.Task');\n+var basepath = '/redfish/v1';\n+var Errors = injector.get('Errors');\n+\n+module.exports = {\n+    listChassis: listChassis,\n+    getChassis: getChassis,\n+    getThermal: getThermal,\n+    getPower: getPower\n+};\n+\n+var dataFactory = function(identifier, dataName) {\n+    switch(dataName)  {\n+        case 'ohai':\n+        case 'dmi':\n+            return waterline.nodes.needByIdentifier(identifier)\n+            .then(function(node) {\n+                return waterline.catalogs.findLatestCatalogOfSource(node.id, dataName);\n+            })\n+            .then(function (catalogs) {\n+                if (_.isEmpty(catalogs)) {\n+                    throw new Errors.NotFoundError(\n+                        'No Catalogs Found for Source (' + dataName + ').'\n+                    );\n+                }\n+                return catalogs;\n+            });\n+        case 'system':\n+            return waterline.nodes.needByIdentifier(identifier)\n+            .then(function(node) {\n+                return _.filter(node.relations, function(relation) {\n+                    return relation.relationType === 'encloses';\n+                }).map(function(relation) {\n+                    return relation.targets[0];\n+                });\n+            });\n+        case 'chassis':\n+            return waterline.nodes.needByIdentifier(identifier)\n+            .then(function(node) {\n+                return _.filter(node.relations, function(relation) {\n+                    return relation.relationType === 'encloses';\n+                }).map(function(relation) {\n+                    return relation.targets;\n+                });\n+            })\n+            .then(function(targets) {\n+                return targets[0];\n+            });\n+        case 'chassisData':\n+            return waterline.workitems.findPollers({node: identifier})\n+            .filter(function(poller) {\n+                return poller.config.command === 'chassis';\n+            }).spread(function(poller) {\n+                return taskProtocol.requestPollerCache(poller.id, { latestOnly: true });\n+            }).then(function(data) {\n+                var chassisData = data[0].chassis;\n+                chassisData.power = (chassisData.power) ? 'On' : 'Off';\n+                return chassisData;\n+            });\n+        case 'sdrData':\n+            return waterline.workitems.findPollers({node: identifier})\n+            .filter(function(poller) {\n+                return poller.config.command === 'sdr';\n+            }).spread(function(poller) {\n+                return taskProtocol.requestPollerCache(poller.id, { latestOnly: true });\n+            }).then(function(data) {\n+                return data[0].sdr;\n+            });\n+    }\n+};\n+\n+function listChassis(req, res) {\n+    var options = {};\n+    options.basepath = basepath;\n+    options.templateScope = ['global'];\n+    options.url = req.url;\n+\n+    waterline.nodes.find({type: 'enclosure'}).then(function(nodes) {\n+        options.nodes = nodes;\n+        return redfish.render('redfish.1.0.0.chassiscollection.json', \n+                            'ChassisCollection.json#/definitions/ChassisCollection',\n+                            options);\n+    }).then(function(output) {\n+        res.status(200).json(output);\n+    })\n+    .catch(function(error) {\n+        res.status(500).json(error);\n+    });\n+}\n+\n+function getChassis(req, res) {\n+    var identifier = req.swagger.params.identifier.value;\n+    var options = {};\n+    options.basepath = basepath;\n+    options.templateScope = ['global'];\n+    options.url = req.url;\n+    options.identifier = identifier;\n+    options.chassisType = \"Other\";\n+    var typeEnum = [\r\n+\t\t\t\"Rack\",\r\n+\t\t\t\"Blade\",\r\n+\t\t\t\"Enclosure\",\r\n+\t\t\t\"StandAlone\",\r\n+\t\t\t\"Stand Alone\",\r\n+\t\t\t\"RackMount\",\r\n+\t\t\t\"Rack Mount\",\r\n+\t\t\t\"Card\",\r\n+\t\t\t\"Cartridge\",\r\n+\t\t\t\"Row\",\r\n+\t\t\t\"Pod\",\r\n+\t\t\t\"Expansion\",\r\n+\t\t\t\"Sidecar\",\r\n+\t\t\t\"Zone\",\r\n+\t\t\t\"Sled\",\r\n+\t\t\t\"Shelf\",\r\n+\t\t\t\"Drawer\",\r\n+\t\t\t\"Module\",\r\n+\t\t\t\"Component\",\r\n+\t\t\t\"Other\" ];\n+    \n+    dataFactory(identifier, 'system')\n+    .then(function(system) {\n+        return Promise.all([ dataFactory(identifier, 'chassis'),\n+                      dataFactory(system, 'ohai'),\n+                      dataFactory(system, 'chassisData') ])","path":"lib/api/redfish-1.0/chassis.js","position":135,"original_position":135,"commit_id":"58fdef6469896729756a4dd0e7716e4be4410bf6","original_commit_id":"58fdef6469896729756a4dd0e7716e4be4410bf6","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Missing semicolon.","created_at":"2016-01-28T22:32:55Z","updated_at":"2016-01-28T22:32:55Z","html_url":"https://github.com/RackHD/on-http/pull/105#discussion_r51198988","pull_request_url":"https://api.github.com/repos/RackHD/on-http/pulls/105","_links":{"self":{"href":"https://api.github.com/repos/RackHD/on-http/pulls/comments/51198988"},"html":{"href":"https://github.com/RackHD/on-http/pull/105#discussion_r51198988"},"pull_request":{"href":"https://api.github.com/repos/RackHD/on-http/pulls/105"}}},"pull_request":{"url":"https://api.github.com/repos/RackHD/on-http/pulls/105","id":57449553,"html_url":"https://github.com/RackHD/on-http/pull/105","diff_url":"https://github.com/RackHD/on-http/pull/105.diff","patch_url":"https://github.com/RackHD/on-http/pull/105.patch","issue_url":"https://api.github.com/repos/RackHD/on-http/issues/105","number":105,"state":"open","locked":false,"title":"Extend redfish API for Chassis","user":{"login":"jlongever","id":13769308,"avatar_url":"https://avatars.githubusercontent.com/u/13769308?v=3","gravatar_id":"","url":"https://api.github.com/users/jlongever","html_url":"https://github.com/jlongever","followers_url":"https://api.github.com/users/jlongever/followers","following_url":"https://api.github.com/users/jlongever/following{/other_user}","gists_url":"https://api.github.com/users/jlongever/gists{/gist_id}","starred_url":"https://api.github.com/users/jlongever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlongever/subscriptions","organizations_url":"https://api.github.com/users/jlongever/orgs","repos_url":"https://api.github.com/users/jlongever/repos","events_url":"https://api.github.com/users/jlongever/events{/privacy}","received_events_url":"https://api.github.com/users/jlongever/received_events","type":"User","site_admin":false},"body":"- Add Chassis root and collections path\r\n- Add Thermal reference object\r\n- Add Power reference object\r\n- Add unit-tests\r\n\r\n@RackHD/corecommitters @zyoung51 @keedya @uppalk1 @tannoa2 ","created_at":"2016-01-28T03:19:51Z","updated_at":"2016-01-28T22:32:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a2cc0e0aa98efd42d227cf81e6c7ba6d5be8bc25","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/RackHD/on-http/pulls/105/commits","review_comments_url":"https://api.github.com/repos/RackHD/on-http/pulls/105/comments","review_comment_url":"https://api.github.com/repos/RackHD/on-http/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RackHD/on-http/issues/105/comments","statuses_url":"https://api.github.com/repos/RackHD/on-http/statuses/58fdef6469896729756a4dd0e7716e4be4410bf6","head":{"label":"jlongever:feature/chassis-redfish-api","ref":"feature/chassis-redfish-api","sha":"58fdef6469896729756a4dd0e7716e4be4410bf6","user":{"login":"jlongever","id":13769308,"avatar_url":"https://avatars.githubusercontent.com/u/13769308?v=3","gravatar_id":"","url":"https://api.github.com/users/jlongever","html_url":"https://github.com/jlongever","followers_url":"https://api.github.com/users/jlongever/followers","following_url":"https://api.github.com/users/jlongever/following{/other_user}","gists_url":"https://api.github.com/users/jlongever/gists{/gist_id}","starred_url":"https://api.github.com/users/jlongever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlongever/subscriptions","organizations_url":"https://api.github.com/users/jlongever/orgs","repos_url":"https://api.github.com/users/jlongever/repos","events_url":"https://api.github.com/users/jlongever/events{/privacy}","received_events_url":"https://api.github.com/users/jlongever/received_events","type":"User","site_admin":false},"repo":{"id":47519290,"name":"on-http","full_name":"jlongever/on-http","owner":{"login":"jlongever","id":13769308,"avatar_url":"https://avatars.githubusercontent.com/u/13769308?v=3","gravatar_id":"","url":"https://api.github.com/users/jlongever","html_url":"https://github.com/jlongever","followers_url":"https://api.github.com/users/jlongever/followers","following_url":"https://api.github.com/users/jlongever/following{/other_user}","gists_url":"https://api.github.com/users/jlongever/gists{/gist_id}","starred_url":"https://api.github.com/users/jlongever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlongever/subscriptions","organizations_url":"https://api.github.com/users/jlongever/orgs","repos_url":"https://api.github.com/users/jlongever/repos","events_url":"https://api.github.com/users/jlongever/events{/privacy}","received_events_url":"https://api.github.com/users/jlongever/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jlongever/on-http","description":"","fork":true,"url":"https://api.github.com/repos/jlongever/on-http","forks_url":"https://api.github.com/repos/jlongever/on-http/forks","keys_url":"https://api.github.com/repos/jlongever/on-http/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jlongever/on-http/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jlongever/on-http/teams","hooks_url":"https://api.github.com/repos/jlongever/on-http/hooks","issue_events_url":"https://api.github.com/repos/jlongever/on-http/issues/events{/number}","events_url":"https://api.github.com/repos/jlongever/on-http/events","assignees_url":"https://api.github.com/repos/jlongever/on-http/assignees{/user}","branches_url":"https://api.github.com/repos/jlongever/on-http/branches{/branch}","tags_url":"https://api.github.com/repos/jlongever/on-http/tags","blobs_url":"https://api.github.com/repos/jlongever/on-http/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jlongever/on-http/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jlongever/on-http/git/refs{/sha}","trees_url":"https://api.github.com/repos/jlongever/on-http/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jlongever/on-http/statuses/{sha}","languages_url":"https://api.github.com/repos/jlongever/on-http/languages","stargazers_url":"https://api.github.com/repos/jlongever/on-http/stargazers","contributors_url":"https://api.github.com/repos/jlongever/on-http/contributors","subscribers_url":"https://api.github.com/repos/jlongever/on-http/subscribers","subscription_url":"https://api.github.com/repos/jlongever/on-http/subscription","commits_url":"https://api.github.com/repos/jlongever/on-http/commits{/sha}","git_commits_url":"https://api.github.com/repos/jlongever/on-http/git/commits{/sha}","comments_url":"https://api.github.com/repos/jlongever/on-http/comments{/number}","issue_comment_url":"https://api.github.com/repos/jlongever/on-http/issues/comments{/number}","contents_url":"https://api.github.com/repos/jlongever/on-http/contents/{+path}","compare_url":"https://api.github.com/repos/jlongever/on-http/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jlongever/on-http/merges","archive_url":"https://api.github.com/repos/jlongever/on-http/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jlongever/on-http/downloads","issues_url":"https://api.github.com/repos/jlongever/on-http/issues{/number}","pulls_url":"https://api.github.com/repos/jlongever/on-http/pulls{/number}","milestones_url":"https://api.github.com/repos/jlongever/on-http/milestones{/number}","notifications_url":"https://api.github.com/repos/jlongever/on-http/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jlongever/on-http/labels{/name}","releases_url":"https://api.github.com/repos/jlongever/on-http/releases{/id}","deployments_url":"https://api.github.com/repos/jlongever/on-http/deployments","created_at":"2015-12-07T00:04:52Z","updated_at":"2016-01-11T23:21:53Z","pushed_at":"2016-01-28T22:28:55Z","git_url":"git://github.com/jlongever/on-http.git","ssh_url":"git@github.com:jlongever/on-http.git","clone_url":"https://github.com/jlongever/on-http.git","svn_url":"https://github.com/jlongever/on-http","homepage":null,"size":1721,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"RackHD:master","ref":"master","sha":"3edc0af96958939381bd12a3d015e7570ab01fd3","user":{"login":"RackHD","id":13982662,"avatar_url":"https://avatars.githubusercontent.com/u/13982662?v=3","gravatar_id":"","url":"https://api.github.com/users/RackHD","html_url":"https://github.com/RackHD","followers_url":"https://api.github.com/users/RackHD/followers","following_url":"https://api.github.com/users/RackHD/following{/other_user}","gists_url":"https://api.github.com/users/RackHD/gists{/gist_id}","starred_url":"https://api.github.com/users/RackHD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RackHD/subscriptions","organizations_url":"https://api.github.com/users/RackHD/orgs","repos_url":"https://api.github.com/users/RackHD/repos","events_url":"https://api.github.com/users/RackHD/events{/privacy}","received_events_url":"https://api.github.com/users/RackHD/received_events","type":"Organization","site_admin":false},"repo":{"id":41690081,"name":"on-http","full_name":"RackHD/on-http","owner":{"login":"RackHD","id":13982662,"avatar_url":"https://avatars.githubusercontent.com/u/13982662?v=3","gravatar_id":"","url":"https://api.github.com/users/RackHD","html_url":"https://github.com/RackHD","followers_url":"https://api.github.com/users/RackHD/followers","following_url":"https://api.github.com/users/RackHD/following{/other_user}","gists_url":"https://api.github.com/users/RackHD/gists{/gist_id}","starred_url":"https://api.github.com/users/RackHD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RackHD/subscriptions","organizations_url":"https://api.github.com/users/RackHD/orgs","repos_url":"https://api.github.com/users/RackHD/repos","events_url":"https://api.github.com/users/RackHD/events{/privacy}","received_events_url":"https://api.github.com/users/RackHD/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RackHD/on-http","description":"","fork":false,"url":"https://api.github.com/repos/RackHD/on-http","forks_url":"https://api.github.com/repos/RackHD/on-http/forks","keys_url":"https://api.github.com/repos/RackHD/on-http/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RackHD/on-http/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RackHD/on-http/teams","hooks_url":"https://api.github.com/repos/RackHD/on-http/hooks","issue_events_url":"https://api.github.com/repos/RackHD/on-http/issues/events{/number}","events_url":"https://api.github.com/repos/RackHD/on-http/events","assignees_url":"https://api.github.com/repos/RackHD/on-http/assignees{/user}","branches_url":"https://api.github.com/repos/RackHD/on-http/branches{/branch}","tags_url":"https://api.github.com/repos/RackHD/on-http/tags","blobs_url":"https://api.github.com/repos/RackHD/on-http/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RackHD/on-http/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RackHD/on-http/git/refs{/sha}","trees_url":"https://api.github.com/repos/RackHD/on-http/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RackHD/on-http/statuses/{sha}","languages_url":"https://api.github.com/repos/RackHD/on-http/languages","stargazers_url":"https://api.github.com/repos/RackHD/on-http/stargazers","contributors_url":"https://api.github.com/repos/RackHD/on-http/contributors","subscribers_url":"https://api.github.com/repos/RackHD/on-http/subscribers","subscription_url":"https://api.github.com/repos/RackHD/on-http/subscription","commits_url":"https://api.github.com/repos/RackHD/on-http/commits{/sha}","git_commits_url":"https://api.github.com/repos/RackHD/on-http/git/commits{/sha}","comments_url":"https://api.github.com/repos/RackHD/on-http/comments{/number}","issue_comment_url":"https://api.github.com/repos/RackHD/on-http/issues/comments{/number}","contents_url":"https://api.github.com/repos/RackHD/on-http/contents/{+path}","compare_url":"https://api.github.com/repos/RackHD/on-http/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RackHD/on-http/merges","archive_url":"https://api.github.com/repos/RackHD/on-http/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RackHD/on-http/downloads","issues_url":"https://api.github.com/repos/RackHD/on-http/issues{/number}","pulls_url":"https://api.github.com/repos/RackHD/on-http/pulls{/number}","milestones_url":"https://api.github.com/repos/RackHD/on-http/milestones{/number}","notifications_url":"https://api.github.com/repos/RackHD/on-http/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RackHD/on-http/labels{/name}","releases_url":"https://api.github.com/repos/RackHD/on-http/releases{/id}","deployments_url":"https://api.github.com/repos/RackHD/on-http/deployments","created_at":"2015-08-31T17:29:08Z","updated_at":"2016-01-26T18:11:40Z","pushed_at":"2016-01-28T22:28:55Z","git_url":"git://github.com/RackHD/on-http.git","ssh_url":"git@github.com:RackHD/on-http.git","clone_url":"https://github.com/RackHD/on-http.git","svn_url":"https://github.com/RackHD/on-http","homepage":null,"size":2036,"stargazers_count":7,"watchers_count":7,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":6,"forks":31,"open_issues":6,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RackHD/on-http/pulls/105"},"html":{"href":"https://github.com/RackHD/on-http/pull/105"},"issue":{"href":"https://api.github.com/repos/RackHD/on-http/issues/105"},"comments":{"href":"https://api.github.com/repos/RackHD/on-http/issues/105/comments"},"review_comments":{"href":"https://api.github.com/repos/RackHD/on-http/pulls/105/comments"},"review_comment":{"href":"https://api.github.com/repos/RackHD/on-http/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RackHD/on-http/pulls/105/commits"},"statuses":{"href":"https://api.github.com/repos/RackHD/on-http/statuses/58fdef6469896729756a4dd0e7716e4be4410bf6"}}}}