├── snapshot ├── dev_config.PNG ├── ironic_info.png ├── shovel_func.png └── shovel_settings.png ├── scripts ├── post-install.sh ├── shovel.conf └── index.html ├── .eslintrc.js ├── main.js ├── lib ├── services │ ├── encryption.js │ ├── logger.js │ └── poller.js └── api │ ├── openstack │ ├── glance.js │ ├── keystone.js │ └── ironic.js │ ├── monorail │ └── monorail.js │ └── client.js ├── shovel_instructions.md ├── config.json ├── package.json ├── test ├── helper.js ├── api │ ├── ironic.js │ ├── client.js │ └── monorail.js ├── services │ └── poller.js └── controllers │ └── Shovel.js ├── index.js ├── README.md ├── LICENSE ├── api └── swagger.json └── controllers └── Shovel.js /snapshot/dev_config.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/shovel/master/snapshot/dev_config.PNG -------------------------------------------------------------------------------- /snapshot/ironic_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/shovel/master/snapshot/ironic_info.png -------------------------------------------------------------------------------- /snapshot/shovel_func.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/shovel/master/snapshot/shovel_func.png -------------------------------------------------------------------------------- /snapshot/shovel_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/shovel/master/snapshot/shovel_settings.png -------------------------------------------------------------------------------- /scripts/post-install.sh: -------------------------------------------------------------------------------- 1 | cp scripts/index.html node_modules/swagger-tools/middleware/swagger-ui/ 2 | cp scripts/shovel.conf /etc/init/shovel.conf 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "rules": { 3 | "indent": [ 4 | 2, 5 | 4 6 | ], 7 | "quotes": [ 8 | 2, 9 | "single" 10 | ], 11 | "linebreak-style": [ 12 | 2, 13 | "unix" 14 | ], 15 | "semi": [ 16 | 2, 17 | "always" 18 | ] 19 | }, 20 | "env": { 21 | "es6": true, 22 | "browser": true 23 | }, 24 | "extends": "openstack" 25 | }; 26 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | var cp = require('child_process'); 2 | var fs = require('fs'); 3 | 4 | var server = cp.fork('index.js'); 5 | console.log('Server started'); 6 | 7 | fs.watchFile('config.json', function (event, filename) { 8 | server.kill(); 9 | console.log('Server stopped'); 10 | server = cp.fork('index.js'); 11 | console.log('Server started'); 12 | }); 13 | 14 | process.on('SIGINT', function () { 15 | server.kill(); 16 | fs.unwatchFile('config.json'); 17 | console.info('found an error in the server'); 18 | process.exit(); 19 | }); -------------------------------------------------------------------------------- /scripts/shovel.conf: -------------------------------------------------------------------------------- 1 | #!upstart 2 | description "start shovel server" 3 | 4 | start on startup 5 | stop on shutdown 6 | 7 | script 8 | export HOME="/root" 9 | echo $$ > /var/run/shovel.pid 10 | echo Starting shovel service 11 | chdir /var/Shovel/ 12 | exec /usr/bin/nodejs main.js >> /var/log/shovel.log 2>&1 13 | end script 14 | 15 | pre-start script 16 | echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/shovel.log 17 | end script 18 | 19 | pre-stop script 20 | rm /var/run/shovel.pid 21 | echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/shovel.log 22 | end script 23 | -------------------------------------------------------------------------------- /lib/services/encryption.js: -------------------------------------------------------------------------------- 1 | /*eslint-env node*/ 2 | var crypto = require('crypto'); 3 | var config = require('./../../config.json'); 4 | 5 | var CryptoFuncs = { 6 | encrypt: function (text) { 7 | 'use strict'; 8 | var cipher = crypto.createCipher('aes-256-cbc', config.key); 9 | cipher.update(text, 'utf8', 'base64'); 10 | return cipher.final('base64'); 11 | }, 12 | decrypt: function (text) { 13 | 'use strict'; 14 | var decipher = crypto.createDecipher('aes-256-cbc', config.key); 15 | decipher.update(text, 'base64', 'utf8'); 16 | return decipher.final('utf8'); 17 | } 18 | }; 19 | 20 | module.exports = Object.create(CryptoFuncs); 21 | -------------------------------------------------------------------------------- /lib/services/logger.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | /*eslint-env node*/ 4 | var winston = require('winston'); 5 | 6 | module.exports.Logger = function Logger(level) { 7 | 'use strict'; 8 | var logger = new winston.Logger({ 9 | levels: { 10 | verbose: 5, 11 | debug: 4, 12 | info: 3, 13 | warn: 2, 14 | error: 1, 15 | mask: 0 16 | }, 17 | colors: { 18 | verbose: 'cyan', 19 | debug: 'blue', 20 | info: 'green', 21 | warn: 'yellow', 22 | error: 'red' 23 | } 24 | }).add(winston.transports.Console, { 25 | level: level, 26 | prettyPrint: true, 27 | colorize: true, 28 | silent: false, 29 | timestamp: true 30 | }); 31 | return logger; 32 | }; 33 | -------------------------------------------------------------------------------- /lib/api/openstack/glance.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | /*eslint-env node*/ 4 | var config = require('./../../../config.json'); 5 | var client = require('./../client'); 6 | var Promise = require('bluebird'); 7 | Promise.promisifyAll(client); 8 | 9 | var pfx = config.glance.version; 10 | var request = { 11 | host: config.glance.httpHost, 12 | port: config.glance.httpPort, 13 | path: pfx, 14 | token: '', 15 | data: '' 16 | }; 17 | 18 | /* 19 | * glance wrapper functions 20 | */ 21 | var glanceWrapper = { 22 | get_images: function (token) { 23 | 'use strict'; 24 | request.token = token; 25 | request.path = pfx + '/images'; 26 | return client.GetAsync(request); 27 | }, 28 | getStatus: function () { 29 | 'use strict'; 30 | return client.getStatus(); 31 | } 32 | }; 33 | module.exports = Object.create(glanceWrapper); 34 | -------------------------------------------------------------------------------- /shovel_instructions.md: -------------------------------------------------------------------------------- 1 | # RackHD/OpenStack Coordinator (shovel) 2 | 3 | You can install Shovel by cloning this repo 4 | 5 | ```sh 6 | git clone https://github.com/openstack/shovel.git 7 | sudo mv Shovel /var/ 8 | cd /var/Shovel 9 | sudo npm install 10 | sudo ./scripts/post-install.sh 11 | sudo npm start 12 | ``` 13 | Or you can use npm install to Download shovel package 14 | 15 | ```sh 16 | npm install node-shovel 17 | sudo mv node_modules/node-shovel /var/Shovel 18 | cd /var/Shovel 19 | sudo ./scripts/post-install.sh 20 | sudo npm start 21 | ``` 22 | 23 | Once the service is running, you can use swagger GUI to setup RackHD, Ironic, Keystone and Glance hostname and login information: http://:9005/docs (You can also change Shovel Port(default:9005) note that the service will restart with the new configuration. 24 | 25 | ## Shovel-Ironic Set info Example: 26 | 27 | ![alt text](snapshot/ironic_info.png) 28 | 29 | ## Shovel Set Port Example: 30 | 31 | ![alt text](snapshot/shovel_settings.png) 32 | 33 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "shovel": { 3 | "appver": "v0.1", 4 | "apiver": "v1.1", 5 | "httpPort": 9005, 6 | "hostname": "0.0.0.0" 7 | }, 8 | "monorail": { 9 | "httpHost": "172.31.128.1", 10 | "httpPort": "8080", 11 | "version": "1.1" 12 | }, 13 | "ironic": { 14 | "httpHost": "172.31.128.145", 15 | "httpPort": "6385", 16 | "version": "v1", 17 | "os_username": "admin", 18 | "os_password": "WUAPAvNNK+51D+JsotLxCQ==", 19 | "os_tenant_name": "admin", 20 | "os_auth_token": "None", 21 | "insecure": "False" 22 | }, 23 | "keystone": { 24 | "httpHost": "172.31.128.145", 25 | "httpPort": "5000", 26 | "version": "v2.0" 27 | }, 28 | "glance": { 29 | "httpHost": "172.31.128.145", 30 | "httpPort": "9292", 31 | "version": "v1", 32 | "os_username": "admin", 33 | "os_password": "WUAPAvNNK+51D+JsotLxCQ==", 34 | "os_tenant_name": "admin", 35 | "os_auth_token": "None", 36 | "insecure": "False" 37 | }, 38 | "key": "CBC6CEB67F4A347DCE43D83A6FA16" 39 | } 40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-shovel", 3 | "version": "1.0.4", 4 | "description": "RackHD-OpenStack Coordinator", 5 | "main": "main.js", 6 | "keywords": [ 7 | "swagger" 8 | ], 9 | "license": "Apache-2.0", 10 | "dependencies": { 11 | "bluebird": "3.1.1", 12 | "swagger-tools": "0.8.*", 13 | "should": "~7.0.1", 14 | "mocha": "^2.1.0", 15 | "sinon": "1.16.1", 16 | "supertest": "^0.15.0", 17 | "underscore": "^1.8.3", 18 | "xunit-file": "0.0.6", 19 | "winston": "2.1.1", 20 | "jsonfile": "2.2.3", 21 | "crypto": "0.0.3", 22 | "istanbul": "0.4.1", 23 | "nock": "3.6.0", 24 | "eslint-config-openstack": "~1.2.3", 25 | "eslint": "~1.10.3", 26 | "express": "~4.13.4", 27 | "tar": "~2.2.1" 28 | }, 29 | "scripts": { 30 | "start": "start shovel", 31 | "test": "istanbul cover -x '**/test/**' node_modules/mocha/bin/_mocha test/api/* test/services/* test/controllers/* && istanbul report cobertura", 32 | "lint": "./node_modules/eslint/bin/eslint.js controllers/Shovel.js lib/*" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/helper.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | var app = require('express')(); 4 | var http = require('http'); 5 | var swaggerTools = require('swagger-tools'); 6 | var sinon = require('sinon'); 7 | var winston = require('winston'); 8 | var logger = require('./../lib/services/logger'); 9 | var loggerVar = new (winston.Logger)({ 10 | levels: { verbose: 5, debug: 4, info: 3, warn: 2, error: 1, mask: 0 }, 11 | colors: { verbose: 'cyan', debug: 'blue', info: 'green', warn: 'yellow', error: 'red' } 12 | }) 13 | .add(winston.transports.Console, { level: 'mask' }); 14 | var options = { 15 | swaggerUi: '/swagger.json', 16 | controllers: './controllers', 17 | useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode) 18 | }; 19 | var swaggerDoc = require('./../api/swagger.json'); 20 | 21 | module.exports.maskLogger = function maskLogger() { 22 | sinon.stub(logger, 'Logger').returns(loggerVar); 23 | }; 24 | 25 | module.exports.restoreLogger = function restoreLogger() { 26 | logger['Logger'].restore(); 27 | }; 28 | 29 | module.exports.startServer = function startServer() { 30 | this.maskLogger(); 31 | swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) { 32 | app.use(middleware.swaggerMetadata()); 33 | app.use(middleware.swaggerRouter(options)); 34 | http.createServer(app).listen(9008, 'localhost'); 35 | }); 36 | }; 37 | module.exports.stopServer = function stopServer() { 38 | this.restoreLogger(); 39 | var net = require('net'); 40 | var socket = net.createConnection(9008); 41 | socket.end(); 42 | }; -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* global process */ 2 | 'use strict'; 3 | 4 | var app = require('express')(); 5 | var http = require('http'); 6 | var swaggerTools = require('swagger-tools'); 7 | var config = require('./config.json'); 8 | var Poller = require('./lib/services/poller'); 9 | var serverPort = config.shovel.httpPort; 10 | 11 | // swaggerRouter configuration 12 | var options = { 13 | swaggerUi: '/swagger.json', 14 | controllers: './controllers', 15 | useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode) 16 | }; 17 | 18 | // The Swagger document (require it, build it programmatically, fetch it from a URL, ...) 19 | var swaggerDoc = require('./api/swagger.json'); 20 | 21 | // Initialize the Swagger middleware 22 | swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) { 23 | // Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain 24 | app.use(middleware.swaggerMetadata()); 25 | 26 | // Validate Swagger requests 27 | app.use(middleware.swaggerValidator()); 28 | 29 | // Route validated requests to appropriate controller 30 | app.use(middleware.swaggerRouter(options)); 31 | 32 | // Serve the Swagger documents and Swagger UI 33 | app.use(middleware.swaggerUi()); 34 | 35 | // Start the server 36 | http.createServer(app).listen(config.shovel.httpPort, config.shovel.hostname, function () { 37 | console.log('Your server is listening on port %d ', config.shovel.httpPort); 38 | console.log('Swagger-ui is available on http://%s:%d/docs', config.shovel.hostname, config.shovel.httpPort); 39 | var pollerInstance = new Poller(5000);//timeInterval to 5s 40 | pollerInstance.startServer(); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /lib/api/openstack/keystone.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | /*eslint-env node*/ 4 | /* keystone authentication */ 5 | var config = require('./../../../config.json'); 6 | var client = require('./../client'); 7 | var Promise = require('bluebird'); 8 | var encryption = require('./../../services/encryption'); 9 | var logger = require('./../../services/logger').Logger; 10 | 11 | Promise.promisifyAll(client); 12 | 13 | var request = { 14 | host: config.keystone.httpHost, 15 | path: '/' + config.keystone.version + '/tokens', 16 | port: config.keystone.httpPort, 17 | token: '', 18 | data: {}, 19 | api: {}, 20 | useragent: '' 21 | }; 22 | 23 | var KeystoneAuthentication = { 24 | authenticatePassword: function (tenantName, username, password) { 25 | 'use strict'; 26 | var decrypted; 27 | try { 28 | decrypted = encryption.decrypt(password); 29 | } catch (err) { 30 | logger.error(err); 31 | //return empty promise 32 | return Promise.resolve(); 33 | } 34 | request.data = JSON.stringify( 35 | { 36 | auth: { 37 | tenantName: tenantName, 38 | passwordCredentials: { 39 | username: username, 40 | password: decrypted 41 | 42 | } 43 | } 44 | }); 45 | return client.PostAsync(request); 46 | }, 47 | 48 | authenticateToken: function (tenantName, username, token) { 49 | 'use strict'; 50 | request.data = JSON.stringify( 51 | { 52 | auth: { 53 | tenantName: tenantName, 54 | token: { 55 | id: token 56 | } 57 | } 58 | }); 59 | return client.PostAsync(request); 60 | }, 61 | getStatus: function () { 62 | 'use strict'; 63 | return client.getStatus(); 64 | } 65 | }; 66 | module.exports = Object.create(KeystoneAuthentication); 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shovel(RackHD/OpenStack Coordinator) 2 | 3 | Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. 4 | 5 | ## Description 6 | Shovel is an application that provides a service with a set of APIs that wraps around RackHD/Ironic existing APIs allowing users to find Baremetal Compute nodes dynamically discovered by RackHD and register/unregister them with Ironic (OpenStack Bare Metal Provisioning Program).Shovel also provides poller service that monitors compute nodes and logs the errors from SEL into Ironic Database. 7 | 8 | A Shovel Horizon plugin is also provided to interface with the Shovel service. The plugin adds a new Panel to the admin Dashboard called rackhd that displays a table of all the Baremetal systems discovered by RackHD. It also allows the user to see the node catalog in a nice table View, Register/Unregister node in Ironic, display node SEL and enable/register a failover node. 9 | 10 | ## Demo 11 | Shovel 13 | 14 | ## Instructions 15 | - Use [RackHD: Quick Setup](http://rackhd.readthedocs.org/en/latest/getting_started.html) to install [RackHD](https://github.com/RackHD/RackHD). 16 | - Use Devstack to [Deploy Openstack](http://docs.openstack.org/developer/ironic/dev/dev-quickstart.html#deploying-ironic-with-devstack) to a single machine. 17 | - Shovel-Horizon consists of two repositories: 18 | - Service Application called Shovel, serves as [RackHD](https://github.com/RackHD/RackHD)/[Ironic](https://wiki.openstack.org/wiki/Ironic) coordinator (Readme [Instructions](shovel_instructions.md) to setup the service). 19 | - [Shovel Horizon](https://github.com/keedya/shovel-horizon-plugin) Plug-in ( [Instructions](https://github.com/keedya/shovel-horizon-plugin/blob/master/README.md) to Deploy plug-in to Horizon interface). 20 | 21 | ### System level Diagram 22 | ![alt text](snapshot/dev_config.PNG) 23 | 24 | ### Services Diagram 25 | ![alt text](snapshot/shovel_func.png) 26 | 27 | 28 | ## Licensing 29 | 30 | Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 31 | 32 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 33 | 34 | RackHD is a Trademark of Dell EMC 35 | 36 | ## Support 37 | Please file bugs and issues at the GitHub issues page. 38 | -------------------------------------------------------------------------------- /lib/api/openstack/ironic.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | /*eslint-env node*/ 4 | var config = require('./../../../config.json'); 5 | var client = require('./../client'); 6 | var Promise = require('bluebird'); 7 | Promise.promisifyAll(client); 8 | var pfx = config.ironic.version; 9 | var request = { 10 | host: config.ironic.httpHost, 11 | port: config.ironic.httpPort, 12 | path: pfx, 13 | token: '', 14 | data: '', 15 | api: { 16 | name: 'X-OpenStack-Ironic-API-Version', 17 | version: '1.6' 18 | } 19 | }; 20 | 21 | /* 22 | * Ironic wrapper functions 23 | */ 24 | var ironicWrapper = { 25 | get_chassis: function (token) { 26 | 'use strict'; 27 | request.token = token; 28 | request.path = pfx + '/chassis'; 29 | return client.GetAsync(request); 30 | 31 | }, 32 | get_chassis_by_id: function (token, identifier) { 33 | 'use strict'; 34 | request.token = token; 35 | request.path = pfx + '/chassis/' + identifier; 36 | return client.GetAsync(request); 37 | }, 38 | get_node_list: function (token) { 39 | 'use strict'; 40 | request.token = token; 41 | request.path = pfx + '/nodes/detail'; 42 | return client.GetAsync(request); 43 | }, 44 | get_node: function (token, identifier) { 45 | 'use strict'; 46 | request.token = token; 47 | request.path = pfx + '/nodes/' + identifier; 48 | return client.GetAsync(request); 49 | }, 50 | create_node: function (token, node) { 51 | 'use strict'; 52 | request.token = token; 53 | request.path = pfx + '/nodes'; 54 | request.data = node; 55 | return client.PostAsync(request); 56 | }, 57 | patch_node: function (token, identifier, data) { 58 | 'use strict'; 59 | request.token = token; 60 | request.path = pfx + '/nodes/' + identifier; 61 | request.data = data; 62 | return client.PatchAsync(request); 63 | }, 64 | delete_node: function (token, identifier) { 65 | 'use strict'; 66 | request.token = token; 67 | request.path = pfx + '/nodes/' + identifier; 68 | return client.DeleteAsync(request); 69 | }, 70 | get_port_list: function (token) { 71 | 'use strict'; 72 | request.token = token; 73 | request.path = pfx + '/ports'; 74 | return client.GetAsync(request); 75 | }, 76 | get_port: function (token, identifier) { 77 | 'use strict'; 78 | request.token = token; 79 | request.path = pfx + '/ports/' + identifier; 80 | return client.GetAsync(request); 81 | }, 82 | create_port: function (token, port) { 83 | 'use strict'; 84 | request.token = token; 85 | request.path = pfx + '/ports'; 86 | request.data = port; 87 | return client.PostAsync(request); 88 | }, 89 | set_power_state: function (token, identifier, state) { 90 | 'use strict'; 91 | request.token = token; 92 | request.path = pfx + '/nodes/' + identifier + '/states/power'; 93 | if (state === 'off' || state === 'on') { 94 | request.data = JSON.stringify({ target: 'power ' + state }); 95 | } 96 | if (state === 'reboot') { 97 | request.data = JSON.stringify({ target: 'rebooting' }); 98 | } 99 | return client.PutAsync(request); 100 | }, 101 | get_driver_list: function (token) { 102 | 'use strict'; 103 | request.token = token; 104 | request.path = pfx + '/drivers'; 105 | return client.GetAsync(request); 106 | }, 107 | getStatus: function () { 108 | 'use strict'; 109 | return client.getStatus(); 110 | } 111 | }; 112 | 113 | module.exports = Object.create(ironicWrapper); 114 | -------------------------------------------------------------------------------- /test/api/ironic.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | var request = require('supertest'); 4 | var should = require('should'); 5 | var sinon = require('sinon'); 6 | var ironic = require('./../../lib/api/openstack/ironic'); 7 | var client = require('./../../lib/api/client'); 8 | var Promise = require('bluebird'); 9 | Promise.promisifyAll(client); 10 | 11 | describe('****Ironic Lib****', function () { 12 | beforeEach('set up mocks', function () { 13 | var output = ({ data: 'ironic service' }); 14 | sinon.stub(client, 'GetAsync').returns(Promise.resolve(output)); 15 | sinon.stub(client, 'PostAsync').returns(Promise.resolve(output)); 16 | sinon.stub(client, 'PatchAsync').returns(Promise.resolve(output)); 17 | sinon.stub(client, 'PutAsync').returns(Promise.resolve(output)); 18 | sinon.stub(client, 'DeleteAsync').returns(Promise.resolve(output)); 19 | }); 20 | afterEach('teardown mocks', function () { 21 | client['GetAsync'].restore(); 22 | client['PostAsync'].restore(); 23 | client['PatchAsync'].restore(); 24 | client['PutAsync'].restore(); 25 | client['DeleteAsync'].restore(); 26 | 27 | }); 28 | it('ironic.get_chassis return data from ironic', function (done) { 29 | return ironic.get_chassis('123') 30 | .then(function (result) { 31 | result.should.have.property('data'); 32 | done(); 33 | }); 34 | }); 35 | it('get_chassis_by_id return data from ironic', function (done) { 36 | return ironic.get_chassis_by_id('123', '123') 37 | .then(function (result) { 38 | result.should.have.property('data'); 39 | done(); 40 | }); 41 | }); 42 | it('get_chassis_by_id return data from ironic', function (done) { 43 | return ironic.get_node_list('123') 44 | .then(function (result) { 45 | result.should.have.property('data'); 46 | done(); 47 | 48 | }); 49 | }); 50 | it('get_node return data from ironic', function (done) { 51 | return ironic.get_node('123', '123') 52 | .then(function (result) { 53 | result.should.have.property('data'); 54 | done(); 55 | }); 56 | }); 57 | it('patch_node return data from ironic', function (done) { 58 | return ironic.patch_node('123', '123', {}) 59 | .then(function (result) { 60 | result.should.have.property('data'); 61 | done(); 62 | }); 63 | }); 64 | it('delete_node return data from ironic', function (done) { 65 | return ironic.delete_node('123', '123') 66 | .then(function (result) { 67 | result.should.have.property('data'); 68 | done(); 69 | }); 70 | }); 71 | it('get_port_list return data from ironic', function (done) { 72 | return ironic.get_port_list('123') 73 | .then(function (result) { 74 | result.should.have.property('data'); 75 | done(); 76 | }); 77 | }); 78 | it('get_port return data from ironic', function (done) { 79 | return ironic.get_port('123', 'identifier') 80 | .then(function (result) { 81 | result.should.have.property('data'); 82 | done(); 83 | }); 84 | }); 85 | it('set_power_state on return data from ironic', function (done) { 86 | return ironic.set_power_state('123', 'identifier', 'on') 87 | .then(function (result) { 88 | result.should.have.property('data'); 89 | done(); 90 | }); 91 | }); 92 | it('set_power_state off return data from ironic', function (done) { 93 | return ironic.set_power_state('123', 'identifier', 'off') 94 | .then(function (result) { 95 | result.should.have.property('data'); 96 | done(); 97 | }); 98 | }); 99 | it('set_power_state reboot return data from ironic', function (done) { 100 | return ironic.set_power_state('123', 'identifier', 'reboot') 101 | .then(function (result) { 102 | result.should.have.property('data'); 103 | done(); 104 | }); 105 | }); 106 | it('get_driver_list return data from ironic', function (done) { 107 | return ironic.get_driver_list('123') 108 | .then(function (result) { 109 | result.should.have.property('data'); 110 | done(); 111 | }); 112 | }); 113 | }); -------------------------------------------------------------------------------- /scripts/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Shovel UI 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 107 | 108 | 109 | 110 | 120 | 121 |
 
122 |
123 | 124 | 125 | -------------------------------------------------------------------------------- /lib/api/monorail/monorail.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | /*eslint-env node*/ 4 | var config = require('./../../../config.json'); 5 | var client = require('./../client'); 6 | var Promise = require('bluebird'); 7 | var _ = require('underscore'); 8 | Promise.promisifyAll(client); 9 | 10 | var pfx = '/api/' + config.monorail.version; 11 | var request = { 12 | host: config.monorail.httpHost, 13 | port: config.monorail.httpPort, 14 | path: pfx, 15 | token: '', 16 | data: '', 17 | api: '' 18 | }; 19 | /* 20 | * Monorail wrapper functions 21 | */ 22 | var MonorailWrapper = { 23 | request_nodes_get: function () { 24 | 'use strict'; 25 | request.path = pfx + '/nodes'; 26 | return client.GetAsync(request); 27 | }, 28 | request_node_get: function (identifier) { 29 | 'use strict'; 30 | request.path = pfx + '/nodes/' + identifier; 31 | return client.GetAsync(request); 32 | }, 33 | request_whitelist_set: function (hwaddr) { 34 | 'use strict'; 35 | request.path = pfx + '/nodes/' + hwaddr + '/dhcp/whitelist'; 36 | return client.PostAsync(request); 37 | }, 38 | request_whitelist_del: function (hwaddr) { 39 | 'use strict'; 40 | request.path = pfx + '/nodes/' + hwaddr + '/dhcp/whitelist'; 41 | return client.DeleteAsync(request); 42 | }, 43 | request_catalogs_get: function (hwaddr) { 44 | 'use strict'; 45 | request.path = pfx + '/nodes/' + hwaddr + '/catalogs'; 46 | return client.GetAsync(request); 47 | }, 48 | get_catalog_data_by_source: function (hwaddr, source) { 49 | 'use strict'; 50 | request.path = pfx + '/nodes/' + hwaddr + '/catalogs/' + source; 51 | return client.GetAsync(request); 52 | }, 53 | request_poller_get: function (identifier) { 54 | 'use strict'; 55 | request.path = pfx + '/nodes/' + identifier + '/pollers'; 56 | return client.GetAsync(request); 57 | }, 58 | request_poller_data_get: function (identifier) { 59 | 'use strict'; 60 | request.path = pfx + '/pollers/' + identifier + '/data/current'; 61 | return client.GetAsync(request); 62 | }, 63 | lookupCatalog: function lookupCatalog(node) { 64 | 'use strict'; 65 | var self = this; 66 | return self.get_catalog_data_by_source(node.id, 'dmi') 67 | .then(function (dmi) { 68 | if (!_.has(JSON.parse(dmi), 'data')) { 69 | return false; 70 | } 71 | }) 72 | .then(function () { 73 | return self.get_catalog_data_by_source(node.id, 'lsscsi'); 74 | }) 75 | .then(function (lsscsi) { 76 | if (!_.has(JSON.parse(lsscsi), 'data')) { 77 | return false; 78 | } 79 | }) 80 | .then(function () { 81 | return self.get_catalog_data_by_source(node.id, 'bmc'); 82 | }) 83 | .then(function (bmc) { 84 | if (!_.has(JSON.parse(bmc), 'data')) { 85 | return false; 86 | } else { 87 | return true; 88 | } 89 | }) 90 | .catch(function () { 91 | return false; 92 | }); 93 | }, 94 | nodeDiskSize: function nodeDiskSize(node) { 95 | 'use strict'; 96 | var localGb = 0; 97 | var self = this; 98 | return self.get_catalog_data_by_source(node.id, 'lsscsi'). 99 | then(function (scsi) { 100 | scsi = JSON.parse(scsi); 101 | if (scsi.data) { 102 | for (var elem = 0; elem < scsi.data.length; elem++) { 103 | var item = scsi.data[elem]; 104 | if (item.peripheralType === 'disk') { 105 | localGb += parseFloat(item.size.replace('GB', '').trim()); 106 | } 107 | } 108 | } 109 | return Promise.resolve(localGb); 110 | }) 111 | .catch(function (err) { 112 | throw err; 113 | }); 114 | }, 115 | getNodeMemoryCpu: function getNodeMemoryCpu(computeNode) { 116 | 'use strict'; 117 | var self = this; 118 | var dmiData = { cpus: 0, memory: 0 }; 119 | return self.get_catalog_data_by_source(computeNode.id, 'dmi'). 120 | then(function (dmi) { 121 | dmi = JSON.parse(dmi); 122 | if (dmi.data) { 123 | var dmiTotal = 0; 124 | if (dmi.data['Memory Device']) { 125 | var memoryDevice = dmi.data['Memory Device']; 126 | for (var elem = 0; elem < memoryDevice.length; elem++) { 127 | var item = memoryDevice[elem]; 128 | //logger.info(item['Size']); 129 | if (item.Size.indexOf('GB') > -1) { 130 | dmiTotal += parseFloat(item.Size.replace('GB', '').trim()) * 1000; 131 | } 132 | if (item.Size.indexOf('MB') > -1) { 133 | dmiTotal += parseFloat(item.Size.replace('MB', '').trim()); 134 | } 135 | } 136 | dmiData.memory = dmiTotal; 137 | } 138 | if (dmi.data.hasOwnProperty('Processor Information')) { 139 | dmiData.cpus = dmi.data['Processor Information'].length; 140 | } 141 | } 142 | return Promise.resolve(dmiData); 143 | }) 144 | .catch(function (err) { 145 | throw err; 146 | }); 147 | }, 148 | runWorkFlow: function runWorkFlow(hwaddr,graphName,content) { 149 | 'use strict'; 150 | request.path = pfx + '/nodes/' + hwaddr + '/workflows/?name=' + graphName; 151 | if (content !== null) { 152 | request.data = JSON.stringify(content); 153 | } 154 | return client.PostAsync(request); 155 | }, 156 | getWorkFlowActive: function getWorkFlowActive(hwaddr) { 157 | 'use strict'; 158 | request.path = pfx + '/nodes/' + hwaddr + '/workflows/active'; 159 | return client.GetAsync(request); 160 | }, 161 | deleteWorkFlowActive: function deleteWorkFlowActive(hwaddr) { 162 | 'use strict'; 163 | request.path = pfx + '/nodes/' + hwaddr + '/workflows/active'; 164 | return client.DeleteAsync(request); 165 | }, 166 | createTask: function createTask(content) { 167 | 'use strict'; 168 | request.path = pfx + '/workflows/tasks/'; 169 | request.data = JSON.stringify(content); 170 | return client.PutAsync(request); 171 | }, 172 | createWorkflow: function createWorkflow(content) { 173 | 'use strict'; 174 | request.path = pfx + '/workflows'; 175 | request.data = JSON.stringify(content); 176 | return client.PutAsync(request); 177 | }, 178 | getStatus: function () { 179 | 'use strict'; 180 | return client.getStatus(); 181 | } 182 | }; 183 | module.exports = Object.create(MonorailWrapper); 184 | -------------------------------------------------------------------------------- /lib/services/poller.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | /*eslint-env node*/ 4 | var monorail = require('./../api/monorail/monorail'); 5 | var ironic = require('./../api/openstack/ironic'); 6 | var keystone = require('./../api/openstack/keystone'); 7 | var _ = require('underscore'); 8 | var config = require('./../../config.json'); 9 | var logger = require('./logger').Logger('info'); 10 | var Promise = require('bluebird'); 11 | 12 | module.exports = Poller; 13 | var ironicConfig = config.ironic; 14 | function Poller(timeInterval) { 15 | 'use strict'; 16 | this._timeInterval = timeInterval; 17 | this._ironicToken = null; 18 | this._timeObj = null; 19 | 20 | Poller.prototype.getToken = function () { 21 | var self = this; 22 | return keystone.authenticatePassword(ironicConfig.os_tenant_name, 23 | ironicConfig.os_username, ironicConfig.os_password). 24 | then(function (token) { 25 | self._ironicToken = token = JSON.parse(token).access.token.id; 26 | return token; 27 | }) 28 | .catch(function (err) { 29 | logger.error(err); 30 | return null; 31 | }); 32 | }; 33 | 34 | Poller.prototype.stopServer = function () { 35 | try { 36 | clearInterval(this.timeObj); 37 | this.timeObj = 0; 38 | } catch (err) { 39 | logger.error(err); 40 | } 41 | }; 42 | 43 | Poller.prototype.runPoller = function (ironicNodes) { 44 | var self = this; 45 | if (ironicNodes !== null) { 46 | for (var i = 0; i < ironicNodes.length; i++) { 47 | logger.info('Running poller on :' + ironicNodes[i].uuid + ':'); 48 | self.searchIronic(ironicNodes[i]); 49 | } 50 | } 51 | }; 52 | 53 | Poller.prototype.searchIronic = function (ironicNode) { 54 | var self = this; 55 | var nodeData = ironicNode; 56 | try { 57 | if (nodeData !== null && 58 | nodeData.extra && nodeData.extra.timer) { 59 | if (!nodeData.extra.timer.stop) { 60 | var timeNow = new Date(); 61 | var timeFinished = nodeData.extra.timer.finish; 62 | var _timeInterval = nodeData.extra.timer.timeInterval; 63 | var parsedDate = new Date(Date.parse(timeFinished)); 64 | var newDate = new Date(parsedDate.getTime() + _timeInterval); 65 | if (newDate < timeNow) { 66 | nodeData.extra.timer.start = new Date().toJSON(); 67 | if (nodeData.extra.timer.isDone) { 68 | nodeData.extra.timer.isDone = false; 69 | return self.updateInfo(self._ironicToken, nodeData). 70 | then(function (data) { 71 | return self.patchData(nodeData.uuid, JSON.stringify(data)); 72 | }). 73 | then(function (result) { 74 | return result; 75 | }); 76 | } 77 | } 78 | } 79 | } 80 | return Promise.resolve(null); 81 | } catch (err) { 82 | logger.error(err); 83 | return Promise.resolve(null); 84 | } 85 | }; 86 | 87 | Poller.prototype.getNodes = function (token) { 88 | return ironic.get_node_list(token). 89 | then(function (result) { 90 | return JSON.parse(result).nodes; 91 | }) 92 | .catch(function (err) { 93 | logger.error(err); 94 | return null; 95 | }); 96 | }; 97 | 98 | Poller.prototype.patchData = function (uuid, data) { 99 | var self = this; 100 | return ironic.patch_node(self._ironicToken, uuid, data). 101 | then(function (result) { 102 | result = JSON.parse(result); 103 | if (typeof result !== 'undefined') { 104 | return result.extra; 105 | } 106 | return null; 107 | }) 108 | .catch(function (err) { 109 | logger.error(err); 110 | return null; 111 | }); 112 | }; 113 | 114 | Poller.prototype.updateInfo = function (token, nodeData) { 115 | return this.getSeldata(nodeData.extra.nodeid). 116 | then(function (result) { 117 | var lastEvent = {}; 118 | if (result !== null) { 119 | result = JSON.parse(result); 120 | if (result[0] && result[0].hasOwnProperty('sel')) { 121 | if (nodeData.extra.eventre !== null) { 122 | var arr = result[0].sel; 123 | var events = _.where(arr, { event: nodeData.extra.eventre }); 124 | if (events !== null) { 125 | logger.info(events); 126 | nodeData.extra.eventcnt = events.length; 127 | lastEvent = events[events.length - 1]; 128 | } 129 | } 130 | } 131 | } 132 | //update finish time 133 | nodeData.extra.timer.finish = new Date().toJSON(); 134 | nodeData.extra.timer.isDone = true; 135 | nodeData.extra.events = lastEvent; 136 | var data = [ 137 | { 138 | path: '/extra', 139 | value: nodeData.extra, 140 | op: 'replace' 141 | }]; 142 | return data; 143 | }) 144 | .catch(function (err) { 145 | logger.error(err); 146 | return null; 147 | }); 148 | }; 149 | 150 | Poller.prototype.getSeldata = function (identifier) { 151 | return monorail.request_poller_get(identifier). 152 | then(function (pollers) { 153 | if (typeof pollers !== 'undefined') { 154 | pollers = JSON.parse(pollers); 155 | return Promise.filter(pollers, function (poller) { 156 | return poller.config.command === 'sel'; 157 | }) 158 | .then(function (sel) { 159 | if (sel.length > 0) { 160 | return monorail.request_poller_data_get(sel[0].id) 161 | .then(function (data) { 162 | return data; 163 | }) 164 | .catch(function (e) { 165 | logger.error(e); 166 | }); 167 | } 168 | }); 169 | } 170 | return null; 171 | }) 172 | .catch(function (err) { 173 | logger.error(err); 174 | return null; 175 | }); 176 | }; 177 | 178 | Poller.prototype.startServer = function () { 179 | var self = this; 180 | try { 181 | self._timeObj = setInterval(function () { 182 | return self.getToken() 183 | .then(function (token) { 184 | return self.getNodes(token); 185 | }) 186 | .then(function (ironicNodes) { 187 | return self.runPoller(ironicNodes); 188 | }); 189 | }, self._timeInterval); 190 | } catch (err) { 191 | logger.error(err); 192 | } 193 | }; 194 | } 195 | -------------------------------------------------------------------------------- /test/api/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | var should = require('should'); 4 | var client = require('./../../lib/api/client'); 5 | var Promise = require('bluebird'); 6 | var nock = require('nock'); 7 | Promise.promisifyAll(client); 8 | 9 | describe('client with http requests', function () { 10 | var option = { host: 'localhost', port: 7070, path: '/api/', token: '', data: '{"auth":{"tenantName":"admin" }}', api: '' }; 11 | it('get return data from targeted server', function (done) { 12 | nock('http://localhost:7070/api') 13 | .get('/') 14 | .reply(200, { data: 'data from server' }); 15 | return client.GetAsync(option) 16 | .then(function (result) { 17 | JSON.parse(result).should.have.property('data'); 18 | done(); 19 | }); 20 | }); 21 | it('get return data from targeted server with a token', function (done) { 22 | nock('http://localhost:7070/api') 23 | .get('/') 24 | .reply(200, { data: 'data from server' }); 25 | option.token = '1234'; 26 | return client.GetAsync(option) 27 | .then(function (result) { 28 | JSON.parse(result).should.have.property('data'); 29 | done(); 30 | }); 31 | }); 32 | it('get return data from targeted server', function (done) { 33 | return client.GetAsync(option) 34 | .catch(function (result) { 35 | result.should.have.property('errorMessage'); 36 | done(); 37 | }); 38 | }); 39 | 40 | it('post return data from targeted server', function (done) { 41 | nock('http://localhost:7070/api') 42 | .post('/') 43 | .reply(200, { data: 'data from server' }); 44 | 45 | return client.PostAsync(option) 46 | .then(function (result) { 47 | JSON.parse(result).should.have.property('data'); 48 | done(); 49 | }); 50 | }); 51 | it('post return data from targeted server', function (done) { 52 | nock('http://localhost:7070/api') 53 | .post('/') 54 | .reply(200, { data: 'data from server' }); 55 | option.token = '1234'; 56 | return client.PostAsync(option) 57 | .then(function (result) { 58 | JSON.parse(result).should.have.property('data'); 59 | done(); 60 | }); 61 | }); 62 | it('post return data from targeted server', function (done) { 63 | nock('http://localhost:7070/api') 64 | .post('/') 65 | .reply(200, { data: 'data from server' }); 66 | return client.PostAsync(option) 67 | .then(function (result) { 68 | JSON.parse(result).should.have.property('data'); 69 | done(); 70 | }); 71 | }); 72 | it('post return data from targeted server', function (done) { 73 | nock('http://localhost:7070/api') 74 | .post('/') 75 | .reply(200, { data: 'data from server' }); 76 | option.token = '1234'; 77 | return client.PostAsync(option) 78 | .then(function (result) { 79 | JSON.parse(result).should.have.property('data'); 80 | done(); 81 | }); 82 | }); 83 | it('post return data from targeted server', function (done) { 84 | return client.PostAsync(option) 85 | .catch(function (result) { 86 | result.should.have.property('errorMessage'); 87 | done(); 88 | }); 89 | }); 90 | 91 | it('delete return data from targeted server', function (done) { 92 | nock('http://localhost:7070/api') 93 | .delete('/') 94 | .reply(200, { data: 'data from server' }); 95 | 96 | return client.DeleteAsync(option) 97 | .then(function (result) { 98 | JSON.parse(result).should.have.property('data'); 99 | done(); 100 | }); 101 | }); 102 | it('delete return data from targeted server', function (done) { 103 | nock('http://localhost:7070/api') 104 | .delete('/') 105 | .reply(200, { data: 'data from server' }); 106 | option.token = '1234'; 107 | return client.DeleteAsync(option) 108 | .then(function (result) { 109 | JSON.parse(result).should.have.property('data'); 110 | done(); 111 | }); 112 | }); 113 | it('delete return data from targeted server', function (done) { 114 | return client.DeleteAsync(option) 115 | .catch(function (result) { 116 | result.should.have.property('errorMessage'); 117 | done(); 118 | }); 119 | }); 120 | 121 | it('put return data from targeted server', function (done) { 122 | nock('http://localhost:7070/api') 123 | .put('/') 124 | .reply(200, { data: 'data from server' }); 125 | 126 | return client.PutAsync(option) 127 | .then(function (result) { 128 | JSON.parse(result).should.have.property('data'); 129 | done(); 130 | }); 131 | }); 132 | it('put return data from targeted server', function (done) { 133 | nock('http://localhost:7070/api') 134 | .put('/') 135 | .reply(200, { data: 'data from server' }); 136 | option.token = '1234'; 137 | return client.PutAsync(option) 138 | .then(function (result) { 139 | JSON.parse(result).should.have.property('data'); 140 | done(); 141 | }); 142 | }); 143 | it('put return data from targeted server', function (done) { 144 | nock('http://localhost:7070/api') 145 | .put('/') 146 | .reply(200, { data: 'data from server' }); 147 | return client.PutAsync(option) 148 | .then(function (result) { 149 | JSON.parse(result).should.have.property('data'); 150 | done(); 151 | }); 152 | }); 153 | it('put return data from targeted server', function (done) { 154 | return client.PutAsync(option) 155 | .catch(function (result) { 156 | result.should.have.property('errorMessage'); 157 | done(); 158 | }); 159 | }); 160 | 161 | it('path return data from targeted server', function (done) { 162 | nock('http://localhost:7070/api') 163 | .patch('/') 164 | .reply(200, { data: 'data from server' }); 165 | return client.PatchAsync(option) 166 | .then(function (result) { 167 | JSON.parse(result).should.have.property('data'); 168 | done(); 169 | }); 170 | }); 171 | it('patch return data from targeted server', function (done) { 172 | nock('http://localhost:7070/api') 173 | .patch('/') 174 | .reply(200, { data: 'data from server' }); 175 | option.token = '1234'; 176 | return client.PatchAsync(option) 177 | .then(function (result) { 178 | JSON.parse(result).should.have.property('data'); 179 | done(); 180 | }); 181 | }); 182 | it('patch return data from targeted server', function (done) { 183 | nock('http://localhost:7070/api') 184 | .patch('/') 185 | .reply(200, { data: 'data from server' }); 186 | return client.PatchAsync(option) 187 | .then(function (result) { 188 | JSON.parse(result).should.have.property('data'); 189 | done(); 190 | }); 191 | }); 192 | it('patch return data from targeted server', function (done) { 193 | return client.PatchAsync(option) 194 | .catch(function (result) { 195 | result.should.have.property('errorMessage'); 196 | done(); 197 | }); 198 | }); 199 | }); -------------------------------------------------------------------------------- /lib/api/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | /*eslint-env node*/ 4 | 5 | //global 6 | var statusCode; 7 | 8 | /* http client */ 9 | var HttpClient = { 10 | Get: function (msg, output) { 11 | 'use strict'; 12 | statusCode = 0; 13 | var http = require('http'); 14 | var options = { 15 | hostname: msg.host, 16 | path: msg.path, 17 | port: msg.port, 18 | method: 'GET', 19 | headers: {} 20 | }; 21 | if (Buffer.byteLength(msg.token)) { 22 | options.headers['X-Auth-Token'] = msg.token; 23 | } 24 | 25 | var cb = function (response) { 26 | var body = ''; 27 | response.on('data', function (chunk) { 28 | body += chunk; 29 | }); 30 | response.on('error', function (err) { 31 | var errorMessage = { errorMessage: { hostname: msg.host, message: err } }; 32 | statusCode = response.statusCode; 33 | output(errorMessage); 34 | }); 35 | response.on('end', function () { 36 | statusCode = response.statusCode; 37 | output(null, body); 38 | }); 39 | }; 40 | 41 | var request = http.request(options, cb); 42 | request.on('error', function (e) { 43 | var errorMessage = { errorMessage: { hostname: msg.host, message: e } }; 44 | output(errorMessage); 45 | }); 46 | 47 | request.end(); 48 | }, 49 | Post: function (msg, output) { 50 | 'use strict'; 51 | statusCode = 0; 52 | var http = require('http'); 53 | var options = { 54 | hostname: msg.host, 55 | path: msg.path, 56 | port: msg.port, 57 | method: 'POST', 58 | headers: { 59 | 'Content-type': 'application/json', 60 | Accept: 'application/json', 61 | 'Content-Length': Buffer.byteLength(msg.data), 62 | 'User-Agent': 'shovel-client' 63 | } 64 | }; 65 | 66 | /*Update the request header with special fields*/ 67 | if (Buffer.byteLength(msg.token)) { 68 | options.headers['X-Auth-Token'] = msg.token; 69 | } 70 | if (Buffer.byteLength(JSON.stringify(msg.api))) { 71 | options.headers[msg.api.name] = msg.api.version; 72 | } 73 | 74 | var cb = function (response) { 75 | var body = ''; 76 | response.on('data', function (chunk) { 77 | body += chunk; 78 | }); 79 | response.on('error', function (e) { 80 | statusCode = response.statusCode; 81 | var errorMessage = { errorMessage: { hostname: msg.host, message: e } }; 82 | output(errorMessage); 83 | }); 84 | response.on('end', function () { 85 | statusCode = response.statusCode; 86 | output(null, body); 87 | }); 88 | }; 89 | 90 | var request = http.request(options, cb); 91 | request.on('error', function (e) { 92 | var errorMessage = { errorMessage: { hostname: msg.host, message: e } }; 93 | output(errorMessage); 94 | }); 95 | 96 | if (Buffer.byteLength(msg.data)) { 97 | request.write(msg.data); 98 | } 99 | request.end(); 100 | }, 101 | Delete: function (msg, output) { 102 | 'use strict'; 103 | statusCode = 0; 104 | var http = require('http'); 105 | var options = { 106 | hostname: msg.host, 107 | path: msg.path, 108 | port: msg.port, 109 | method: 'DELETE', 110 | headers: {} 111 | }; 112 | 113 | if (Buffer.byteLength(msg.token)) { 114 | options.headers['X-Auth-Token'] = msg.token; 115 | } 116 | 117 | if (Buffer.byteLength(JSON.stringify(msg.api))) { 118 | options.headers[msg.api.name] = msg.api.version; 119 | } 120 | 121 | var cb = function (response) { 122 | var body = ''; 123 | response.on('data', function (chunk) { 124 | body += chunk; 125 | }); 126 | response.on('error', function (err) { 127 | statusCode = response.statusCode; 128 | var errorMessage = { errorMessage: { hostname: msg.host, message: err } }; 129 | output(errorMessage); 130 | }); 131 | response.on('end', function () { 132 | statusCode = response.statusCode; 133 | output(null, body); 134 | }); 135 | }; 136 | 137 | var request = http.request(options, cb); 138 | request.on('error', function (e) { 139 | var errorMessage = { errorMessage: { hostname: msg.host, message: e } }; 140 | output(errorMessage); 141 | }); 142 | 143 | request.end(); 144 | }, 145 | Put: function (msg, output) { 146 | 'use strict'; 147 | statusCode = 0; 148 | var http = require('http'); 149 | var options = { 150 | hostname: msg.host, 151 | path: msg.path, 152 | port: msg.port, 153 | method: 'PUT', 154 | headers: { 155 | 'Content-type': 'application/json', 156 | Accept: 'application/json', 157 | 'Content-Length': Buffer.byteLength(msg.data), 158 | 'User-Agent': 'shovel-client' 159 | } 160 | }; 161 | 162 | /*Update the request header with special fields*/ 163 | if (Buffer.byteLength(msg.token)) { 164 | options.headers['X-Auth-Token'] = msg.token; 165 | } 166 | if (Buffer.byteLength(JSON.stringify(msg.api))) { 167 | options.headers[msg.api.name] = msg.api.version; 168 | } 169 | 170 | var cb = function (response) { 171 | var body = ''; 172 | response.on('data', function (chunk) { 173 | body += chunk; 174 | }); 175 | response.on('error', function (e) { 176 | statusCode = response.statusCode; 177 | var errorMessage = { errorMessage: { hostname: msg.host, message: e } }; 178 | output(errorMessage); 179 | }); 180 | response.on('end', function () { 181 | statusCode = response.statusCode; 182 | output(null, body); 183 | }); 184 | }; 185 | 186 | var request = http.request(options, cb); 187 | request.on('error', function (e) { 188 | var errorMessage = { errorMessage: { hostname: msg.host, message: e } }; 189 | output(errorMessage); 190 | }); 191 | 192 | if (Buffer.byteLength(msg.data)) { 193 | request.write(msg.data); 194 | } 195 | request.end(); 196 | }, 197 | Patch: function (msg, output) { 198 | 'use strict'; 199 | statusCode = 0; 200 | var http = require('http'); 201 | var options = { 202 | hostname: msg.host, 203 | path: msg.path, 204 | port: msg.port, 205 | method: 'PATCH', 206 | headers: { 207 | 'Content-type': 'application/json', 208 | Accept: 'application/json', 209 | 'Content-Length': Buffer.byteLength(msg.data), 210 | 'User-Agent': 'shovel-client' 211 | } 212 | }; 213 | 214 | /*Update the request header with special fields*/ 215 | if (Buffer.byteLength(msg.token)) { 216 | options.headers['X-Auth-Token'] = msg.token; 217 | } 218 | if (Buffer.byteLength(JSON.stringify(msg.api))) { 219 | options.headers[msg.api.name] = msg.api.version; 220 | } 221 | 222 | var cb = function (response) { 223 | var body = ''; 224 | response.on('data', function (chunk) { 225 | body += chunk; 226 | }); 227 | response.on('error', function (err) { 228 | statusCode = response.statusCode; 229 | var errorMessage = { errorMessage: { hostname: msg.host, message: err } }; 230 | output(errorMessage); 231 | }); 232 | response.on('end', function () { 233 | statusCode = response.statusCode; 234 | output(null, body); 235 | }); 236 | }; 237 | 238 | var request = http.request(options, cb); 239 | request.on('error', function (e) { 240 | var errorMessage = { errorMessage: { hostname: msg.host, message: e } }; 241 | output(errorMessage); 242 | }); 243 | 244 | if (Buffer.byteLength(msg.data)) { 245 | request.write(msg.data); 246 | } 247 | request.end(); 248 | }, 249 | getStatus: function() { 250 | 'use strict'; 251 | return statusCode; 252 | } 253 | }; 254 | module.exports = Object.create(HttpClient); 255 | 256 | -------------------------------------------------------------------------------- /test/api/monorail.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | var should = require('should'); 4 | var sinon = require('sinon'); 5 | var monorail = require('./../../lib/api/monorail/monorail'); 6 | var Promise = require('bluebird'); 7 | var _ = require('underscore'); 8 | var client = require('./../../lib/api/client'); 9 | var Promise = require('bluebird'); 10 | Promise.promisifyAll(client); 11 | 12 | describe('****Monorail Lib****',function(){ 13 | var rackhdNode = [{ workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }]; 14 | var catalogSource = [{ source: 'dmi', data: {'Memory Device': [{ Size: '1 GB' }, { Size: '1 GB' }], 15 | 'Processor Information': [{}, {}] }}, { source: 'lsscsi', data: [{ peripheralType: 'disk', size: '1GB' }] }]; 16 | var rackhdNode =[ { workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }]; 17 | var identifier = '123456789'; 18 | 19 | describe('monorail nodeDiskSize getNodeMemoryCpu', function () { 20 | describe('monorail getNodeMemoryCpu', function () { 21 | afterEach('teardown mocks', function () { 22 | //monorail 23 | monorail['get_catalog_data_by_source'].restore(); 24 | }); 25 | 26 | it('response should returns an integer with value equal to memory size 2000MB and cpus=2', function (done) { 27 | sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0]))); 28 | return monorail.getNodeMemoryCpu(rackhdNode). 29 | then(function (result) { 30 | result.cpus.should.be.exactly(2); 31 | result.memory.should.be.exactly(2000); 32 | done(); 33 | }); 34 | }); 35 | }); 36 | describe('nodeDiskSize', function () { 37 | beforeEach('set up mocks', function () { 38 | }); 39 | 40 | afterEach('teardown mocks', function () { 41 | //monorail 42 | monorail['get_catalog_data_by_source'].restore(); 43 | }); 44 | it('response should returns an integer with value equal to disk size 1GB', function (done) { 45 | //monorail 46 | sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[1]))); 47 | return monorail.nodeDiskSize(rackhdNode). 48 | then(function (result) { 49 | result.should.be.exactly(1); 50 | done(); 51 | }); 52 | }); 53 | 54 | it('response should returns an integer with value equal to 0', function (done) { 55 | //monorail 56 | sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify({}))); 57 | return monorail.nodeDiskSize(rackhdNode). 58 | then(function (result) { 59 | result.should.be.exactly(0); 60 | done(); 61 | }); 62 | }); 63 | }); 64 | }); 65 | describe('lookupCatalog', function () { 66 | afterEach('teardown mocks', function () { 67 | //monorail 68 | monorail['get_catalog_data_by_source'].restore(); 69 | }); 70 | it('lookupCatalog response should be equal to true', function (done) { 71 | sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0]))); 72 | return monorail.lookupCatalog(rackhdNode[0]). 73 | then(function (result) { 74 | JSON.parse(result).should.be.exactly(true); 75 | done(); 76 | }) 77 | .catch(function (err) { 78 | throw err; 79 | }) 80 | }); 81 | it('lookupCatalog response should be equal to fasle if catalog does not have property data', function (done) { 82 | sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify({}))); 83 | return monorail.lookupCatalog(rackhdNode[0]). 84 | then(function (result) { 85 | JSON.parse(result).should.be.exactly(false); 86 | done(); 87 | }) 88 | .catch(function (err) { 89 | throw err; 90 | }) 91 | }); 92 | }); 93 | describe('monorail with client get/post/patch/delete returns data', function () { 94 | beforeEach('set up mocks', function () { 95 | var output = ({ data: 'monorail service' }); 96 | sinon.stub(client, 'GetAsync').returns(Promise.resolve(output)); 97 | sinon.stub(client, 'PostAsync').returns(Promise.resolve(output)); 98 | sinon.stub(client, 'PatchAsync').returns(Promise.resolve(output)); 99 | sinon.stub(client, 'PutAsync').returns(Promise.resolve(output)); 100 | sinon.stub(client, 'DeleteAsync').returns(Promise.resolve(output)); 101 | }); 102 | afterEach('teardown mocks', function () { 103 | client['GetAsync'].restore(); 104 | client['PostAsync'].restore(); 105 | client['PatchAsync'].restore(); 106 | client['PutAsync'].restore(); 107 | client['DeleteAsync'].restore(); 108 | 109 | }); 110 | 111 | it('monorail.request_nodes_get return data from monorail', function (done) { 112 | return monorail.request_nodes_get() 113 | .then(function (result) { 114 | result.should.have.property('data'); 115 | done(); 116 | }); 117 | }); 118 | it('monorail.request_node_get return data from monorail', function (done) { 119 | return monorail.request_node_get('123') 120 | .then(function (result) { 121 | result.should.have.property('data'); 122 | done(); 123 | }); 124 | }); 125 | it('monorail.request_whitelist_set return data from monorail', function (done) { 126 | return monorail.request_whitelist_set('123') 127 | .then(function (result) { 128 | result.should.have.property('data'); 129 | done(); 130 | }); 131 | }); 132 | it('monorail.request_whitelist_del return data from monorail', function (done) { 133 | return monorail.request_whitelist_del('123') 134 | .then(function (result) { 135 | result.should.have.property('data'); 136 | done(); 137 | }); 138 | }); 139 | it('monorail.request_catalogs_get return data from monorail', function (done) { 140 | return monorail.request_catalogs_get('123') 141 | .then(function (result) { 142 | result.should.have.property('data'); 143 | done(); 144 | }); 145 | }); 146 | it('monorail.get_catalog_data_by_source return data from monorail', function (done) { 147 | return monorail.get_catalog_data_by_source('123', 'bmc') 148 | .then(function (result) { 149 | result.should.have.property('data'); 150 | done(); 151 | }); 152 | }); 153 | it('monorail.request_poller_get return data from monorail', function (done) { 154 | return monorail.request_poller_get('123') 155 | .then(function (result) { 156 | result.should.have.property('data'); 157 | done(); 158 | }); 159 | }); 160 | it('monorail.request_poller_data_get return data from monorail', function (done) { 161 | return monorail.request_poller_data_get('123') 162 | .then(function (result) { 163 | result.should.have.property('data'); 164 | done(); 165 | }); 166 | }); 167 | it('monorail.runWorkFlow return data from monorail', function (done) { 168 | return monorail.runWorkFlow('123','Graph.Name',{}) 169 | .then(function (result) { 170 | result.should.have.property('data'); 171 | done(); 172 | }); 173 | }); 174 | it('monorail.getWorkFlowActive return data from monorail', function (done) { 175 | return monorail.getWorkFlowActive('123') 176 | .then(function (result) { 177 | result.should.have.property('data'); 178 | done(); 179 | }); 180 | }); 181 | it('monorail.deleteWorkFlowActive return data from monorail', function (done) { 182 | return monorail.deleteWorkFlowActive('123') 183 | .then(function (result) { 184 | result.should.have.property('data'); 185 | done(); 186 | }); 187 | }); 188 | it('monorail.createWorkflow return data from monorail', function (done) { 189 | return monorail.createWorkflow({}) 190 | .then(function (result) { 191 | result.should.have.property('data'); 192 | done(); 193 | }); 194 | }); 195 | it('monorail.createTask return data from monorail', function (done) { 196 | return monorail.createTask({}) 197 | .then(function (result) { 198 | result.should.have.property('data'); 199 | done(); 200 | }); 201 | }); 202 | }); 203 | }); -------------------------------------------------------------------------------- /test/services/poller.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | var should = require('should'); 4 | var sinon = require('sinon'); 5 | var monorail = require('./../../lib/api/monorail/monorail'); 6 | var ironic = require('./../../lib/api/openstack/ironic'); 7 | var keystone = require('./../../lib/api/openstack/keystone'); 8 | var Promise = require('bluebird'); 9 | var client = require('./../../lib/api/client'); 10 | Promise.promisifyAll(client); 11 | var _ = require('underscore'); 12 | var helper = require('./../helper'); 13 | //lib to be tested 14 | var Poller; 15 | 16 | describe('*****Shovel poller Class****', function () { 17 | 18 | var rackhdNode =[ { workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }]; 19 | var identifier = '9a761508-4eee-4065-b47b-45c22dff54c2'; 20 | var ironic_node_list = [ { uuid: "9a761508-4eee-4065-b47b-45c22dff54c2", extra: { name: "D51B-2U (dual 10G LoM)", eventre: "", nodeid: "564cefa014ee77be18e48efd", 21 | timer: { start: "2015-11-30T21:14:11.753Z", finish: "2015-11-30T21:14:11.753Z", stop: false, isDone: true, timeInterval: 500 }, eventcnt: 0}}]; 22 | var nodePollers = [{ config: { command: "sel" }, id: "564dd86285fb1e7c72721543" }]; 23 | var _sel = { sel:[ { logId: "1", date: "12/03/2015", time: "08:54:11", sensorType: "Memory", sensorNumber: "#0x53", event: "Correctable ECC", value: "Asserted"} ] }; 24 | var keyToken = { access:{ token:{id:'123456'} } }; 25 | var selEvent = { message: "There is no cache record for the poller with ID 564cf02a4978dadc187976f5.Perhaps it has not been run yet?" }; 26 | var extraPatch = {extra: {name: "QuantaPlex T41S-2U", eventre: "Correctable ECC",nodeid: "565f3f3b4c95bce26f35c6a0", 27 | timer: {timeInterval: 15000, start: "2015-12-03T17:38:20.569Z",finish: "2015-12-03T17:38:20.604Z",stop: false,isDone: true} } }; 28 | var patchedData = [{ 'path': '/extra', 'value': extraPatch.extra, 'op': 'replace' }]; 29 | var pollerInstance; 30 | 31 | before('mask logger', function () { 32 | helper.maskLogger(); 33 | Poller = require('./../../lib/services/poller'); 34 | }); 35 | after('restore logger', function () { 36 | helper.restoreLogger(); 37 | }); 38 | describe('Poller unit tests', function () { 39 | before('start Poller service', function () { 40 | pollerInstance = new Poller(5000);//timeInterval to 5s 41 | }); 42 | 43 | beforeEach('set up mocks', function () { 44 | sinon.stub(monorail, 'request_poller_get').returns(Promise.resolve(JSON.stringify(nodePollers))); 45 | sinon.stub(monorail, 'request_poller_data_get').returns(Promise.resolve(JSON.stringify(_sel))); 46 | sinon.stub(ironic, 'patch_node').returns(Promise.resolve(JSON.stringify(extraPatch))); 47 | sinon.stub(keystone, 'authenticatePassword').returns(Promise.resolve(JSON.stringify(keyToken))); 48 | sinon.stub(ironic, 'get_node_list').returns(Promise.resolve(JSON.stringify(ironic_node_list))); 49 | sinon.stub(ironic, 'get_node').returns(Promise.resolve(JSON.stringify(ironic_node_list[0]))); 50 | }); 51 | 52 | afterEach('teardown mocks', function () { 53 | monorail['request_poller_get'].restore(); 54 | monorail['request_poller_data_get'].restore(); 55 | ironic['patch_node'].restore(); 56 | keystone['authenticatePassword'].restore(); 57 | ironic['get_node_list'].restore(); 58 | ironic['get_node'].restore(); 59 | 60 | }); 61 | 62 | it('Poller.prototype.searchIronic have property name, timer', function (done) { 63 | return pollerInstance.searchIronic(ironic_node_list[0]). 64 | then(function (result) { 65 | result.should.have.property('name'); 66 | result.should.have.property('timer'); 67 | done(); 68 | }); 69 | }); 70 | 71 | it('start server should call get nodes once', function (done) { 72 | pollerInstance.startServer(0); 73 | pollerInstance.stopServer(); 74 | var callback = sinon.spy(); 75 | pollerInstance.getNodes(callback); 76 | callback.should.be.calledOnce; 77 | done(); 78 | }); 79 | 80 | it('start server should call runPoller once', function (done) { 81 | pollerInstance.startServer(0); 82 | pollerInstance.stopServer(); 83 | var callback = sinon.spy(); 84 | pollerInstance.runPoller(ironic_node_list, callback); 85 | callback.should.be.calledOnce; 86 | done(); 87 | 88 | }); 89 | 90 | it('start server should call searchIronic once', function (done) { 91 | pollerInstance.startServer(0); 92 | pollerInstance.stopServer(); 93 | var callback = sinon.spy(); 94 | pollerInstance.searchIronic(ironic_node_list[0], callback); 95 | callback.should.be.calledOnce; 96 | done(); 97 | 98 | }); 99 | 100 | it('pollerInstance.getSeldata() have property sensorNumber, event', function (done) { 101 | return pollerInstance.getSeldata(identifier) 102 | .then(function (data) { 103 | var result = JSON.parse(data); 104 | result.should.have.property('sel'); 105 | _.each(result[0], function (item) { 106 | item.should.have.property('sensorNumber'); 107 | item.should.have.property('event'); 108 | }); 109 | done(); 110 | }) 111 | .catch(function (err) { 112 | throw (err); 113 | }); 114 | }); 115 | 116 | it('Poller.prototype.updateInfo have property path, value', function (done) { 117 | return pollerInstance.updateInfo(identifier, extraPatch). 118 | then(function (data) { 119 | var result = data; 120 | _.each(result, function (item) { 121 | item.should.have.property('path'); 122 | item.should.have.property('value'); 123 | }); 124 | done(); 125 | }) 126 | .catch(function (err) { 127 | throw err; 128 | }); 129 | }); 130 | 131 | it('Poller.prototype.patchData should have property nodeid, timer', function (done) { 132 | return Poller.prototype.patchData('uuid', JSON.stringify(patchedData)). 133 | then(function (data) { 134 | data.should.have.property('nodeid'); 135 | data.should.have.property('timer'); 136 | done(); 137 | }) 138 | .catch(function (err) { 139 | throw (err); 140 | done(); 141 | }); 142 | }); 143 | 144 | it('Poller.prototype.getNodes should have property uuid, extra', function (done) { 145 | return pollerInstance.getNodes(). 146 | then(function (result) { 147 | _.each(result, function (item) { 148 | item.should.have.property('uuid'); 149 | item.should.have.property('extra'); 150 | }); 151 | done(); 152 | }) 153 | .catch(function (err) { 154 | throw (err); 155 | }); 156 | }); 157 | 158 | it('Poller.prototype.getToken should return token 123456', function (done) { 159 | return pollerInstance.getToken(). 160 | then(function (token) { 161 | token.should.be.equal('123456'); 162 | done(); 163 | }) 164 | .catch(function (err) { 165 | throw err; 166 | }); 167 | 168 | }); 169 | 170 | }); 171 | describe('client get/post returns error', function () { 172 | before('set up mocks', function () { 173 | //set client to return an error 174 | pollerInstance = new Poller(5000);//timeInterval to 5s 175 | var output = ({ error: 'error_message' }); 176 | sinon.stub(client, 'GetAsync').returns(Promise.reject(output)); 177 | sinon.stub(client, 'PostAsync').returns(Promise.reject(output)); 178 | sinon.stub(client, 'PatchAsync').returns(Promise.reject(output)); 179 | sinon.stub(client, 'PutAsync').returns(Promise.reject(output)); 180 | sinon.stub(client, 'DeleteAsync').returns(Promise.reject(output)); 181 | }); 182 | after('teardown mocks', function () { 183 | client['GetAsync'].restore(); 184 | client['PostAsync'].restore(); 185 | client['PatchAsync'].restore(); 186 | client['PutAsync'].restore(); 187 | client['DeleteAsync'].restore(); 188 | }); 189 | it('poller.get_token return null', function (done) { 190 | return pollerInstance.getToken('123') 191 | .then(function (result) { 192 | (result === null).should.be.exactly(true); 193 | done(); 194 | }); 195 | }); 196 | it('poller.getSeldata return null', function (done) { 197 | return pollerInstance.getSeldata('123') 198 | .then(function (result) { 199 | (result === null).should.be.exactly(true); 200 | done(); 201 | }); 202 | }); 203 | it('poller.updateInfo return json obj with property : path', function (done) { 204 | return pollerInstance.updateInfo(identifier, extraPatch) 205 | .then(function (result) { 206 | result[0].should.have.property('path', '/extra'); 207 | done(); 208 | }); 209 | }); 210 | it('poller.patchData return null', function (done) { 211 | return pollerInstance.patchData(identifier, extraPatch) 212 | .then(function (result) { 213 | (result === null).should.be.exactly(true); 214 | done(); 215 | }); 216 | }); 217 | it('poller.getNodes return null', function (done) { 218 | return pollerInstance.getNodes() 219 | .then(function (result) { 220 | (result === null).should.be.exactly(true); 221 | done(); 222 | }); 223 | }); 224 | }); 225 | }); 226 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /api/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "Shovel APIs", 5 | "description": "", 6 | "version": "1.0.0" 7 | }, 8 | "produces": [ "application/json" ], 9 | "basePath": "/api/1.1", 10 | "paths": { 11 | 12 | "/info": { 13 | "get": { 14 | "x-swagger-router-controller": "Shovel", 15 | "tags": [ "Shovel Config" ], 16 | "operationId": "infoGet", 17 | "summary": "Get nodes info", 18 | "responses": { 19 | 20 | "200": { 21 | "description": "Not Implemented" 22 | }, 23 | 24 | "default": { 25 | "description": "unexpected error" 26 | } 27 | } 28 | } 29 | }, 30 | "/shovel/config": { 31 | "get": { 32 | "x-swagger-router-controller": "Shovel", 33 | "tags": [ "Shovel Config" ], 34 | "operationId": "configget", 35 | "summary": "Get shovel config file", 36 | "responses": { 37 | 38 | "200": { 39 | "description": "Not Implemented" 40 | }, 41 | 42 | "default": { 43 | "description": "unexpected error" 44 | } 45 | } 46 | } 47 | }, 48 | "/shovel/set-config": { 49 | "post": { 50 | "x-swagger-router-controller": "Shovel", 51 | "tags": [ "Shovel Config" ], 52 | "operationId": "configset", 53 | "summary": "set shovel config file", 54 | "parameters": [ 55 | { 56 | "name": "Shovel Config Info", 57 | "in": "body", 58 | "description": "Shovel Config Info", 59 | "required": true, 60 | "schema": { 61 | "$ref": "#/definitions/config" 62 | } 63 | } 64 | ], 65 | "responses": { 66 | 67 | "200": { 68 | "description": "Not Implemented" 69 | }, 70 | 71 | "default": { 72 | "description": "unexpected error" 73 | } 74 | } 75 | } 76 | }, 77 | "/shovel/monorail/set-config": { 78 | "post": { 79 | "x-swagger-router-controller": "Shovel", 80 | "tags": [ "Shovel Config" ], 81 | "operationId": "configsetmono", 82 | "summary": "set shovel- monorail info", 83 | "parameters": [ 84 | { 85 | "name": "Shovel Config Info", 86 | "in": "body", 87 | "description": "Shovel Config Info", 88 | "required": true, 89 | "schema": { 90 | "$ref": "#/definitions/monorail" 91 | } 92 | } 93 | ], 94 | "responses": { 95 | 96 | "200": { 97 | "description": "Not Implemented" 98 | }, 99 | 100 | "default": { 101 | "description": "unexpected error" 102 | } 103 | } 104 | } 105 | }, 106 | "/shovel/ironic/set-config": { 107 | "post": { 108 | "x-swagger-router-controller": "Shovel", 109 | "tags": [ "Shovel Config" ], 110 | "operationId": "configsetironic", 111 | "summary": "set shovel ironic info", 112 | "parameters": [ 113 | { 114 | "name": "Shovel Config Info", 115 | "in": "body", 116 | "description": "Shovel Config Info", 117 | "required": true, 118 | "schema": { 119 | "$ref": "#/definitions/ironic" 120 | } 121 | } 122 | ], 123 | "responses": { 124 | 125 | "200": { 126 | "description": "Not Implemented" 127 | }, 128 | 129 | "default": { 130 | "description": "unexpected error" 131 | } 132 | } 133 | } 134 | }, 135 | "/shovel/glance/set-config": { 136 | "post": { 137 | "x-swagger-router-controller": "Shovel", 138 | "tags": [ "Shovel Config" ], 139 | "operationId": "configsetglance", 140 | "summary": "set shovel glance info", 141 | "parameters": [ 142 | { 143 | "name": "Shovel Config Info", 144 | "in": "body", 145 | "description": "Shovel Config Info", 146 | "required": true, 147 | "schema": { 148 | "$ref": "#/definitions/glance" 149 | } 150 | } 151 | ], 152 | "responses": { 153 | 154 | "200": { 155 | "description": "Not Implemented" 156 | }, 157 | 158 | "default": { 159 | "description": "unexpected error" 160 | } 161 | } 162 | } 163 | }, 164 | "/shovel/keystone/set-config": { 165 | "post": { 166 | "x-swagger-router-controller": "Shovel", 167 | "tags": [ "Shovel Config" ], 168 | "operationId": "configsetkeystone", 169 | "summary": "set shovel Keystone info", 170 | "parameters": [ 171 | { 172 | "name": "Shovel Config Info", 173 | "in": "body", 174 | "description": "Shovel Config Info", 175 | "required": true, 176 | "schema": { 177 | "$ref": "#/definitions/keystone" 178 | } 179 | } 180 | ], 181 | "responses": { 182 | 183 | "200": { 184 | "description": "Not Implemented" 185 | }, 186 | 187 | "default": { 188 | "description": "unexpected error" 189 | } 190 | } 191 | } 192 | }, 193 | "/catalogs/{identifier}": { 194 | "get": { 195 | "x-swagger-router-controller": "Shovel", 196 | "tags": [ "RackHD API Wrappers" ], 197 | "operationId": "catalogsGet", 198 | "parameters": [ 199 | { 200 | "name": "identifier", 201 | "in": "path", 202 | "description": "rackhd node ID", 203 | "required": true, 204 | "type": "string" 205 | } 206 | ], 207 | "summary": "Get catalog for a specified node", 208 | "responses": { 209 | 210 | "200": { 211 | "description": "Not Implemented" 212 | }, 213 | 214 | "default": { 215 | "description": "unexpected error" 216 | } 217 | } 218 | } 219 | }, 220 | "/catalogs/{identifier}/{source}": { 221 | "get": { 222 | "x-swagger-router-controller": "Shovel", 223 | "tags": [ "RackHD API Wrappers" ], 224 | "operationId": "catalogsbysourceGet", 225 | "parameters": [ 226 | { 227 | "name": "identifier", 228 | "in": "path", 229 | "description": "rackhd node ID", 230 | "required": true, 231 | "type": "string" 232 | }, 233 | { 234 | "name": "source", 235 | "in": "path", 236 | "description": "source", 237 | "required": true, 238 | "type": "string" 239 | } 240 | ], 241 | "summary": "Get source in the catalog for a specified node", 242 | "responses": { 243 | 244 | "200": { 245 | "description": "Not Implemented" 246 | }, 247 | 248 | "default": { 249 | "description": "unexpected error" 250 | } 251 | } 252 | } 253 | }, 254 | "/nodes/{identifier}": { 255 | "get": { 256 | "x-swagger-router-controller": "Shovel", 257 | "tags": [ "RackHD API Wrappers" ], 258 | "operationId": "nodeGet", 259 | "parameters": [ 260 | { 261 | "name": "identifier", 262 | "in": "path", 263 | "description": "rackhd node ID", 264 | "required": true, 265 | "type": "string" 266 | } 267 | ], 268 | "summary": "get specific node by id", 269 | "responses": { 270 | 271 | "200": { 272 | "description": "Not Implemented" 273 | }, 274 | 275 | "default": { 276 | "description": "unexpected error" 277 | } 278 | } 279 | } 280 | }, 281 | "/nodes": { 282 | "get": { 283 | "x-swagger-router-controller": "Shovel", 284 | "tags": [ "RackHD API Wrappers" ], 285 | "operationId": "nodesGet", 286 | "summary": "get All rackhd Nodes that been discovered with BMC,DMI information", 287 | "responses": { 288 | 289 | "200": { 290 | "description": "Not Implemented" 291 | }, 292 | 293 | "default": { 294 | "description": "unexpected error" 295 | } 296 | } 297 | } 298 | }, 299 | "/nodes/{identifier}/sel": { 300 | "get": { 301 | "x-swagger-router-controller": "Shovel", 302 | "tags": [ "RackHD API Wrappers" ], 303 | "operationId": "getSeldata", 304 | "parameters": [ 305 | { 306 | "name": "identifier", 307 | "in": "path", 308 | "description": "Node SEL information", 309 | "required": true, 310 | "type": "string" 311 | } 312 | ], 313 | "summary": "get current SEL data for specified node ID", 314 | "responses": { 315 | "200": { 316 | "description": "Not Implemented" 317 | }, 318 | 319 | "default": { 320 | "description": "unexpected error" 321 | } 322 | } 323 | } 324 | }, 325 | "/ironic/nodes": { 326 | "get": { 327 | "x-swagger-router-controller": "Shovel", 328 | "tags": [ "Ironic API Wrappers" ], 329 | "operationId": "ironicnodesGet", 330 | "summary": "get All ironic Nodes", 331 | "responses": { 332 | 333 | "200": { 334 | "description": "Not Implemented" 335 | }, 336 | 337 | "default": { 338 | "description": "unexpected error" 339 | } 340 | } 341 | } 342 | }, 343 | "/ironic/node/{identifier}": { 344 | "patch": { 345 | "x-swagger-router-controller": "Shovel", 346 | "tags": [ "Ironic API Wrappers" ], 347 | "operationId": "ironicnodePatch", 348 | "summary": "patch specified ironic node", 349 | "parameters": [ 350 | { 351 | "name": "identifier", 352 | "in": "path", 353 | "description": "Ironic node ID", 354 | "required": true, 355 | "type": "string" 356 | }, 357 | { 358 | "name": "patchnode", 359 | "in": "body", 360 | "description": "Node patch form data", 361 | "required": true, 362 | "schema": { 363 | "$ref": "#/definitions/patchnode" 364 | } 365 | } 366 | ], 367 | "responses": { 368 | "200": { 369 | "description": "Not Implemented" 370 | }, 371 | 372 | "default": { 373 | "description": "unexpected error" 374 | } 375 | } 376 | } 377 | }, 378 | "/ironic/chassis/{identifier}": { 379 | "get": { 380 | "x-swagger-router-controller": "Shovel", 381 | "tags": [ "Ironic API Wrappers" ], 382 | "operationId": "ironicchassisGet", 383 | "summary": "get Ironic chassis by id", 384 | "parameters": [ 385 | { 386 | "name": "identifier", 387 | "in": "path", 388 | "description": "Ironic node ID", 389 | "required": true, 390 | "type": "string" 391 | } 392 | ], 393 | "responses": { 394 | 395 | "200": { 396 | "description": "Not Implemented" 397 | }, 398 | 399 | "default": { 400 | "description": "unexpected error" 401 | } 402 | } 403 | } 404 | }, 405 | "/ironic/nodes/{identifier}": { 406 | "get": { 407 | "x-swagger-router-controller": "Shovel", 408 | "tags": [ "Ironic API Wrappers" ], 409 | "operationId": "ironicnodeGet", 410 | "summary": "get Ironic node by name", 411 | "parameters": [ 412 | { 413 | "name": "identifier", 414 | "in": "path", 415 | "description": "Ironic node name or ID", 416 | "required": true, 417 | "type": "string" 418 | } 419 | ], 420 | "responses": { 421 | 422 | "200": { 423 | "description": "Not Implemented" 424 | }, 425 | 426 | "default": { 427 | "description": "unexpected error" 428 | } 429 | } 430 | } 431 | }, 432 | "/register": { 433 | "post": { 434 | "x-swagger-router-controller": "Shovel", 435 | "tags": [ "Shoveling" ], 436 | "operationId": "registerpost", 437 | "summary": "Register an rackhd node in Ironic", 438 | "parameters": [ 439 | { 440 | "name": "Node Info", 441 | "in": "body", 442 | "description": "Node Registration info", 443 | "required": true, 444 | "schema": { 445 | "$ref": "#/definitions/regnode" 446 | } 447 | } 448 | ], 449 | "responses": { 450 | 451 | "200": { 452 | "description": "Not Implemented" 453 | }, 454 | 455 | "default": { 456 | "description": "unexpected error" 457 | } 458 | } 459 | } 460 | }, 461 | "/unregister/{identifier}": { 462 | "delete": { 463 | "x-swagger-router-controller": "Shovel", 464 | "tags": [ "Shoveling" ], 465 | "operationId": "unregisterdel", 466 | "summary": "UnRegister a node from Ironic", 467 | "parameters": [ 468 | { 469 | "name": "identifier", 470 | "in": "path", 471 | "description": "Ironic node ID", 472 | "required": true, 473 | "type": "string" 474 | } 475 | ], 476 | "responses": { 477 | 478 | "200": { 479 | "description": "Not Implemented" 480 | }, 481 | 482 | "default": { 483 | "description": "unexpected error" 484 | } 485 | } 486 | } 487 | }, 488 | "/ironic/drivers": { 489 | "get": { 490 | "x-swagger-router-controller": "Shovel", 491 | "tags": [ "Ironic API Wrappers" ], 492 | "operationId": "driversGet", 493 | "summary": "Get all the drivers used in Ironic", 494 | "responses": { 495 | 496 | "200": { 497 | "description": "Not implemented", 498 | 499 | "headers": { 500 | "x-expires": { 501 | "type": "string" 502 | } 503 | } 504 | }, 505 | "default": { 506 | "description": "unexpected error" 507 | } 508 | } 509 | } 510 | }, 511 | "/glance/images": { 512 | "get": { 513 | "x-swagger-router-controller": "Shovel", 514 | "tags": [ "Glance API Wrappers" ], 515 | "operationId": "imagesGet", 516 | "summary": "Get all the images in Glance", 517 | "responses": { 518 | 519 | "200": { 520 | "description": "Not implemented", 521 | 522 | "headers": { 523 | "x-expires": { 524 | "type": "string" 525 | } 526 | } 527 | }, 528 | "default": { 529 | "description": "unexpected error" 530 | } 531 | } 532 | } 533 | }, 534 | "/deployos/{identifier}/": { 535 | "post": { 536 | "x-swagger-router-controller": "Shovel", 537 | "tags": [ "Nodes Provisionning" ], 538 | "operationId": "deployOS", 539 | "summary": "Deploy OS to a specific node", 540 | "parameters": [ 541 | { 542 | "name": "identifier", 543 | "in": "path", 544 | "description": "rackHD node ID", 545 | "required": true, 546 | "type": "string" 547 | }, 548 | { 549 | "name": "Config", 550 | "in": "body", 551 | "description": "OS Configuration", 552 | "required": true, 553 | "schema": { 554 | "$ref": "#/definitions/deployos" 555 | } 556 | } 557 | ], 558 | "responses": { 559 | "200": { 560 | "description": "Not Implemented" 561 | }, 562 | "default": { 563 | "description": "unexpected error" 564 | } 565 | } 566 | } 567 | }, 568 | "/worflow-status/{identifier}": { 569 | "get": { 570 | "x-swagger-router-controller": "Shovel", 571 | "tags": [ "Nodes Provisionning" ], 572 | "operationId": "workflowStatus", 573 | "summary": "Get status of an active worflow running on a certain node in rackHD", 574 | "parameters": [ 575 | { 576 | "name": "identifier", 577 | "in": "path", 578 | "description": "rackHD node ID", 579 | "required": true, 580 | "type": "string" 581 | } 582 | ], 583 | "responses": { 584 | "200": { 585 | "description": "Not Implemented" 586 | }, 587 | "default": { 588 | "description": "unexpected error" 589 | } 590 | } 591 | } 592 | }, 593 | "/run/ansible-playbook/{identifier}": { 594 | "post": { 595 | "x-swagger-router-controller": "Shovel", 596 | "tags": [ "Nodes Provisionning" ], 597 | "operationId": "runAnsible", 598 | "summary": "run the uploaded ansible playbook", 599 | "parameters": [ 600 | { 601 | "name": "identifier", 602 | "in": "path", 603 | "description": "rackHD node ID", 604 | "required": true, 605 | "type": "string" 606 | }, 607 | { 608 | "name": "Config", 609 | "in": "body", 610 | "description": "OS Configuration", 611 | "required": true, 612 | "schema": { 613 | "$ref": "#/definitions/run-ansible" 614 | } 615 | } 616 | ], 617 | "responses": { 618 | "200": { 619 | "description": "Not Implemented" 620 | }, 621 | "default": { 622 | "description": "unexpected error" 623 | } 624 | } 625 | } 626 | } 627 | }, 628 | "definitions": { 629 | "monorail": { 630 | "type": "object", 631 | "properties": { 632 | "httpHost": { 633 | "type": "string" 634 | }, 635 | "httpPort": { 636 | "type": "string" 637 | }, 638 | "version": { 639 | "type": "string" 640 | } 641 | } 642 | }, 643 | "config": { 644 | "type": "object", 645 | "properties": { 646 | "httpPort": { 647 | "type": "integer", 648 | "format": "int32" 649 | } 650 | } 651 | }, 652 | "ironic": { 653 | "type": "object", 654 | "properties": { 655 | "httpHost": { 656 | "type": "string" 657 | }, 658 | "httpPort": { 659 | "type": "string" 660 | }, 661 | "version": { 662 | "type": "string" 663 | }, 664 | "os_username": { 665 | "type": "string" 666 | }, 667 | "os_password": { 668 | "type": "string" 669 | }, 670 | "os_tenant_name": { 671 | "type": "string" 672 | }, 673 | "os_auth_token": { 674 | "type": "string" 675 | }, 676 | "insecure": { 677 | "type": "string" 678 | } 679 | } 680 | }, 681 | "glance": { 682 | "type": "object", 683 | "properties": { 684 | "httpHost": { 685 | "type": "string" 686 | }, 687 | "httpPort": { 688 | "type": "string" 689 | }, 690 | "version": { 691 | "type": "string" 692 | }, 693 | "os_username": { 694 | "type": "string" 695 | }, 696 | "os_password": { 697 | "type": "string" 698 | }, 699 | "os_tenant_name": { 700 | "type": "string" 701 | }, 702 | "os_auth_token": { 703 | "type": "string" 704 | }, 705 | "insecure": { 706 | "type": "string" 707 | } 708 | } 709 | }, 710 | "keystone": { 711 | "type": "object", 712 | "properties": { 713 | "httpHost": { 714 | "type": "string" 715 | }, 716 | "httpPort": { 717 | "type": "string" 718 | }, 719 | "version": { 720 | "type": "string" 721 | } 722 | } 723 | }, 724 | "regnode": { 725 | "type": "object", 726 | "required": [ 727 | "uuid", 728 | "kernel", 729 | "ramdisk", 730 | "port" 731 | ], 732 | "properties": { 733 | "uuid": { 734 | "type": "string" 735 | }, 736 | "driver": { 737 | "type": "string" 738 | }, 739 | "ipmihost": { 740 | "type": "string" 741 | }, 742 | "ipmiuser": { 743 | "type": "string" 744 | }, 745 | "ipmipass": { 746 | "type": "string" 747 | }, 748 | "sshhost": { 749 | "type": "string" 750 | }, 751 | "sshuser": { 752 | "type": "string" 753 | }, 754 | "sshpass": { 755 | "type": "string" 756 | }, 757 | "sshport": { 758 | "type": "string" 759 | }, 760 | "name": { 761 | "type": "string" 762 | }, 763 | "kernel": { 764 | "type": "string" 765 | }, 766 | "ramdisk": { 767 | "type": "string" 768 | }, 769 | "port": { 770 | 771 | "type": "string" 772 | } 773 | } 774 | }, 775 | "patchnode": { 776 | "type": "array", 777 | "items": { 778 | "type": "object" 779 | } 780 | }, 781 | "deployos": { 782 | "type": "object", 783 | "required": [ 784 | "name", 785 | "options" 786 | ], 787 | "properties": { 788 | "name": { 789 | "type": "string", 790 | "example": "Graph.InstallCentOS" 791 | }, 792 | "options": { 793 | "type": "object", 794 | "required": [ 795 | "defaults" 796 | ], 797 | "properties": { 798 | "defaults": { 799 | "type": "object", 800 | "properties": { 801 | "obmServiceName": { 802 | "type": "string", 803 | "example": "ipmi-obm-service" 804 | } 805 | } 806 | }, 807 | "install-os": { 808 | "type": "object", 809 | "properties": { 810 | "repo": { 811 | "type": "string" 812 | }, 813 | "rootPassword": { 814 | "type": "string" 815 | }, 816 | "users": { 817 | "type": "array", 818 | "items": { 819 | "type": "object", 820 | "required": [ 821 | "name", 822 | "password" 823 | ], 824 | "properties": { 825 | "name": { 826 | "type": "string" 827 | }, 828 | "password": { 829 | "type": "string" 830 | }, 831 | "uid": { 832 | "type": "integer" 833 | } 834 | } 835 | } 836 | }, 837 | "networkDevices": { 838 | "type": "array", 839 | "items": { 840 | "type": "object", 841 | "required": [ 842 | "device", 843 | "ipv4" 844 | ], 845 | "properties": { 846 | "device": { 847 | "type": "string" 848 | }, 849 | "ipv4": { 850 | "type": "object" 851 | } 852 | } 853 | } 854 | } 855 | } 856 | } 857 | } 858 | } 859 | } 860 | }, 861 | "run-ansible": { 862 | "type": "object", 863 | "required": [ 864 | "name" 865 | ], 866 | "properties": { 867 | "name": { 868 | "type": "string", 869 | "example": "runExample" 870 | }, 871 | "vars": { 872 | "type": "object" 873 | }, 874 | "playbookPath": { 875 | "type": "string", 876 | "example": "files/extract/main.yml" 877 | } 878 | } 879 | } 880 | } 881 | } 882 | -------------------------------------------------------------------------------- /controllers/Shovel.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | /*eslint-env node*/ 3 | 4 | var monorail = require('./../lib/api/monorail/monorail'); 5 | var ironic = require('./../lib/api/openstack/ironic'); 6 | var config = require('./../config.json'); 7 | var glance = require('./../lib/api/openstack/glance'); 8 | var keystone = require('./../lib/api/openstack/keystone'); 9 | var logger = require('./../lib/services/logger').Logger('info'); 10 | var encryption = require('./../lib/services/encryption'); 11 | var jsonfile = require('jsonfile'); 12 | var _ = require('underscore'); 13 | var Promise = require('bluebird'); 14 | var ironicConfig = config.ironic; 15 | var glanceConfig = config.glance; 16 | 17 | /* 18 | * @api {get} /api/1.1/info / GET / 19 | * @apiDescription get shovel information 20 | * @apiVersion 1.1.0 21 | */ 22 | module.exports.infoGet = function infoGet(req, res) { 23 | 'use strict'; 24 | var info = { 25 | name: 'shovel', 26 | description: 'rackHD-ironic agent', 27 | appversion: config.shovel.appver, 28 | apiversion: config.shovel.apiver 29 | }; 30 | res.setHeader('Content-Type', 'application/json'); 31 | res.end(JSON.stringify(info)); 32 | }; 33 | 34 | /* 35 | * @api {get} /api/1.1/ironic/drivers / GET / 36 | * @apiDescription get ironic drivers 37 | * @apiVersion 1.1.0 38 | */ 39 | module.exports.driversGet = function driversGet(req, res) { 40 | 'use strict'; 41 | return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username, 42 | ironicConfig.os_password). 43 | then(function (token) { 44 | token = JSON.parse(token).access.token.id; 45 | return ironic.get_driver_list(token); 46 | }). 47 | then(function (result) { 48 | res.status(ironic.getStatus()); 49 | res.setHeader('Content-Type', 'application/json'); 50 | res.end(result); 51 | }) 52 | .catch(function (err) { 53 | logger.error({ message: err, path: req.url }); 54 | res.setHeader('Content-Type', 'application/json'); 55 | res.status(500); 56 | res.end(JSON.stringify(err)); 57 | }); 58 | }; 59 | 60 | /* 61 | * @api {get} /api/1.1/ironic/nodes / GET / 62 | * @apiDescription get ironic nodes 63 | * @apiVersion 1.1.0 64 | */ 65 | module.exports.ironicnodesGet = function ironicnodesGet(req, res) { 66 | 'use strict'; 67 | return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username, 68 | ironicConfig.os_password). 69 | then(function (token) { 70 | token = JSON.parse(token).access.token.id; 71 | return ironic.get_node_list(token); 72 | }). 73 | then(function (result) { 74 | res.setHeader('Content-Type', 'application/json'); 75 | res.status(ironic.getStatus()); 76 | res.end(result); 77 | }) 78 | .catch(function (err) { 79 | logger.error({ message: err, path: req.url }); 80 | res.setHeader('Content-Type', 'application/json'); 81 | res.status(500); 82 | res.end(JSON.stringify(err)); 83 | }); 84 | }; 85 | 86 | /* 87 | * @api {get} /api/1.1/ironic/chassis / GET / 88 | * @apiDescription get ironic chassis 89 | * @apiVersion 1.1.0 90 | */ 91 | module.exports.ironicchassisGet = function ironicchassisGet(req, res) { 92 | 'use strict'; 93 | return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username, 94 | ironicConfig.os_password). 95 | then(function (token) { 96 | token = JSON.parse(token).access.token.id; 97 | return ironic.get_chassis_by_id(token, req.swagger.params.identifier.value); 98 | }). 99 | then(function (result) { 100 | res.setHeader('Content-Type', 'application/json'); 101 | res.status(ironic.getStatus()); 102 | res.end(result); 103 | }) 104 | .catch(function (err) { 105 | logger.error({ message: err, path: req.url }); 106 | res.setHeader('Content-Type', 'application/json'); 107 | res.status(500); 108 | res.end(JSON.stringify(err)); 109 | }); 110 | }; 111 | 112 | /* 113 | * @api {get} /api/1.1/ironic/nodes / GET / 114 | * @apiDescription get ironic node 115 | * @apiVersion 1.1.0 116 | */ 117 | module.exports.ironicnodeGet = function ironicnodeGet(req, res) { 118 | 'use strict'; 119 | return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username, 120 | ironicConfig.os_password). 121 | then(function (token) { 122 | token = JSON.parse(token).access.token.id; 123 | return ironic.get_node(token, req.swagger.params.identifier.value); 124 | }). 125 | then(function (result) { 126 | res.setHeader('Content-Type', 'application/json'); 127 | res.status(ironic.getStatus()); 128 | res.end(result); 129 | }) 130 | .catch(function (err) { 131 | logger.error({ message: err, path: req.url }); 132 | res.setHeader('Content-Type', 'application/json'); 133 | res.status(500); 134 | res.end(JSON.stringify(err)); 135 | }); 136 | }; 137 | 138 | /* 139 | * @api {patch} /api/1.1/ironic/node/identifier / PATCH / 140 | * @apiDescription patch ironic node info 141 | * @apiVersion 1.1.0 142 | */ 143 | module.exports.ironicnodePatch = function ironicnodePatch(req, res) { 144 | 'use strict'; 145 | return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username, 146 | ironicConfig.os_password). 147 | then(function (token) { 148 | token = JSON.parse(token).access.token.id; 149 | var data = JSON.stringify(req.body); 150 | return ironic.patch_node(token, req.swagger.params.identifier.value, data); 151 | }). 152 | then(function (result) { 153 | res.setHeader('Content-Type', 'application/json'); 154 | res.status(ironic.getStatus()); 155 | res.end(result); 156 | }) 157 | .catch(function (err) { 158 | logger.error({ message: err, path: req.url }); 159 | res.setHeader('Content-Type', 'application/json'); 160 | res.status(500); 161 | res.end(JSON.stringify(err)); 162 | }); 163 | }; 164 | 165 | /* 166 | * @api {get} /api/1.1/catalogs/identifier / GET / 167 | * @apiDescription get catalogs 168 | * @apiVersion 1.1.0 169 | */ 170 | module.exports.catalogsGet = function catalogsGet(req, res) { 171 | 'use strict'; 172 | return monorail.request_catalogs_get(req.swagger.params.identifier.value). 173 | then(function (catalogs) { 174 | res.setHeader('Content-Type', 'application/json'); 175 | res.status(monorail.getStatus()); 176 | res.end(catalogs); 177 | }) 178 | .catch(function (err) { 179 | logger.error({ message: err, path: req.url }); 180 | res.setHeader('Content-Type', 'application/json'); 181 | res.status(500); 182 | res.end(JSON.stringify(err)); 183 | }); 184 | }; 185 | 186 | /* 187 | * @api {get} /api/1.1/catalogs/identifier / GET / 188 | * @apiDescription get catalogs by source 189 | * @apiVersion 1.1.0 190 | */ 191 | module.exports.catalogsbysourceGet = function catalogsbysourceGet(req, res) { 192 | 'use strict'; 193 | return monorail.get_catalog_data_by_source(req.swagger.params.identifier.value, 194 | req.swagger.params.source.value). 195 | then(function (catalogs) { 196 | res.setHeader('Content-Type', 'application/json'); 197 | res.status(monorail.getStatus()); 198 | res.end(catalogs); 199 | }) 200 | .catch(function (err) { 201 | logger.error({ message: err, path: req.url }); 202 | res.setHeader('Content-Type', 'application/json'); 203 | res.status(500); 204 | res.end(JSON.stringify(err)); 205 | }); 206 | }; 207 | 208 | /* 209 | * @api {get} /api/1.1/nodes/identifier / GET / 210 | * @apiDescription get specific node by id 211 | * @apiVersion 1.1.0 212 | */ 213 | module.exports.nodeGet = function nodeGet(req, res) { 214 | 'use strict'; 215 | return monorail.request_node_get(req.swagger.params.identifier.value). 216 | then(function (node) { 217 | res.setHeader('Content-Type', 'application/json'); 218 | res.status(monorail.getStatus()); 219 | res.end(node); 220 | }) 221 | .catch(function (err) { 222 | logger.error({ message: err, path: req.url }); 223 | res.setHeader('Content-Type', 'application/json'); 224 | res.status(500); 225 | res.end(JSON.stringify(err)); 226 | }); 227 | }; 228 | 229 | /* 230 | * @api {get} /api/1.1/nodes / GET / 231 | * @apiDescription get list of monorail nodes 232 | * @apiVersion 1.1.0 233 | */ 234 | module.exports.nodesGet = function nodesGet(req, res) { 235 | 'use strict'; 236 | return monorail.request_nodes_get(). 237 | then(function (nodes) { 238 | Promise.filter(JSON.parse(nodes), function (node) { 239 | return monorail.lookupCatalog(node); 240 | }) 241 | .then(function (discoveredNodes) { 242 | res.setHeader('Content-Type', 'application/json'); 243 | res.status(monorail.getStatus()); 244 | res.end(JSON.stringify(discoveredNodes)); 245 | }); 246 | }) 247 | .catch(function (err) { 248 | logger.error({ message: err, path: req.url }); 249 | res.status(500); 250 | res.setHeader('Content-Type', 'application/json'); 251 | res.end(JSON.stringify(err)); 252 | }); 253 | }; 254 | 255 | /* 256 | * @api {get} /api/1.1/nodes/identifier/sel / GET / 257 | * @apiDescription get specific node by id 258 | * @apiVersion 1.1.0 259 | */ 260 | module.exports.getSeldata = function getSeldata(req, res,next) { 261 | 'use strict'; 262 | return monorail.request_poller_get(req.swagger.params.identifier.value). 263 | then(function (pollers) { 264 | pollers = JSON.parse(pollers); 265 | return Promise.filter(pollers, function (poller) { 266 | return poller.config.command === 'sel'; 267 | }) 268 | .then(function (sel) { 269 | if (sel.length > 0) { 270 | return monorail.request_poller_data_get(sel[0].id) 271 | .then(function (data) { 272 | res.setHeader('Content-Type', 'application/json'); 273 | res.status(monorail.getStatus()); 274 | res.end(data); 275 | }); 276 | } 277 | next(); 278 | }); 279 | }) 280 | .catch(function (err) { 281 | logger.error({ message: err, path: req.url }); 282 | res.setHeader('Content-Type', 'application/json'); 283 | res.status(500); 284 | res.end(JSON.stringify(err)); 285 | }); 286 | }; 287 | 288 | /* 289 | * @api register: node 290 | * @apiDescription register a node in Ironic 291 | * @apiVersion 1.1.0 292 | */ 293 | module.exports.registerpost = function registerpost(req, res) { 294 | 'use strict'; 295 | var localGb, ironicToken, ironicNode, extra, port, propreties, node, info, userEntry; 296 | //init 297 | extra = port = propreties = node = info = {}; 298 | userEntry = req.body; 299 | if (userEntry.driver === 'pxe_ipmitool') { 300 | info = { 301 | ipmi_address: userEntry.ipmihost, 302 | ipmi_username: userEntry.ipmiuser, 303 | ipmi_password: userEntry.ipmipass, 304 | deploy_kernel: userEntry.kernel, 305 | deploy_ramdisk: userEntry.ramdisk 306 | }; 307 | } else if (userEntry.driver === 'pxe_ssh') { 308 | info = { 309 | ssh_address: userEntry.sshhost, 310 | ssh_username: userEntry.sshuser, 311 | ssh_password: userEntry.sshpass, 312 | ssh_port: userEntry.sshport, 313 | deploy_kernel: userEntry.kernel, 314 | deploy_ramdisk: userEntry.ramdisk 315 | }; 316 | } else { 317 | info = {}; 318 | } 319 | 320 | /* Fill in the extra meta data with some failover and event data */ 321 | extra = { 322 | nodeid: userEntry.uuid, 323 | name: userEntry.name, 324 | lsevents: { time: 0 }, 325 | eventcnt: 0, 326 | timer: {} 327 | }; 328 | if (typeof userEntry.failovernode !== 'undefined') { 329 | extra.failover = userEntry.failovernode; 330 | } 331 | if (typeof userEntry.eventre !== 'undefined') { 332 | extra.eventre = userEntry.eventre; 333 | } 334 | 335 | localGb = 0.0; 336 | return monorail.request_node_get(userEntry.uuid). 337 | then(function (result) { 338 | if (!JSON.parse(result).hasOwnProperty('name')) { 339 | var error = { error_message: { message: 'failed to find required node in RackHD' } }; 340 | logger.error(error); 341 | throw error; 342 | } 343 | ironicNode = JSON.parse(result); 344 | return monorail.nodeDiskSize(ironicNode) 345 | .catch(function (err) { 346 | var error = { error_message: { message: 'failed to get compute node Disk Size' } }; 347 | logger.error(err); 348 | throw error; 349 | 350 | }); 351 | }).then(function (localDisk) { 352 | localGb = localDisk; 353 | return monorail.getNodeMemoryCpu(ironicNode) 354 | .catch(function (err) { 355 | var error = { error_message: { message: 'failed to get compute node memory size' } }; 356 | logger.error(err); 357 | throw error; 358 | }); 359 | }).then(function (dmiData) { 360 | if (localGb === 0 || dmiData.cpus === 0 || dmiData.memory === 0) { 361 | var error = { 362 | error_message: { 363 | message: 'failed to get compute node data', 364 | nodeDisk: localGb, 365 | memorySize: dmiData.memory, 366 | cpuCount: dmiData.cpus 367 | } 368 | }; 369 | throw error; 370 | } 371 | propreties = { 372 | cpus: dmiData.cpus, 373 | memory_mb: dmiData.memory, 374 | local_gb: localGb 375 | }; 376 | node = { 377 | name: userEntry.uuid, 378 | driver: userEntry.driver, 379 | driver_info: info, 380 | properties: propreties, 381 | extra: extra 382 | }; 383 | return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username, 384 | ironicConfig.os_password); 385 | }). 386 | then(function (token) { 387 | ironicToken = JSON.parse(token).access.token.id; 388 | return ironic.create_node(ironicToken, JSON.stringify(node)); 389 | }). 390 | then(function (ret) { 391 | logger.debug('\r\ncreate node:\r\n' + ret); 392 | if (ret && JSON.parse(ret).error_message) { 393 | throw JSON.parse(ret); 394 | } 395 | ironicNode = JSON.parse(ret); 396 | port = { address: userEntry.port, node_uuid: ironicNode.uuid }; 397 | return ironic.create_port(ironicToken, JSON.stringify(port)); 398 | }). 399 | then(function (createPort) { 400 | if (createPort && JSON.parse(createPort).error_message) { 401 | throw JSON.parse(createPort); 402 | } 403 | logger.info('\r\nCreate port:\r\n' + JSON.stringify(createPort)); 404 | return ironic.set_power_state(ironicToken, ironicNode.uuid, 'on'); 405 | }). 406 | then(function (pwrState) { 407 | logger.info('\r\npwrState: on'); 408 | if (pwrState && JSON.parse(pwrState).error_message) { 409 | throw JSON.parse(pwrState); 410 | } 411 | }).then(function () { 412 | var timer = {}; 413 | timer.start = new Date().toJSON(); 414 | timer.finish = new Date().toJSON(); 415 | timer.stop = false; 416 | timer.timeInterval = 15000; 417 | timer.isDone = true; 418 | var data = [{ path: '/extra/timer', value: timer, op: 'replace' }]; 419 | return ironic.patch_node(ironicToken, ironicNode.uuid, JSON.stringify(data)); 420 | }). 421 | then(function (result) { 422 | logger.info('\r\patched node:\r\n' + result); 423 | }). 424 | then(function () { 425 | _.each(ironicNode.identifiers, function (mac) { 426 | return monorail.request_whitelist_set(mac) 427 | .then(function (whitelist) { 428 | logger.info('\r\nmonorail whitelist:\r\n' + JSON.stringify(whitelist)); 429 | }); 430 | }); 431 | }) 432 | .then(function () { 433 | res.setHeader('Content-Type', 'application/json'); 434 | var success = { 435 | result: 'success' 436 | }; 437 | res.end(JSON.stringify(success)); 438 | }) 439 | .catch(function (err) { 440 | logger.error({ message: err, path: req.url }); 441 | res.setHeader('Content-Type', 'application/json'); 442 | res.status(500); 443 | res.end(JSON.stringify(err)); 444 | }); 445 | }; 446 | /* 447 | * @api unregister: node 448 | * @apiDescription unregister a node from Ironic 449 | * @apiVersion 1.1.0 450 | */ 451 | module.exports.unregisterdel = function unregisterdel(req, res) { 452 | 'use strict'; 453 | var ironicToken; 454 | return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username, 455 | ironicConfig.os_password). 456 | then(function (token) { 457 | ironicToken = JSON.parse(token).access.token.id; 458 | return ironic.delete_node(ironicToken, req.swagger.params.identifier.value); 459 | }) 460 | .then(function (delNode) { 461 | if (delNode && JSON.parse(delNode).error_message) { 462 | throw delNode; 463 | } else { 464 | logger.info('ironicNode: ' + 465 | req.swagger.params.identifier.value + 466 | ' is been deleted susccessfully'); 467 | res.setHeader('Content-Type', 'application/json'); 468 | var success = { 469 | result: 'success' 470 | }; 471 | res.end(JSON.stringify(success)); 472 | //remove macs from whitelist in rackHD 473 | return monorail.request_node_get(req.swagger.params.identifier.value) 474 | .then(function (node) { 475 | _.each(JSON.parse(node).identifiers, function (mac) { 476 | return monorail.request_whitelist_del(mac); 477 | }); 478 | }); 479 | } 480 | }) 481 | .catch(function (err) { 482 | logger.error({ message: err, path: req.url }); 483 | res.setHeader('Content-Type', 'application/json'); 484 | res.status(500); 485 | res.end(JSON.stringify(err)); 486 | }); 487 | }; 488 | 489 | /* 490 | * @api config.json: modify shovel-monorail 491 | * @apiDescription modify shovel config.json file and restart the server 492 | * @apiVersion 1.1.0 493 | */ 494 | module.exports.configsetmono = function configsetmono(req, res) { 495 | 'use strict'; 496 | res.setHeader('content-type', 'text/plain'); 497 | if (setConfig('monorail', req.body)) { 498 | res.end('success'); 499 | } else { 500 | res.status(500); 501 | res.end('failed to update monorail config'); 502 | } 503 | }; 504 | 505 | /* 506 | * @api config.json: modify shovel-keystone 507 | * @apiDescription modify shovel config.json file and restart the server 508 | * @apiVersion 1.1.0 509 | */ 510 | module.exports.configsetkeystone = function configsetkeystone(req, res) { 511 | 'use strict'; 512 | res.setHeader('content-type', 'text/plain'); 513 | if (setConfig('keystone', req.body)) { 514 | res.end('success'); 515 | } else { 516 | res.status(500); 517 | res.end('failed to update keystone config'); 518 | } 519 | }; 520 | 521 | /* 522 | * @api config.json: modify shovel-ironic 523 | * @apiDescription modify shovel config.json file and restart the server 524 | * @apiVersion 1.1.0 525 | */ 526 | module.exports.configsetironic = function configsetironic(req, res) { 527 | 'use strict'; 528 | res.setHeader('content-type', 'text/plain'); 529 | if (req.body.hasOwnProperty('os_password')) { 530 | var password = req.body.os_password; 531 | //replace password with encrypted value 532 | try { 533 | req.body.os_password = encryption.encrypt(password); 534 | } catch (err) { 535 | logger.error(err); 536 | res.end('failed to update ironic config'); 537 | } 538 | } 539 | if (setConfig('ironic', req.body)) { 540 | res.end('success'); 541 | } else { 542 | res.status(500); 543 | res.end('failed to update ironic config'); 544 | } 545 | }; 546 | 547 | /* 548 | * @api config.json: modify shovel-glance 549 | * @apiDescription modify shovel config.json file and restart the server 550 | * @apiVersion 1.1.0 551 | */ 552 | module.exports.configsetglance = function configsetglance(req, res) { 553 | 'use strict'; 554 | res.setHeader('content-type', 'text/plain'); 555 | if (req.body.hasOwnProperty('os_password')) { 556 | var password = req.body.os_password; 557 | //replace password with encrypted value 558 | try { 559 | req.body.os_password = encryption.encrypt(password); 560 | } catch (err) { 561 | logger.error(err); 562 | res.end('failed to update ironic config'); 563 | } 564 | } 565 | if (setConfig('glance', req.body)) { 566 | res.end('success'); 567 | } else { 568 | res.status(500); 569 | res.end('failed to update glance config'); 570 | } 571 | }; 572 | 573 | /* 574 | * @api config.json: modify 575 | * @apiDescription modify shovel config.json file and restart the server 576 | * @apiVersion 1.1.0 577 | */ 578 | module.exports.configset = function configset(req, res) { 579 | 'use strict'; 580 | res.setHeader('content-type', 'text/plain'); 581 | if (setConfig('shovel', req.body) === true) { 582 | res.end('success'); 583 | } else { 584 | res.status(500); 585 | res.end('failed to update shovel config'); 586 | } 587 | }; 588 | 589 | function setConfig(keyValue, entry) { 590 | 'use strict'; 591 | var filename = 'config.json'; 592 | jsonfile.readFile(filename, function (error, output) { 593 | try { 594 | var content = keyValue === null ? output : output[keyValue]; 595 | var filteredList = _.pick(content, Object.keys(entry)); 596 | _.each(Object.keys(filteredList), function (key) { 597 | content[key] = entry[key]; 598 | 599 | }); 600 | output[keyValue] = content; 601 | jsonfile.writeFile(filename, output, { spaces: 2 }, function () { 602 | logger.debug(content); 603 | }); 604 | } catch (err) { 605 | logger.error(err); 606 | return false; 607 | } 608 | }); 609 | return true; 610 | } 611 | 612 | /* 613 | * @api config.json: get 614 | * @apiDescription get shovel config.json file and restart the server 615 | * @apiVersion 1.1.0 616 | */ 617 | module.exports.configget = function configget(req, res) { 618 | 'use strict'; 619 | var filename = 'config.json'; 620 | jsonfile.readFile(filename, function (error,content) { 621 | try { 622 | delete content.key; 623 | if (content.ironic.hasOwnProperty('os_password')) { 624 | content.ironic.os_password = '[REDACTED]'; 625 | } 626 | if (content.glance.hasOwnProperty('os_password')) { 627 | content.glance.os_password = '[REDACTED]'; 628 | } 629 | res.setHeader('Content-Type', 'application/json'); 630 | res.end(JSON.stringify(content)); 631 | } catch (err) { 632 | logger.error(err); 633 | res.setHeader('content-type', 'text/plain'); 634 | res.status(500); 635 | res.end('failed to get config'); 636 | } 637 | }); 638 | }; 639 | 640 | /* 641 | * @api {get} /api/1.1/glance/images / GET / 642 | * @apiDescription get glance images 643 | */ 644 | module.exports.imagesGet = function imagesGet(req, res) { 645 | 'use strict'; 646 | return keystone.authenticatePassword(glanceConfig.os_tenant_name, glanceConfig.os_username, 647 | glanceConfig.os_password). 648 | then(function (token) { 649 | token = JSON.parse(token).access.token.id; 650 | return glance.get_images(token); 651 | }). 652 | then(function (result) { 653 | res.setHeader('Content-Type', 'application/json'); 654 | res.end(result); 655 | }) 656 | .catch(function (err) { 657 | logger.error({ message: err, path: req.url }); 658 | res.setHeader('Content-Type', 'application/json'); 659 | res.status(500); 660 | res.end(JSON.stringify(err)); 661 | }); 662 | }; 663 | /* 664 | * @api {post} /api/1.1/deployOS/identifier / POST / 665 | * @apiDescription deploy OS to specific node 666 | */ 667 | module.exports.deployOS = function deployOS(req, res) { 668 | 'use strict'; 669 | res.setHeader('Content-Type', 'application/json'); 670 | return monorail.runWorkFlow(req.swagger.params.identifier.value, 671 | req.body.name,req.body) 672 | .then(function(result) { 673 | res.status(monorail.getStatus()); 674 | res.end(result); 675 | }) 676 | .catch(function(err) { 677 | res.status(500); 678 | res.end(JSON.stringify(err)); 679 | }); 680 | }; 681 | /* 682 | * @api {get} /api/1.1/workflow-status/identifier / GET / 683 | * @apiDescription Get status of an active worflow running on a node in rackHD 684 | */ 685 | module.exports.workflowStatus = function workflowStatus(req,res) { 686 | 'use strict'; 687 | res.setHeader('Content-Type', 'application/json'); 688 | return monorail.getWorkFlowActive(req.swagger.params.identifier.value) 689 | .then(function(data) { 690 | res.status(monorail.getStatus()); 691 | if (monorail.getStatus() === 200 && data) { 692 | res.end(JSON.stringify({jobStatus:'Running'})); 693 | } else { 694 | res.end(JSON.stringify({jobStatus:'Currently there is no job running on this node'})); 695 | } 696 | }) 697 | .catch(function(err) { 698 | res.status(500); 699 | res.end(JSON.stringify(err)); 700 | }); 701 | }; 702 | /* 703 | * @api {put} /api/1.1/uploadFiles/filename / PUT / 704 | * @apiDescription uploaded ansible playbook in tar form and extract it 705 | */ 706 | //Code for tar file uploads 707 | // module.exports.uploadFiles = function uploadFiles(req, res) { 708 | // 'use strict'; 709 | // res.setHeader('content-type', 'text/plain'); 710 | // var tar = require('tar'); 711 | // var extractor = tar.Extract({path: 'files/extract'}) 712 | // .on('error', function(err) { 713 | // logger.error(err); 714 | // res.status(500); 715 | // res.end('error'); 716 | // }) 717 | // .on('end', function() { 718 | // res.status(202); 719 | // res.end('success'); 720 | // }); 721 | // var stream = require('stream'); 722 | // var bufferStream = new stream.PassThrough(); 723 | // bufferStream.end(new Buffer(req.swagger.params.playbook.value.buffer)); 724 | // bufferStream.pipe(extractor); 725 | // }; 726 | 727 | /* 728 | * @api {post} /api/1.1/runAnsible/{identifier} / POST / 729 | * @apiDescription run uploaded ansible playbook in tar form and extract it 730 | */ 731 | module.exports.runAnsible = function runAnsible(req, res) { 732 | 'use strict'; 733 | res.setHeader('Content-Type', 'application/json'); 734 | var ansibleTask = { 735 | friendlyName: req.body.name, 736 | injectableName: 'Task.Ansible.' + req.body.name, 737 | implementsTask: 'Task.Base.Ansible', 738 | options: { 739 | playbook: req.body.playbookPath, 740 | vars : req.body.vars 741 | }, 742 | properties: { } 743 | }; 744 | var ansibleWorkflow = { 745 | friendlyName: 'Graph ' + req.body.name, 746 | injectableName: 'Graph.Ansible.' + req.body.name, 747 | tasks : [ 748 | { 749 | label: 'ansible-job', 750 | taskName: 'Task.Ansible.' + req.body.name 751 | } 752 | ] 753 | }; 754 | return monorail.createTask(ansibleTask) 755 | .then(function() { 756 | return monorail.createWorkflow(ansibleWorkflow); 757 | }) 758 | .then(function() { 759 | return monorail.runWorkFlow(req.swagger.params.identifier.value, 760 | 'Graph.Ansible.' + req.body.name,null); 761 | }) 762 | .then(function(result) { 763 | res.status(monorail.getStatus()); 764 | res.end(result); 765 | }) 766 | .catch(function(err) { 767 | res.status(500); 768 | res.end(JSON.stringify(err)); 769 | }); 770 | }; 771 | -------------------------------------------------------------------------------- /test/controllers/Shovel.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015, EMC, Inc. 2 | 3 | var request = require('supertest'); 4 | var should = require('should'); 5 | var sinon = require('sinon'); 6 | var monorail = require('./../../lib/api/monorail/monorail'); 7 | var ironic = require('./../../lib/api/openstack/ironic'); 8 | var keystone = require('./../../lib/api/openstack/keystone'); 9 | var glance = require('./../../lib/api/openstack/glance'); 10 | var Promise = require('bluebird'); 11 | var _ = require('underscore'); 12 | var helper = require('./../helper'); 13 | var url = 'http://localhost:9008'; 14 | 15 | 16 | describe('****SHOVEL API Interface****', function () { 17 | 18 | var rackhdNode = [{ workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }]; 19 | var identifier = '9a761508-4eee-4065-b47b-45c22dff54c2'; 20 | var ironic_node_list = [{ uuid: "9a761508-4eee-4065-b47b-45c22dff54c2", extra: { name: "D51B-2U (dual 10G LoM)", eventre: "", nodeid: "564cefa014ee77be18e48efd", 21 | timer: { start: "2015-11-30T21:14:11.753Z", finish: "2015-11-30T21:14:11.772Z", stop: false, isDone: true, timeInteval: 5000 }, eventcnt: 0 } } ]; 22 | var nodePollers = [{ config: { command: "sel" }, id: "564dd86285fb1e7c72721543" }]; 23 | var _sel = { sel: [{ logId: "1", date: "12/03/2015", time: "08:54:11", sensorType: "Memory", sensorNumber: "#0x53", event: "Correctable ECC", value: "Asserted" }] }; 24 | var keyToken = { access: { token: { id: '123456' } } }; 25 | var selEvent = { message: "There is no cache record for the poller with ID 564cf02a4978dadc187976f5.Perhaps it has not been run yet?" }; 26 | var extraPatch = { extra: { name: "QuantaPlex T41S-2U", eventre: "Correctable ECC", nodeid: "565f3f3b4c95bce26f35c6a0", 27 | timer: { timeInterval: 15000, start: "2015-12-03T17:38:20.569Z", finish: "2015-12-03T17:38:20.604Z", stop: false, isDone: true } } }; 28 | var patchedData = [{ 'path': '/extra', 'value': extraPatch.extra, 'op': 'replace' }]; 29 | var catalog = [{ node: "9a761508-4eee-4065-b47b-45c22dff54c2", source: "dmi", data: {} }]; 30 | var ironicDrivers = { drivers: [{ "hosts": ["localhost"], "name": "pxe_ssh", "links": [] }] }; 31 | var ironicChassis = { uuid: "1ac07daf-264e-4bd5-b0c4-d53095c217ac", link: [], extra: {}, created_at: "", "nodes": [], description: "ironic test chassis" }; 32 | var catalogSource = [{ source: 'dmi', data: { 'Memory Device': [{ Size: '1 GB' }, { Size: '1 GB' }], 'Processor Information': [{}, {}] } }, 33 | { source: 'lsscsi', data: [{ peripheralType: 'disk', size: '1GB' }] }]; 34 | var glanceImages = { "images": [{ "name": "ir-deploy-pxe_ssh.initramfs", "container_format": "ari", "disk_format": "ari" }] }; 35 | 36 | before('start HTTP server', function () { 37 | helper.startServer(); 38 | }); 39 | after('stop HTTP server', function () { 40 | helper.stopServer(); 41 | }); 42 | describe('Shovel api unit testing', function () { 43 | var dmiData = { cpus: 1, memory: 1 }; 44 | var getWorkflow; 45 | beforeEach('set up mocks', function () { 46 | //monorail 47 | sinon.stub(monorail, 'request_node_get').returns(Promise.resolve(JSON.stringify(rackhdNode[0]))); 48 | sinon.stub(monorail, 'request_nodes_get').returns(Promise.resolve(JSON.stringify(rackhdNode))); 49 | sinon.stub(monorail, 'lookupCatalog').returns(Promise.resolve(true)); 50 | sinon.stub(monorail, 'request_catalogs_get').returns(Promise.resolve(JSON.stringify(catalog))); 51 | sinon.stub(monorail, 'request_poller_get').returns(Promise.resolve(JSON.stringify(nodePollers))); 52 | sinon.stub(monorail, 'request_poller_data_get').returns(Promise.resolve(JSON.stringify(_sel))); 53 | sinon.stub(monorail, 'request_whitelist_del').returns(Promise.resolve('')); 54 | sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(0)); 55 | sinon.stub(monorail, 'getNodeMemoryCpu').returns(Promise.resolve(dmiData)); 56 | sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0]))); 57 | sinon.stub(monorail, 'runWorkFlow').returns(Promise.resolve('{"definition":{}}')); 58 | getWorkflow = sinon.stub(monorail,'getWorkFlowActive'); 59 | sinon.stub(monorail, 'createTask').returns(Promise.resolve()); 60 | sinon.stub(monorail, 'createWorkflow').returns(Promise.resolve()); 61 | //glance 62 | sinon.stub(glance, 'get_images').returns(Promise.resolve(JSON.stringify(glanceImages))); 63 | //keystone 64 | sinon.stub(keystone, 'authenticatePassword').returns(Promise.resolve(JSON.stringify(keyToken))); 65 | //ironic 66 | sinon.stub(ironic, 'get_driver_list').returns(Promise.resolve(JSON.stringify(ironicDrivers))); 67 | sinon.stub(ironic, 'get_chassis_by_id').returns(Promise.resolve(JSON.stringify(ironicChassis))); 68 | sinon.stub(ironic, 'patch_node').returns(Promise.resolve(JSON.stringify(extraPatch))); 69 | sinon.stub(ironic, 'get_node_list').returns(Promise.resolve(JSON.stringify(ironic_node_list))); 70 | sinon.stub(ironic, 'get_node').returns(Promise.resolve(JSON.stringify(ironic_node_list[0]))); 71 | sinon.stub(ironic, 'delete_node').returns(Promise.resolve('')); 72 | }); 73 | 74 | afterEach('teardown mocks', function () { 75 | //monorail 76 | monorail['request_node_get'].restore(); 77 | monorail['request_nodes_get'].restore(); 78 | monorail['request_poller_get'].restore(); 79 | monorail['request_poller_data_get'].restore(); 80 | monorail['request_catalogs_get'].restore(); 81 | monorail['lookupCatalog'].restore(); 82 | monorail['request_whitelist_del'].restore(); 83 | monorail['nodeDiskSize'].restore(); 84 | monorail['getNodeMemoryCpu'].restore(); 85 | monorail['get_catalog_data_by_source'].restore(); 86 | monorail['runWorkFlow'].restore(); 87 | monorail['getWorkFlowActive'].restore(); 88 | monorail['createTask'].restore(); 89 | monorail['createWorkflow'].restore(); 90 | //ironic 91 | ironic['patch_node'].restore(); 92 | ironic['get_node_list'].restore(); 93 | ironic['get_node'].restore(); 94 | ironic['get_chassis_by_id'].restore(); 95 | ironic['get_driver_list'].restore(); 96 | ironic['delete_node'].restore(); 97 | //glance 98 | glance['get_images'].restore(); 99 | //keystone 100 | keystone['authenticatePassword'].restore(); 101 | }); 102 | 103 | it('shovel-info response should have property \'name\': \'shovel\'', function (done) { 104 | request(url) 105 | .get('/api/1.1/info') 106 | .end(function (err, res) { 107 | if (err) { 108 | throw err; 109 | } 110 | JSON.parse(res.text).should.have.property('name', 'shovel'); 111 | done(); 112 | }); 113 | }); 114 | 115 | it('shovel-catalogs/{identifier} in case of a correct rackHD id, response should include property node, source and data', function (done) { 116 | request(url) 117 | .get('/api/1.1/catalogs/' + identifier) 118 | .end(function (err, res) { 119 | if (err) { 120 | throw err; 121 | } 122 | JSON.parse(res.text)[0].should.have.property('node', identifier); 123 | JSON.parse(res.text)[0].should.have.property('data'); 124 | JSON.parse(res.text)[0].should.have.property('source'); 125 | done(); 126 | }); 127 | }); 128 | 129 | it('shovel-catalogs/{identifier}/source in case of a correct rackHD id, response should include property source and data', function (done) { 130 | request(url) 131 | .get('/api/1.1/catalogs/' + identifier + '/dmi') 132 | .end(function (err, res) { 133 | if (err) { 134 | throw err; 135 | } 136 | JSON.parse(res.text).should.have.property('data'); 137 | JSON.parse(res.text).should.have.property('source'); 138 | done(); 139 | }); 140 | }); 141 | 142 | it('shovel-nodes/{identifier} in case of correct id, response should include property: id,identifiers', function (done) { 143 | request(url) 144 | .get('/api/1.1/nodes/' + identifier) 145 | .end(function (err, res) { 146 | if (err) { 147 | throw err; 148 | } 149 | JSON.parse(res.text).should.have.property('id'); 150 | JSON.parse(res.text).should.have.property('identifiers'); 151 | done(); 152 | }); 153 | }); 154 | 155 | it('shovel-ironic/chassis/{identifier} in case of a correct id, response should include property: uuid , description ', function (done) { 156 | request(url) 157 | .get('/api/1.1/ironic/chassis/' + identifier) 158 | .end(function (err, res) { 159 | if (err) { 160 | throw err; 161 | } 162 | JSON.parse(res.text).should.have.property('uuid'); 163 | JSON.parse(res.text).should.have.property('description'); 164 | done(); 165 | }); 166 | }); 167 | 168 | it('shovel-ironic/drivers response should have property \'drivers\'', function (done) { 169 | request(url) 170 | .get('/api/1.1/ironic/drivers') 171 | .end(function (err, res) { 172 | if (err) { 173 | throw err; 174 | } 175 | JSON.parse(res.text).should.have.property('drivers'); 176 | done(); 177 | }); 178 | }); 179 | 180 | it('shovel-ironic/nodes response should have property \'uuid\'', function (done) { 181 | request(url) 182 | .get('/api/1.1/ironic/nodes') 183 | .end(function (err, res) { 184 | if (err) { 185 | throw err; 186 | } 187 | JSON.parse(res.text)[0].should.have.property('uuid'); 188 | done(); 189 | }); 190 | }); 191 | 192 | it('shovel-ironic/nodes/identifier response should have property \'uuid\'', function (done) { 193 | request(url) 194 | .get('/api/1.1/ironic/nodes/' + identifier) 195 | .end(function (err, res) { 196 | if (err) { 197 | throw err; 198 | } 199 | JSON.parse(res.text).should.have.property('uuid'); 200 | done(); 201 | }); 202 | }); 203 | 204 | it('shovel-ironic/patch response should have property nodeid timer', function (done) { 205 | var body = {}; 206 | request(url) 207 | .patch('/api/1.1/ironic/node/' + identifier) 208 | .send(body) 209 | .end(function (err, res) { 210 | if (err) { 211 | throw err; 212 | } 213 | JSON.parse(res.text).extra.should.have.property('nodeid'); 214 | JSON.parse(res.text).extra.should.have.property('timer'); 215 | done(); 216 | }); 217 | }); 218 | 219 | it('shovel-nodes response should have property "identifiers"', function (done) { 220 | request(url) 221 | .get('/api/1.1/nodes') 222 | .end(function (err, res) { 223 | if (err) { 224 | throw err; 225 | } 226 | for (item in JSON.parse(res.text)) { 227 | JSON.parse(res.text)[item].should.have.property('identifiers'); 228 | } 229 | done(); 230 | }); 231 | }); 232 | 233 | it('shovel-unregister/{identifier} if ironic id exist, response should include property: result: success', function (done) { 234 | request(url) 235 | .delete('/api/1.1/unregister/' + identifier) 236 | .end(function (err, res) { 237 | if (err) { 238 | throw err; 239 | } 240 | JSON.parse(res.text).result.should.be.equal('success'); 241 | done(); 242 | }); 243 | }); 244 | 245 | it('shovel-getconfig return success', function (done) { 246 | request(url) 247 | .get('/api/1.1/shovel/config') 248 | .end(function (err, res) { 249 | if (err) { 250 | throw err; 251 | } 252 | JSON.parse(res.text).should.have.property('shovel'); 253 | JSON.parse(res.text).should.have.property('ironic'); 254 | JSON.parse(res.text).should.have.property('glance'); 255 | JSON.parse(res.text).should.have.property('keystone') 256 | done(); 257 | }); 258 | }); 259 | 260 | it('shovel-set ironic config return success', function (done) { 261 | var body = { httpHost: "localhost" }; 262 | request(url) 263 | .post('/api/1.1/shovel/ironic/set-config') 264 | .send(body) 265 | .expect('Content-Type', /text/) 266 | .expect(200) 267 | .end(function (err, res) { 268 | if (err) { 269 | throw err; 270 | } 271 | res.text.should.be.exactly('success'); 272 | done(); 273 | }); 274 | }); 275 | 276 | it('shovel-set monorail config return success', function (done) { 277 | var body = { httpHost: "localhost" }; 278 | request(url) 279 | .post('/api/1.1/shovel/monorail/set-config') 280 | .send(body) 281 | .expect('Content-Type', /text/) 282 | .expect(200) 283 | .end(function (err, res) { 284 | if (err) { 285 | throw err; 286 | } 287 | res.text.should.be.exactly('success'); 288 | done(); 289 | }); 290 | }); 291 | 292 | it('shovel-set glance config return success', function (done) { 293 | var body = { httpHost: "localhost" }; 294 | request(url) 295 | .post('/api/1.1/shovel/glance/set-config') 296 | .send(body) 297 | .expect('Content-Type', /text/) 298 | .expect(200) 299 | .end(function (err, res) { 300 | if (err) { 301 | throw err; 302 | } 303 | res.text.should.be.exactly('success'); 304 | done(); 305 | }); 306 | }); 307 | 308 | it('shovel-set keystone config return success', function (done) { 309 | var body = { httpHost: "localhost" }; 310 | request(url) 311 | .post('/api/1.1/shovel/keystone/set-config') 312 | .send(body) 313 | .expect('Content-Type', /text/) 314 | .expect(200) 315 | .end(function (err, res) { 316 | if (err) { 317 | throw err; 318 | } 319 | res.text.should.be.exactly('success'); 320 | done(); 321 | }); 322 | }); 323 | 324 | it('/api/1.1/glance/images should return property name', function (done) { 325 | request(url) 326 | .get('/api/1.1/glance/images') 327 | .end(function (err, res) { 328 | if (err) { 329 | throw err; 330 | } 331 | JSON.parse(res.text).images[0].should.have.property('name'); 332 | done(); 333 | }); 334 | }); 335 | it('/api/1.1/deployos/ should return property definition', function (done) { 336 | request(url) 337 | .post('/api/1.1/deployos/123') 338 | .send({"name": "Graph.InstallCentOS","options": { "defaults": {"obmServiceName": "ipmi-obm-service"}}}) 339 | .end(function (err, res) { 340 | if (err) { 341 | throw err; 342 | } 343 | JSON.parse(res.text).should.have.property('definition'); 344 | done(); 345 | }); 346 | }); 347 | it('/api/1.1/worflow-status/{identifier} should return property jobStatus', function (done) { 348 | getWorkflow.returns(Promise.resolve('{"node":"123", "_status": "valid"}')) 349 | request(url) 350 | .get('/api/1.1/worflow-status/123') 351 | .end(function (err, res) { 352 | if (err) { 353 | throw err; 354 | } 355 | JSON.parse(res.text).should.have.property('jobStatus'); 356 | done(); 357 | }); 358 | }); 359 | it('/api/1.1/run/ansible-playbook/{id} should return property definition', function (done) { 360 | request(url) 361 | .post('/api/1.1/run/ansible-playbook/123') 362 | .send({"name": "Graph.Example","options": {}}) 363 | .end(function (err, res) { 364 | if (err) { 365 | throw err; 366 | } 367 | JSON.parse(res.text).should.have.property('definition'); 368 | done(); 369 | }); 370 | }); 371 | it('/api/1.1/worflow-status/{identifier} should return property jobStatus even if no job is running', function (done) { 372 | getWorkflow.returns(Promise.resolve()); 373 | request(url) 374 | .get('/api/1.1/worflow-status/123') 375 | .end(function (err, res) { 376 | if (err) { 377 | throw err; 378 | } 379 | JSON.parse(res.text).should.have.property('jobStatus'); 380 | done(); 381 | }); 382 | }); 383 | 384 | }); 385 | 386 | describe('Shovel error handling test', function () { 387 | var client = require('./../../lib/api/client'); 388 | Promise.promisifyAll(client); 389 | var body = { "id": identifier, "driver": "string", "ipmihost": "string", "ipmiusername": "string", "ipmipasswd": "string" }; 390 | before('set up mocks', function () { 391 | //set client to return an error 392 | var output = ({ error: 'error_message' }); 393 | sinon.stub(client, 'GetAsync').returns(Promise.reject(output)); 394 | sinon.stub(client, 'PostAsync').returns(Promise.reject(output)); 395 | sinon.stub(client, 'PutAsync').returns(Promise.reject(output)); 396 | }); 397 | after('teardown mocks', function () { 398 | client['GetAsync'].restore(); 399 | client['PostAsync'].restore(); 400 | client['PutAsync'].restore(); 401 | }); 402 | 403 | it('/api/1.1/nodes/identifier should return error message', function (done) { 404 | request(url) 405 | .get('/api/1.1/nodes/' + identifier) 406 | .end(function (err, res) { 407 | if (err) { 408 | throw err; 409 | } 410 | JSON.parse(res.text).should.have.property('error'); 411 | done(); 412 | }); 413 | }); 414 | it('/api/1.1/nodes/catalogs/identifier should return error message', function (done) { 415 | request(url) 416 | .get('/api/1.1/catalogs/' + identifier) 417 | .end(function (err, res) { 418 | if (err) { 419 | throw err; 420 | } 421 | JSON.parse(res.text).should.have.property('error'); 422 | done(); 423 | }); 424 | }); 425 | it('/catalogs/{identifier}/{source} should return error message', function (done) { 426 | request(url) 427 | .get('/api/1.1/catalogs/123/bmc') 428 | .end(function (err, res) { 429 | if (err) { 430 | throw err; 431 | } 432 | JSON.parse(res.text).should.have.property('error'); 433 | done(); 434 | }); 435 | }); 436 | it('/nodes/{identifier} should return error message', function (done) { 437 | request(url) 438 | .get('/api/1.1/nodes/123') 439 | .end(function (err, res) { 440 | if (err) { 441 | throw err; 442 | } 443 | JSON.parse(res.text).should.have.property('error'); 444 | done(); 445 | }); 446 | }); 447 | it('/api/1.1/nodes/123/sel should return error message', function (done) { 448 | request(url) 449 | .get('/api/1.1/nodes/123/sel') 450 | .end(function (err, res) { 451 | if (err) { 452 | throw err; 453 | } 454 | JSON.parse(res.text).should.have.property('error'); 455 | done(); 456 | }); 457 | }); 458 | it('/api/1.1/ironic/nodes should return error message', function (done) { 459 | request(url) 460 | .get('/api/1.1/ironic/nodes') 461 | .end(function (err, res) { 462 | if (err) { 463 | throw err; 464 | } 465 | JSON.parse(res.text).should.have.property('error'); 466 | done(); 467 | }); 468 | }); 469 | it('/api/1.1/ironic/chassis/123 should return error message', function (done) { 470 | request(url) 471 | .get('/api/1.1/ironic/chassis/123') 472 | .end(function (err, res) { 473 | if (err) { 474 | throw err; 475 | } 476 | JSON.parse(res.text).should.have.property('error'); 477 | done(); 478 | }); 479 | }); 480 | it('/api/1.1/ironic/nodes/123 should return error message', function (done) { 481 | request(url) 482 | .get('/api/1.1/ironic/nodes/123') 483 | .end(function (err, res) { 484 | if (err) { 485 | throw err; 486 | } 487 | JSON.parse(res.text).should.have.property('error'); 488 | done(); 489 | }); 490 | }); 491 | it('/api/1.1/ironic/drivers should return error message', function (done) { 492 | request(url) 493 | .get('/api/1.1/ironic/drivers') 494 | .end(function (err, res) { 495 | if (err) { 496 | throw err; 497 | } 498 | JSON.parse(res.text).should.have.property('error'); 499 | done(); 500 | }); 501 | }); 502 | it('/api/1.1/glance/images should return error message', function (done) { 503 | request(url) 504 | .get('/api/1.1/glance/images') 505 | .end(function (err, res) { 506 | if (err) { 507 | throw err; 508 | } 509 | JSON.parse(res.text).should.have.property('error'); 510 | done(); 511 | }); 512 | }); 513 | it('/api/1.1/register should have property error when cant connect to server', function (done) { 514 | request(url) 515 | .post('/api/1.1/register') 516 | .send(body) 517 | .expect('Content-Type', /json/) 518 | .expect(500) 519 | .end(function (err, res) { 520 | if (err) { 521 | throw err; 522 | } 523 | JSON.parse(res.text).should.have.property('error'); 524 | done(); 525 | }); 526 | }); 527 | it('/api/1.1/unregister/ should fail if no connection to server', function (done) { 528 | request(url) 529 | .delete('/api/1.1/unregister/123') 530 | .end(function (err, res) { 531 | if (err) { 532 | throw err; 533 | } 534 | JSON.parse(res.text).should.have.property('error'); 535 | done(); 536 | }); 537 | }); 538 | it('/ironic/node/{identifier} should return error message', function (done) { 539 | request(url) 540 | .patch('/api/1.1/ironic/node/123') 541 | .send([{}]) 542 | .expect(500) 543 | .end(function (err, res) { 544 | if (err) { 545 | throw err; 546 | } 547 | JSON.parse(res.text).should.have.property('error'); 548 | done(); 549 | }); 550 | }); 551 | it('/deployos/{identifier} should return error message', function (done) { 552 | request(url) 553 | .post('/api/1.1/deployos/123') 554 | .send([{}]) 555 | .expect(500) 556 | .end(function (err, res) { 557 | if (err) { 558 | throw err; 559 | } 560 | JSON.parse(res.text).should.have.property('error'); 561 | done(); 562 | }); 563 | }); 564 | it('/worflow-status/{identifier} should return error message', function (done) { 565 | request(url) 566 | .get('/api/1.1/worflow-status/123') 567 | .expect(500) 568 | .end(function (err, res) { 569 | if (err) { 570 | throw err; 571 | } 572 | JSON.parse(res.text).should.have.property('error'); 573 | done(); 574 | }); 575 | }); 576 | it('api/1.1/run/ansible-playbook/{id} should return error message', function (done) { 577 | request(url) 578 | .post('/api/1.1/run/ansible-playbook/123') 579 | .send({name: 'runExample',vars: {}, 580 | playbookPath: 'main.yml' 581 | }) 582 | .expect(500) 583 | .end(function (err, res) { 584 | if (err) { 585 | throw err; 586 | } 587 | JSON.parse(res.text).should.have.property('error'); 588 | done(); 589 | }); 590 | }); 591 | }); 592 | 593 | describe('Shovel api unit test for register', function () { 594 | var error_message = '{"error_message": "{\\"debuginfo\\": null, \\"faultcode\\": \\"Client\\", \\"faultstring\\": \\"some error\\"}"}'; 595 | var body = { "id": identifier, "driver": "string", "ipmihost": "string", "ipmiusername": "string", "ipmipasswd": "string" }; 596 | var getNode, diskSize, memoryCpu, ironicNodeCreate, 597 | ironicCreatePort, ironicPowerState, ironicPatch; 598 | beforeEach('set up mocks', function () { 599 | //monorail 600 | getNode = sinon.stub(monorail, 'request_node_get'); 601 | diskSize = sinon.stub(monorail, 'nodeDiskSize'); 602 | memoryCpu = sinon.stub(monorail, 'getNodeMemoryCpu'); 603 | monorailWhiteList = sinon.stub(monorail,'request_whitelist_set'); 604 | //keystone 605 | sinon.stub(keystone, 'authenticatePassword').returns(Promise.resolve(JSON.stringify(keyToken))); 606 | //ironic 607 | ironicNodeCreate = sinon.stub(ironic, 'create_node'); 608 | ironicCreatePort = sinon.stub(ironic,'create_port'); 609 | ironicPowerState = sinon.stub(ironic,'set_power_state'); 610 | ironicPatch = sinon.stub(ironic, 'patch_node'); 611 | }); 612 | afterEach('teardown mocks', function () { 613 | //monorail 614 | monorail['nodeDiskSize'].restore(); 615 | monorail['getNodeMemoryCpu'].restore(); 616 | monorail['request_node_get'].restore(); 617 | monorail['request_whitelist_set'].restore(); 618 | //keystone 619 | keystone['authenticatePassword'].restore(); 620 | //ironic 621 | ironic['create_node'].restore(); 622 | ironic['create_port'].restore(); 623 | ironic['set_power_state'].restore(); 624 | ironic['patch_node'].restore(); 625 | }); 626 | it('response in register should have property error_message when node returns empty ', function (done) { 627 | getNode.returns(Promise.resolve('{}')); 628 | request(url) 629 | .post('/api/1.1/register') 630 | .send(body) 631 | .expect('Content-Type', /json/) 632 | .expect(500) 633 | .end(function (err, res) { 634 | if (err) { 635 | throw err; 636 | } 637 | JSON.parse(res.text).should.have.property('error_message'); 638 | done(); 639 | }); 640 | }); 641 | it('response in register should have property error_message when diskSize has an exception ', function (done) { 642 | var output = {error_message: { message: 'failed to get compute node Disk Size' }}; 643 | getNode.returns(Promise.resolve(JSON.stringify(rackhdNode[0]))); 644 | diskSize.returns(Promise.reject(output)); 645 | request(url) 646 | .post('/api/1.1/register') 647 | .send(body) 648 | .expect('Content-Type', /json/) 649 | .expect(500) 650 | .end(function (err, res) { 651 | if (err) { 652 | throw err; 653 | } 654 | JSON.parse(res.text).should.have.property('error_message'); 655 | done(); 656 | }); 657 | }); 658 | it('response in register should have property error_message when any of node info equal to 0 ', function (done) { 659 | getNode.returns(Promise.resolve(JSON.stringify(rackhdNode[0]))); 660 | diskSize.returns(Promise.resolve(0)); 661 | memoryCpu.returns(Promise.resolve({ cpus: 0, memory: 0 })); 662 | 663 | request(url) 664 | .post('/api/1.1/register') 665 | .send(body) 666 | .expect('Content-Type', /json/) 667 | .expect(500) 668 | .end(function (err, res) { 669 | if (err) { 670 | throw err; 671 | } 672 | JSON.parse(res.text).should.have.property('error_message'); 673 | done(); 674 | }); 675 | }); 676 | it('response in register should have property error_message create node return error in ironic', function (done) { 677 | getNode.returns(Promise.resolve(JSON.stringify(rackhdNode[0]))); 678 | diskSize.returns(Promise.resolve(1)); 679 | memoryCpu.returns(Promise.resolve({ cpus: 1, memory: 1 })); 680 | ironicNodeCreate.returns(Promise.resolve(error_message)); 681 | request(url) 682 | .post('/api/1.1/register') 683 | .send(body) 684 | .expect('Content-Type', /json/) 685 | .expect(500) 686 | .end(function (err, res) { 687 | if (err) { 688 | throw err; 689 | } 690 | JSON.parse(res.text).should.have.property('error_message'); 691 | done(); 692 | }); 693 | }); 694 | it('response in register should have property error_message create port return error in ironic', function (done) { 695 | getNode.returns(Promise.resolve(JSON.stringify(rackhdNode[0]))); 696 | diskSize.returns(Promise.resolve(1)); 697 | memoryCpu.returns(Promise.resolve({ cpus: 1, memory: 1 })); 698 | ironicNodeCreate.returns(Promise.resolve(JSON.stringify(ironic_node_list[0]))); 699 | ironicCreatePort.returns(Promise.resolve(error_message)); 700 | request(url) 701 | .post('/api/1.1/register') 702 | .send(body) 703 | .expect('Content-Type', /json/) 704 | .expect(500) 705 | .end(function (err, res) { 706 | if (err) { 707 | throw err; 708 | } 709 | JSON.parse(res.text).should.have.property('error_message'); 710 | done(); 711 | }); 712 | }); 713 | it('response in register should have property error_message set power state return error in ironic', function (done) { 714 | getNode.returns(Promise.resolve(JSON.stringify(rackhdNode[0]))); 715 | diskSize.returns(Promise.resolve(1)); 716 | memoryCpu.returns(Promise.resolve({ cpus: 1, memory: 1 })); 717 | ironicNodeCreate.returns(Promise.resolve(JSON.stringify(ironic_node_list[0]))); 718 | ironicCreatePort.returns(Promise.resolve()); 719 | ironicPowerState.returns(Promise.resolve(error_message)); 720 | request(url) 721 | .post('/api/1.1/register') 722 | .send(body) 723 | .expect('Content-Type', /json/) 724 | .expect(500) 725 | .end(function (err, res) { 726 | if (err) { 727 | throw err; 728 | } 729 | JSON.parse(res.text).should.have.property('error_message'); 730 | done(); 731 | }); 732 | }); 733 | it('response in register should have property error_message ironic patch node return error in ironic', function (done) { 734 | getNode.returns(Promise.resolve(JSON.stringify(rackhdNode[0]))); 735 | diskSize.returns(Promise.resolve(1)); 736 | memoryCpu.returns(Promise.resolve({ cpus: 1, memory: 1 })); 737 | ironicNodeCreate.returns(Promise.resolve(JSON.stringify(ironic_node_list[0]))); 738 | ironicCreatePort.returns(Promise.resolve()); 739 | ironicPowerState.returns(Promise.resolve()); 740 | ironicPatch.returns(Promise.reject({error_message:'some error'})); 741 | request(url) 742 | .post('/api/1.1/register') 743 | .send(body) 744 | .expect('Content-Type', /json/) 745 | .expect(500) 746 | .end(function (err, res) { 747 | if (err) { 748 | throw err; 749 | } 750 | JSON.parse(res.text).should.have.property('error_message'); 751 | done(); 752 | }); 753 | }); 754 | it('response in register should have property result on success', function (done) { 755 | getNode.returns(Promise.resolve(JSON.stringify(rackhdNode[0]))); 756 | diskSize.returns(Promise.resolve(1)); 757 | memoryCpu.returns(Promise.resolve({ cpus: 1, memory: 1 })); 758 | ironicNodeCreate.returns(Promise.resolve(JSON.stringify(ironic_node_list[0]))); 759 | ironicCreatePort.returns(Promise.resolve()); 760 | ironicPowerState.returns(Promise.resolve()); 761 | ironicPatch.returns(Promise.resolve()); 762 | request(url) 763 | .post('/api/1.1/register') 764 | .send(body) 765 | .expect('Content-Type', /json/) 766 | .expect(200) 767 | .end(function (err, res) { 768 | if (err) { 769 | throw err; 770 | } 771 | JSON.parse(res.text).should.have.property('result'); 772 | done(); 773 | }); 774 | }); 775 | }); 776 | }); 777 | --------------------------------------------------------------------------------