Merge pull request #9 from keedya/adopt_eslint_openstack
Adopt eslint openstack
This commit is contained in:
commit
b79a6b7469
25
Shovel/.eslintrc.js
Normal file
25
Shovel/.eslintrc.js
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
"rules": {
|
||||
"indent": [
|
||||
2,
|
||||
4
|
||||
],
|
||||
"quotes": [
|
||||
2,
|
||||
"single"
|
||||
],
|
||||
"linebreak-style": [
|
||||
2,
|
||||
"unix"
|
||||
],
|
||||
"semi": [
|
||||
2,
|
||||
"always"
|
||||
]
|
||||
},
|
||||
"env": {
|
||||
"es6": true,
|
||||
"browser": true
|
||||
},
|
||||
"extends": "openstack"
|
||||
};
|
@ -1,8 +1,6 @@
|
||||
// Copyright 2015, EMC, Inc.
|
||||
/*eslint-env node*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var url = require('url');
|
||||
var monorail = require('./../lib/api/monorail/monorail');
|
||||
var ironic = require('./../lib/api/openstack/ironic');
|
||||
var config = require('./../config.json');
|
||||
@ -21,12 +19,13 @@ var glanceConfig = config.glance;
|
||||
* @apiDescription get shovel information
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.infoGet = function infoGet(req, res, next) {
|
||||
module.exports.infoGet = function infoGet(req, res) {
|
||||
'use strict';
|
||||
var info = {
|
||||
name: 'shovel',
|
||||
description: 'onrack-ironic agent',
|
||||
appversion: config.appver,
|
||||
apiversion: config.apiver
|
||||
description: 'rackHD-ironic agent',
|
||||
appversion: config.shovel.appver,
|
||||
apiversion: config.shovel.apiver
|
||||
};
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(info));
|
||||
@ -37,7 +36,8 @@ module.exports.infoGet = function infoGet(req, res, next) {
|
||||
* @apiDescription get ironic drivers
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.driversGet = function driversGet(req, res, next) {
|
||||
module.exports.driversGet = function driversGet(req, res) {
|
||||
'use strict';
|
||||
return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username,
|
||||
ironicConfig.os_password).
|
||||
then(function (token) {
|
||||
@ -60,7 +60,8 @@ module.exports.driversGet = function driversGet(req, res, next) {
|
||||
* @apiDescription get ironic nodes
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.ironicnodesGet = function ironicnodesGet(req, res, next) {
|
||||
module.exports.ironicnodesGet = function ironicnodesGet(req, res) {
|
||||
'use strict';
|
||||
return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username,
|
||||
ironicConfig.os_password).
|
||||
then(function (token) {
|
||||
@ -83,7 +84,8 @@ module.exports.ironicnodesGet = function ironicnodesGet(req, res, next) {
|
||||
* @apiDescription get ironic chassis
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.ironicchassisGet = function ironicchassisGet(req, res, next) {
|
||||
module.exports.ironicchassisGet = function ironicchassisGet(req, res) {
|
||||
'use strict';
|
||||
return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username,
|
||||
ironicConfig.os_password).
|
||||
then(function (token) {
|
||||
@ -106,7 +108,8 @@ module.exports.ironicchassisGet = function ironicchassisGet(req, res, next) {
|
||||
* @apiDescription get ironic node
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.ironicnodeGet = function ironicnodeGet(req, res, next) {
|
||||
module.exports.ironicnodeGet = function ironicnodeGet(req, res) {
|
||||
'use strict';
|
||||
return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username,
|
||||
ironicConfig.os_password).
|
||||
then(function (token) {
|
||||
@ -129,7 +132,8 @@ module.exports.ironicnodeGet = function ironicnodeGet(req, res, next) {
|
||||
* @apiDescription patch ironic node info
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.ironicnodePatch = function ironicnodePatch(req, res, next) {
|
||||
module.exports.ironicnodePatch = function ironicnodePatch(req, res) {
|
||||
'use strict';
|
||||
return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username,
|
||||
ironicConfig.os_password).
|
||||
then(function (token) {
|
||||
@ -153,7 +157,8 @@ module.exports.ironicnodePatch = function ironicnodePatch(req, res, next) {
|
||||
* @apiDescription get catalogs
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.catalogsGet = function catalogsGet(req, res, next) {
|
||||
module.exports.catalogsGet = function catalogsGet(req, res) {
|
||||
'use strict';
|
||||
return monorail.request_catalogs_get(req.swagger.params.identifier.value).
|
||||
then(function (catalogs) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
@ -171,7 +176,8 @@ module.exports.catalogsGet = function catalogsGet(req, res, next) {
|
||||
* @apiDescription get catalogs by source
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.catalogsbysourceGet = function catalogsbysourceGet(req, res, next) {
|
||||
module.exports.catalogsbysourceGet = function catalogsbysourceGet(req, res) {
|
||||
'use strict';
|
||||
return monorail.get_catalog_data_by_source(req.swagger.params.identifier.value,
|
||||
req.swagger.params.source.value).
|
||||
then(function (catalogs) {
|
||||
@ -190,7 +196,8 @@ module.exports.catalogsbysourceGet = function catalogsbysourceGet(req, res, next
|
||||
* @apiDescription get specific node by id
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.nodeGet = function nodeGet(req, res, next) {
|
||||
module.exports.nodeGet = function nodeGet(req, res) {
|
||||
'use strict';
|
||||
return monorail.request_node_get(req.swagger.params.identifier.value).
|
||||
then(function (node) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
@ -208,7 +215,8 @@ module.exports.nodeGet = function nodeGet(req, res, next) {
|
||||
* @apiDescription get list of monorail nodes
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.nodesGet = function nodesGet(req, res, next) {
|
||||
module.exports.nodesGet = function nodesGet(req, res) {
|
||||
'use strict';
|
||||
return monorail.request_nodes_get().
|
||||
then(function (nodes) {
|
||||
Promise.filter(JSON.parse(nodes), function (node) {
|
||||
@ -231,19 +239,24 @@ module.exports.nodesGet = function nodesGet(req, res, next) {
|
||||
* @apiDescription get specific node by id
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.getSeldata = function getSeldata(req, res, next) {
|
||||
module.exports.getSeldata = function getSeldata(req, res,next) {
|
||||
'use strict';
|
||||
return monorail.request_poller_get(req.swagger.params.identifier.value).
|
||||
then(function (pollers) {
|
||||
pollers = JSON.parse(pollers);
|
||||
for (var i in pollers) {
|
||||
if (pollers[i]['config']['command'] === 'sel') {
|
||||
return monorail.request_poller_data_get(pollers[i]['id']).
|
||||
then(function (data) {
|
||||
return Promise.filter(pollers, function (poller) {
|
||||
return poller.config.command === 'sel';
|
||||
})
|
||||
.then(function (sel) {
|
||||
if (sel.length > 0) {
|
||||
return monorail.request_poller_data_get(sel[0].id)
|
||||
.then(function (data) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
next();
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
logger.error({ message: err, path: req.url });
|
||||
@ -257,46 +270,58 @@ module.exports.getSeldata = function getSeldata(req, res, next) {
|
||||
* @apiDescription register a node in Ironic
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.registerpost = function registerpost(req, res, next) {
|
||||
var info = {};
|
||||
var node = {};
|
||||
var propreties = {};
|
||||
var local_gb;
|
||||
var extra = {};
|
||||
var port = {}
|
||||
var ironicToken;
|
||||
var ironic_node;
|
||||
var onrack_node;
|
||||
var user_entry = req.body;
|
||||
if (user_entry.driver == 'pxe_ipmitool') {
|
||||
info = { 'ipmi_address': user_entry.ipmihost, 'ipmi_username': user_entry.ipmiuser, 'ipmi_password': user_entry.ipmipass, 'deploy_kernel': user_entry.kernel, 'deploy_ramdisk': user_entry.ramdisk };
|
||||
}
|
||||
else if (user_entry.driver == 'pxe_ssh') {
|
||||
info = { 'ssh_address': user_entry.sshhost, 'ssh_username': user_entry.sshuser, 'ssh_password': user_entry.sshpass, 'ssh_port': user_entry.sshport, 'deploy_kernel': user_entry.kernel, 'deploy_ramdisk': user_entry.ramdisk };
|
||||
}
|
||||
else {
|
||||
module.exports.registerpost = function registerpost(req, res) {
|
||||
'use strict';
|
||||
var localGb, ironicToken, ironicNode, extra, port, propreties, node, info, userEntry;
|
||||
//init
|
||||
extra = port = propreties = node = info = {};
|
||||
userEntry = req.body;
|
||||
if (userEntry.driver === 'pxe_ipmitool') {
|
||||
info = {
|
||||
'ipmi_address': userEntry.ipmihost,
|
||||
'ipmi_username': userEntry.ipmiuser,
|
||||
'ipmi_password': userEntry.ipmipass,
|
||||
'deploy_kernel': userEntry.kernel,
|
||||
'deploy_ramdisk': userEntry.ramdisk
|
||||
};
|
||||
} else if (userEntry.driver === 'pxe_ssh') {
|
||||
info = {
|
||||
'ssh_address': userEntry.sshhost,
|
||||
'ssh_username': userEntry.sshuser,
|
||||
'ssh_password': userEntry.sshpass,
|
||||
'ssh_port': userEntry.sshport,
|
||||
'deploy_kernel': userEntry.kernel,
|
||||
'deploy_ramdisk': userEntry.ramdisk
|
||||
};
|
||||
} else {
|
||||
info = {};
|
||||
}
|
||||
|
||||
/* Fill in the extra meta data with some failover and event data */
|
||||
extra = { 'nodeid': user_entry.uuid, 'name': user_entry.name, 'lsevents': { 'time': 0 }, 'eventcnt': 0, 'timer': {} };
|
||||
if (typeof user_entry.failovernode !== 'undefined') {
|
||||
extra['failover'] = user_entry.failovernode;
|
||||
extra = {
|
||||
'nodeid': userEntry.uuid,
|
||||
'name': userEntry.name,
|
||||
'lsevents': { 'time': 0 },
|
||||
'eventcnt': 0,
|
||||
'timer': {}
|
||||
};
|
||||
if (typeof userEntry.failovernode !== 'undefined') {
|
||||
extra.failover = userEntry.failovernode;
|
||||
}
|
||||
if (typeof user_entry.eventre !== 'undefined') {
|
||||
extra['eventre'] = user_entry.eventre;
|
||||
if (typeof userEntry.eventre !== 'undefined') {
|
||||
extra.eventre = userEntry.eventre;
|
||||
}
|
||||
|
||||
local_gb = 0.0;
|
||||
return monorail.request_node_get(user_entry.uuid).
|
||||
localGb = 0.0;
|
||||
return monorail.request_node_get(userEntry.uuid).
|
||||
then(function (result) {
|
||||
if (!JSON.parse(result).name) {
|
||||
var error = { error_message: { message: 'failed to find required node in RackHD' } };
|
||||
logger.error(err);
|
||||
logger.error(error);
|
||||
throw error;
|
||||
}
|
||||
onrack_node = JSON.parse(result);
|
||||
return monorail.nodeDiskSize(onrack_node)
|
||||
ironicNode = JSON.parse(result);
|
||||
return monorail.nodeDiskSize(ironicNode)
|
||||
.catch(function (err) {
|
||||
var error = { error_message: { message: 'failed to get compute node Disk Size' } };
|
||||
logger.error(err);
|
||||
@ -304,32 +329,39 @@ module.exports.registerpost = function registerpost(req, res, next) {
|
||||
|
||||
});
|
||||
}).then(function (localDisk) {
|
||||
local_gb = localDisk;
|
||||
return monorail.get_node_memory_cpu(onrack_node)
|
||||
localGb = localDisk;
|
||||
return monorail.getNodeMemoryCpu(ironicNode)
|
||||
.catch(function (err) {
|
||||
var error = { error_message: { message: 'failed to get compute node memory size' } };
|
||||
logger.error(err);
|
||||
throw error;
|
||||
});
|
||||
}).then(function (dmiData) {
|
||||
if (local_gb == 0 || dmiData.cpus == 0 || dmiData.memory == 0) {
|
||||
var error = { error_message: { message: 'failed to get compute node data', nodeDisk: local_gb, memorySize: dmiData.memory, cpuCount: dmiData.cpus } };
|
||||
throw (error);
|
||||
if (localGb === 0 || dmiData.cpus === 0 || dmiData.memory === 0) {
|
||||
var error = {
|
||||
error_message: {
|
||||
message: 'failed to get compute node data',
|
||||
nodeDisk: localGb,
|
||||
memorySize: dmiData.memory,
|
||||
cpuCount: dmiData.cpus
|
||||
}
|
||||
};
|
||||
throw error;
|
||||
}
|
||||
propreties = {
|
||||
'cpus': dmiData.cpus,
|
||||
'memory_mb': dmiData.memory,
|
||||
'local_gb': local_gb
|
||||
'local_gb': localGb
|
||||
};
|
||||
node = {
|
||||
'name': user_entry.uuid,
|
||||
'driver': user_entry.driver,
|
||||
'name': userEntry.uuid,
|
||||
'driver': userEntry.driver,
|
||||
'driver_info': info,
|
||||
'properties': propreties,
|
||||
'extra': extra
|
||||
};
|
||||
return (keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username,
|
||||
ironicConfig.os_password));
|
||||
return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username,
|
||||
ironicConfig.os_password);
|
||||
}).
|
||||
then(function (token) {
|
||||
ironicToken = JSON.parse(token).access.token.id;
|
||||
@ -338,20 +370,20 @@ module.exports.registerpost = function registerpost(req, res, next) {
|
||||
then(function (ret) {
|
||||
logger.debug('\r\ncreate node:\r\n' + ret);
|
||||
if (ret && JSON.parse(ret).error_message) {
|
||||
throw (JSON.parse(ret));
|
||||
throw JSON.parse(ret);
|
||||
}
|
||||
ironic_node = JSON.parse(ret);
|
||||
port = { 'address': user_entry.port, 'node_uuid': ironic_node.uuid };
|
||||
return ironic.create_port(ironicToken, JSON.stringify(port));
|
||||
ironicNode = JSON.parse(ret);
|
||||
port = { 'address': userEntry.port, 'node_uuid': ironicNode.uuid };
|
||||
return ironic.createPort(ironicToken, JSON.stringify(port));
|
||||
}).
|
||||
then(function (create_port) {
|
||||
logger.info('\r\nCreate port:\r\n' + JSON.stringify(create_port));
|
||||
return ironic.set_power_state(ironicToken, ironic_node.uuid, "on");
|
||||
then(function (createPort) {
|
||||
logger.info('\r\nCreate port:\r\n' + JSON.stringify(createPort));
|
||||
return ironic.set_power_state(ironicToken, ironicNode.uuid, 'on');
|
||||
}).
|
||||
then(function (pwr_state) {
|
||||
logger.info('\r\npwr_state: on');
|
||||
if (pwr_state && JSON.parse(pwr_state).error_message) {
|
||||
throw (JSON.parse(pwr_state));
|
||||
then(function (pwrState) {
|
||||
logger.info('\r\npwrState: on');
|
||||
if (pwrState && JSON.parse(pwrState).error_message) {
|
||||
throw JSON.parse(pwrState);
|
||||
}
|
||||
}).then(function () {
|
||||
var timer = {};
|
||||
@ -361,20 +393,20 @@ module.exports.registerpost = function registerpost(req, res, next) {
|
||||
timer.timeInterval = 15000;
|
||||
timer.isDone = true;
|
||||
var data = [{ 'path': '/extra/timer', 'value': timer, 'op': 'replace' }];
|
||||
return ironic.patch_node(ironicToken, ironic_node.uuid, JSON.stringify(data));
|
||||
return ironic.patch_node(ironicToken, ironicNode.uuid, JSON.stringify(data));
|
||||
}).
|
||||
then(function (result) {
|
||||
logger.info('\r\patched node:\r\n' + result);
|
||||
}).
|
||||
then(function () {
|
||||
_.each(onrack_node.identifiers, function (mac) {
|
||||
_.each(ironicNode.identifiers, function (mac) {
|
||||
return monorail.request_whitelist_set(mac)
|
||||
.then(function (whitelist) {
|
||||
logger.info('\r\nmonorail whitelist:\r\n' + JSON.stringify(whitelist));
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(function (whitelist) {
|
||||
.then(function () {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
var success = {
|
||||
result: 'success'
|
||||
@ -392,21 +424,22 @@ module.exports.registerpost = function registerpost(req, res, next) {
|
||||
* @apiDescription unregister a node from Ironic
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.unregisterdel = function unregisterdel(req, res, next) {
|
||||
module.exports.unregisterdel = function unregisterdel(req, res) {
|
||||
'use strict';
|
||||
var ironicToken;
|
||||
//TODO allow using name or ironic node uuid
|
||||
return keystone.authenticatePassword(ironicConfig.os_tenant_name, ironicConfig.os_username,
|
||||
ironicConfig.os_password).
|
||||
then(function (token) {
|
||||
ironicToken = JSON.parse(token).access.token.id;
|
||||
return ironic.delete_node(ironicToken, req.swagger.params.identifier.value);
|
||||
})
|
||||
.then(function (del_node) {
|
||||
if (del_node && JSON.parse(del_node).error_message) {
|
||||
throw (del_node);
|
||||
}
|
||||
else {
|
||||
logger.info('ironicNode: ' + req.swagger.params.identifier.value + ' is been deleted susccessfully');
|
||||
.then(function (delNode) {
|
||||
if (delNode && JSON.parse(delNode).error_message) {
|
||||
throw delNode;
|
||||
} else {
|
||||
logger.info('ironicNode: ' +
|
||||
req.swagger.params.identifier.value +
|
||||
' is been deleted susccessfully');
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
var success = {
|
||||
result: 'success'
|
||||
@ -433,14 +466,14 @@ module.exports.unregisterdel = function unregisterdel(req, res, next) {
|
||||
* @apiDescription modify shovel config.json file and restart the server
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.configsetmono = function configsetmono(req, res, next) {
|
||||
module.exports.configsetmono = function configsetmono(req, res) {
|
||||
'use strict';
|
||||
res.setHeader('content-type', 'text/plain');
|
||||
if (setConfig('monorail', req.body)) {
|
||||
res.end('success');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
res.end('failed to update monorail config');
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -448,14 +481,14 @@ module.exports.configsetmono = function configsetmono(req, res, next) {
|
||||
* @apiDescription modify shovel config.json file and restart the server
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.configsetkeystone = function configsetkeystone(req, res, next) {
|
||||
module.exports.configsetkeystone = function configsetkeystone(req, res) {
|
||||
'use strict';
|
||||
res.setHeader('content-type', 'text/plain');
|
||||
if (setConfig('keystone', req.body)) {
|
||||
res.end('success');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
res.end('failed to update keystone config');
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -463,25 +496,24 @@ module.exports.configsetkeystone = function configsetkeystone(req, res, next) {
|
||||
* @apiDescription modify shovel config.json file and restart the server
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.configsetironic = function configsetironic(req, res, next) {
|
||||
module.exports.configsetironic = function configsetironic(req, res) {
|
||||
'use strict';
|
||||
res.setHeader('content-type', 'text/plain');
|
||||
if (req.body.hasOwnProperty('os_password')) {
|
||||
var password = req.body.os_password;
|
||||
//replace password with encrypted value
|
||||
try {
|
||||
req.body.os_password = encryption.encrypt(password);
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
res.end('failed to update ironic config');
|
||||
}
|
||||
}
|
||||
if (setConfig('ironic', req.body)) {
|
||||
res.end('success');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
res.end('failed to update ironic config');
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -489,25 +521,24 @@ module.exports.configsetironic = function configsetironic(req, res, next) {
|
||||
* @apiDescription modify shovel config.json file and restart the server
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.configsetglance = function configsetglance(req, res, next) {
|
||||
module.exports.configsetglance = function configsetglance(req, res) {
|
||||
'use strict';
|
||||
res.setHeader('content-type', 'text/plain');
|
||||
if (req.body.hasOwnProperty('os_password')) {
|
||||
var password = req.body.os_password;
|
||||
//replace password with encrypted value
|
||||
try {
|
||||
req.body.os_password = encryption.encrypt(password);
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
res.end('failed to update ironic config');
|
||||
}
|
||||
}
|
||||
if (setConfig('glance', req.body)) {
|
||||
res.end('success');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
res.end('failed to update glance config');
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -515,32 +546,32 @@ module.exports.configsetglance = function configsetglance(req, res, next) {
|
||||
* @apiDescription modify shovel config.json file and restart the server
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.configset = function configset(req, res, next) {
|
||||
module.exports.configset = function configset(req, res) {
|
||||
'use strict';
|
||||
res.setHeader('content-type', 'text/plain');
|
||||
if (setConfig('shovel', req.body) == true) {
|
||||
if (setConfig('shovel', req.body) === true) {
|
||||
res.end('success');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
res.end('failed to update shovel config');
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
function setConfig(keyValue, entry) {
|
||||
'use strict';
|
||||
var filename = 'config.json';
|
||||
jsonfile.readFile(filename, function (err, output) {
|
||||
jsonfile.readFile(filename, function (error, output) {
|
||||
try {
|
||||
var content = (keyValue == null) ? output : output[keyValue];
|
||||
var content = keyValue === null ? output : output[keyValue];
|
||||
var filteredList = _.pick(content, Object.keys(entry));
|
||||
_.each(Object.keys(filteredList), function (key) {
|
||||
content[key] = entry[key];
|
||||
|
||||
});
|
||||
output[keyValue] = content;
|
||||
jsonfile.writeFile(filename, output, { spaces: 2 }, function (err) {
|
||||
jsonfile.writeFile(filename, output, { spaces: 2 }, function () {
|
||||
logger.debug(content);
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
return false;
|
||||
}
|
||||
@ -553,25 +584,25 @@ function setConfig(keyValue, entry) {
|
||||
* @apiDescription get shovel config.json file and restart the server
|
||||
* @apiVersion 1.1.0
|
||||
*/
|
||||
module.exports.configget = function configget(req, res, next) {
|
||||
module.exports.configget = function configget(req, res) {
|
||||
'use strict';
|
||||
var filename = 'config.json';
|
||||
jsonfile.readFile(filename, function (err, content) {
|
||||
jsonfile.readFile(filename, function (error,content) {
|
||||
try {
|
||||
delete content['key'];
|
||||
if (content.ironic.hasOwnProperty("os_password")) {
|
||||
delete content.key;
|
||||
if (content.ironic.hasOwnProperty('os_password')) {
|
||||
content.ironic.os_password = '[REDACTED]';
|
||||
}
|
||||
if (content.glance.hasOwnProperty("os_password")) {
|
||||
if (content.glance.hasOwnProperty('os_password')) {
|
||||
content.glance.os_password = '[REDACTED]';
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(content));
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
res.setHeader('content-type', 'text/plain');
|
||||
res.end('failed to get config');
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -579,7 +610,8 @@ module.exports.configget = function configget(req, res, next) {
|
||||
* @api {get} /api/1.1/glance/images / GET /
|
||||
* @apiDescription get glance images
|
||||
*/
|
||||
module.exports.imagesGet = function imagesGet(req, res, next) {
|
||||
module.exports.imagesGet = function imagesGet(req, res) {
|
||||
'use strict';
|
||||
return keystone.authenticatePassword(glanceConfig.os_tenant_name, glanceConfig.os_username,
|
||||
glanceConfig.os_password).
|
||||
then(function (token) {
|
||||
@ -595,4 +627,4 @@ module.exports.imagesGet = function imagesGet(req, res, next) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(err));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
@ -1,159 +1,162 @@
|
||||
// Copyright 2015, EMC, Inc.
|
||||
|
||||
/*eslint-env node*/
|
||||
|
||||
/* http client */
|
||||
var HttpClient = {
|
||||
Get: function( msg, output ) {
|
||||
Get: function (msg, output) {
|
||||
'use strict';
|
||||
var http = require('http');
|
||||
var options = {
|
||||
var options = {
|
||||
hostname: msg.host,
|
||||
path: msg.path,
|
||||
port: msg.port,
|
||||
method: 'GET',
|
||||
headers: {}
|
||||
};
|
||||
|
||||
if( Buffer.byteLength(msg.token) )
|
||||
{
|
||||
options.headers['X-Auth-Token'] = msg.token;
|
||||
};
|
||||
|
||||
cb = function( response ) {
|
||||
if (Buffer.byteLength(msg.token)) {
|
||||
options.headers['X-Auth-Token'] = msg.token;
|
||||
}
|
||||
|
||||
var cb = function (response) {
|
||||
var body = '';
|
||||
response.on('data', function(chunk) {
|
||||
response.on('data', function (chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
response.on('error', function (err) {
|
||||
var errorMessage = { errorMessage: { hostname: msg.host, message: err } };
|
||||
output(errorMessage);
|
||||
});
|
||||
response.on('end', function() {
|
||||
response.on('end', function () {
|
||||
output(null, body);
|
||||
});
|
||||
};
|
||||
|
||||
request = http.request(options, cb);
|
||||
request.on('error', function(e) {
|
||||
|
||||
var request = http.request(options, cb);
|
||||
request.on('error', function (e) {
|
||||
var errorMessage = { errorMessage: { hostname: msg.host, message: e } };
|
||||
output(errorMessage);
|
||||
});
|
||||
|
||||
|
||||
request.end();
|
||||
},
|
||||
Post: function (msg, output) {
|
||||
var http = require('http');
|
||||
var options = {
|
||||
'use strict';
|
||||
var http = require('http');
|
||||
var options = {
|
||||
hostname: msg.host,
|
||||
path: msg.path,
|
||||
port: msg.port,
|
||||
method: 'POST',
|
||||
headers: { 'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(msg.data),
|
||||
'User-Agent': 'shovel-client' }
|
||||
};
|
||||
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(msg.data),
|
||||
'User-Agent': 'shovel-client'
|
||||
}
|
||||
};
|
||||
|
||||
/*Update the request header with special fields*/
|
||||
if( Buffer.byteLength(msg.token) )
|
||||
{
|
||||
if (Buffer.byteLength(msg.token)) {
|
||||
options.headers['X-Auth-Token'] = msg.token;
|
||||
};
|
||||
if( Buffer.byteLength(JSON.stringify(msg.api)) )
|
||||
{
|
||||
}
|
||||
if (Buffer.byteLength(JSON.stringify(msg.api))) {
|
||||
options.headers[msg.api.name] = msg.api.version;
|
||||
};
|
||||
|
||||
cb = function( response ) {
|
||||
}
|
||||
|
||||
var cb = function (response) {
|
||||
var body = '';
|
||||
response.on('data', function(chunk) {
|
||||
response.on('data', function (chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
response.on('error', function (err) {
|
||||
response.on('error', function (e) {
|
||||
var errorMessage = { errorMessage: { hostname: msg.host, message: e } };
|
||||
output(errorMessage);
|
||||
});
|
||||
response.on('end', function() {
|
||||
output(null,body);
|
||||
});
|
||||
response.on('end', function () {
|
||||
output(null, body);
|
||||
});
|
||||
};
|
||||
|
||||
request = http.request(options, cb);
|
||||
request.on('error', function(e) {
|
||||
|
||||
var request = http.request(options, cb);
|
||||
request.on('error', function (e) {
|
||||
var errorMessage = { errorMessage: { hostname: msg.host, message: e } };
|
||||
output(errorMessage);
|
||||
});
|
||||
|
||||
if( Buffer.byteLength(msg.data) )
|
||||
{
|
||||
|
||||
if (Buffer.byteLength(msg.data)) {
|
||||
request.write(msg.data);
|
||||
};
|
||||
request.end();
|
||||
}
|
||||
request.end();
|
||||
},
|
||||
Delete: function( msg, output ) {
|
||||
Delete: function (msg, output) {
|
||||
'use strict';
|
||||
var http = require('http');
|
||||
var options = {
|
||||
var options = {
|
||||
hostname: msg.host,
|
||||
path: msg.path,
|
||||
port: msg.port,
|
||||
method: 'DELETE',
|
||||
headers: {}
|
||||
};
|
||||
|
||||
if( Buffer.byteLength(msg.token) )
|
||||
{
|
||||
};
|
||||
|
||||
if (Buffer.byteLength(msg.token)) {
|
||||
options.headers['X-Auth-Token'] = msg.token;
|
||||
};
|
||||
|
||||
if( Buffer.byteLength(JSON.stringify(msg.api)) )
|
||||
{
|
||||
}
|
||||
|
||||
if (Buffer.byteLength(JSON.stringify(msg.api))) {
|
||||
options.headers[msg.api.name] = msg.api.version;
|
||||
};
|
||||
|
||||
cb = function( response ) {
|
||||
}
|
||||
|
||||
var cb = function (response) {
|
||||
var body = '';
|
||||
response.on('data', function(chunk) {
|
||||
response.on('data', function (chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
response.on('error', function (err) {
|
||||
var errorMessage = { errorMessage: { hostname: msg.host, message: err } };
|
||||
output(errorMessage);
|
||||
});
|
||||
response.on('end', function() {
|
||||
output(null,body);
|
||||
response.on('end', function () {
|
||||
output(null, body);
|
||||
});
|
||||
};
|
||||
|
||||
request = http.request(options, cb);
|
||||
request.on('error', function(e) {
|
||||
|
||||
var request = http.request(options, cb);
|
||||
request.on('error', function (e) {
|
||||
var errorMessage = { errorMessage: { hostname: msg.host, message: e } };
|
||||
output(errorMessage);
|
||||
});
|
||||
|
||||
|
||||
request.end();
|
||||
},
|
||||
Put: function( msg, output ) {
|
||||
var http = require('http');
|
||||
var options = {
|
||||
Put: function (msg, output) {
|
||||
'use strict';
|
||||
var http = require('http');
|
||||
var options = {
|
||||
hostname: msg.host,
|
||||
path: msg.path,
|
||||
port: msg.port,
|
||||
method: 'PUT',
|
||||
headers: { 'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(msg.data),
|
||||
'User-Agent': 'shovel-client' }
|
||||
};
|
||||
|
||||
if( Buffer.byteLength(msg.token) )
|
||||
{
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(msg.data),
|
||||
'User-Agent': 'shovel-client'
|
||||
}
|
||||
};
|
||||
|
||||
if (Buffer.byteLength(msg.token)) {
|
||||
options.headers['X-Auth-Token'] = msg.token;
|
||||
};
|
||||
|
||||
if( Buffer.byteLength(JSON.stringify(msg.api)) )
|
||||
{
|
||||
}
|
||||
|
||||
if (Buffer.byteLength(JSON.stringify(msg.api))) {
|
||||
options.headers[msg.api.name] = msg.api.version;
|
||||
};
|
||||
|
||||
cb = function( response ) {
|
||||
}
|
||||
|
||||
var cb = function (response) {
|
||||
var body = '';
|
||||
response.on('data', function(chunk) {
|
||||
response.on('data', function (chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
response.on('error', function (err) {
|
||||
@ -164,42 +167,43 @@ var HttpClient = {
|
||||
output(null, body);
|
||||
});
|
||||
};
|
||||
|
||||
request = http.request(options, cb);
|
||||
request.on('error', function(e) {
|
||||
|
||||
var request = http.request(options, cb);
|
||||
request.on('error', function (e) {
|
||||
var errorMessage = { errorMessage: { hostname: msg.host, message: e } };
|
||||
output(errorMessage);
|
||||
});
|
||||
|
||||
|
||||
request.write(msg.data);
|
||||
request.end();
|
||||
request.end();
|
||||
},
|
||||
Patch: function (msg, output) {
|
||||
var http = require('http');
|
||||
var options = {
|
||||
'use strict';
|
||||
var http = require('http');
|
||||
var options = {
|
||||
hostname: msg.host,
|
||||
path: msg.path,
|
||||
port: msg.port,
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(msg.data),
|
||||
'User-Agent': 'shovel-client' }
|
||||
};
|
||||
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(msg.data),
|
||||
'User-Agent': 'shovel-client'
|
||||
}
|
||||
};
|
||||
|
||||
/*Update the request header with special fields*/
|
||||
if( Buffer.byteLength(msg.token) )
|
||||
{
|
||||
if (Buffer.byteLength(msg.token)) {
|
||||
options.headers['X-Auth-Token'] = msg.token;
|
||||
};
|
||||
if( Buffer.byteLength(JSON.stringify(msg.api)) )
|
||||
{
|
||||
}
|
||||
if (Buffer.byteLength(JSON.stringify(msg.api))) {
|
||||
options.headers[msg.api.name] = msg.api.version;
|
||||
};
|
||||
|
||||
cb = function( response ) {
|
||||
}
|
||||
|
||||
var cb = function (response) {
|
||||
var body = '';
|
||||
response.on('data', function(chunk) {
|
||||
response.on('data', function (chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
response.on('error', function (err) {
|
||||
@ -210,19 +214,18 @@ var HttpClient = {
|
||||
output(null, body);
|
||||
});
|
||||
};
|
||||
|
||||
request = http.request(options, cb);
|
||||
request.on('error', function(e) {
|
||||
|
||||
var request = http.request(options, cb);
|
||||
request.on('error', function (e) {
|
||||
var errorMessage = { errorMessage: { hostname: msg.host, message: e } };
|
||||
output(errorMessage);
|
||||
});
|
||||
|
||||
if( Buffer.byteLength(msg.data) )
|
||||
{
|
||||
|
||||
if (Buffer.byteLength(msg.data)) {
|
||||
request.write(msg.data);
|
||||
};
|
||||
request.end();
|
||||
},
|
||||
}
|
||||
request.end();
|
||||
}
|
||||
};
|
||||
module.exports = Object.create(HttpClient);
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Copyright 2015, EMC, Inc.
|
||||
|
||||
/*eslint-env node*/
|
||||
var config = require('./../../../config.json');
|
||||
var client = require('./../client');
|
||||
var Promise = require('bluebird');
|
||||
@ -15,42 +18,51 @@ var request = {
|
||||
};
|
||||
|
||||
/*
|
||||
* Monorail wrapper functions
|
||||
*/
|
||||
* Monorail wrapper functions
|
||||
*/
|
||||
var MonorailWrapper = {
|
||||
request_nodes_get: function (ret) {
|
||||
request_nodes_get: function () {
|
||||
'use strict';
|
||||
request.path = pfx + '/nodes';
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
request_node_get: function (identifier, ret) {
|
||||
request_node_get: function (identifier) {
|
||||
'use strict';
|
||||
request.path = pfx + '/nodes/' + identifier;
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
request_whitelist_set: function (hwaddr, ret) {
|
||||
request_whitelist_set: function (hwaddr) {
|
||||
'use strict';
|
||||
request.path = pfx + '/nodes/' + hwaddr + '/dhcp/whitelist';
|
||||
return client.PostAsync(request);
|
||||
},
|
||||
request_whitelist_del: function (hwaddr, ret) {
|
||||
request_whitelist_del: function (hwaddr) {
|
||||
'use strict';
|
||||
request.path = pfx + '/nodes/' + hwaddr + '/dhcp/whitelist';
|
||||
return client.DeleteAsync(request);
|
||||
},
|
||||
request_catalogs_get: function (hwaddr, ret) {
|
||||
request_catalogs_get: function (hwaddr) {
|
||||
'use strict';
|
||||
request.path = pfx + '/nodes/' + hwaddr + '/catalogs';
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
get_catalog_data_by_source: function (hwaddr, source, ret) {
|
||||
get_catalog_data_by_source: function (hwaddr, source) {
|
||||
'use strict';
|
||||
request.path = pfx + '/nodes/' + hwaddr + '/catalogs/' + source;
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
request_poller_get: function (identifier, ret) {
|
||||
request_poller_get: function (identifier) {
|
||||
'use strict';
|
||||
request.path = pfx + '/nodes/' + identifier + '/pollers';
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
request_poller_data_get: function (identifier, ret) {
|
||||
request_poller_data_get: function (identifier) {
|
||||
'use strict';
|
||||
request.path = pfx + '/pollers/' + identifier + '/data/current';
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
lookupCatalog: function lookupCatalog(node) {
|
||||
'use strict';
|
||||
var self = this;
|
||||
return self.get_catalog_data_by_source(node.id, 'dmi')
|
||||
.then(function (dmi) {
|
||||
@ -59,7 +71,7 @@ var MonorailWrapper = {
|
||||
}
|
||||
})
|
||||
.then(function () {
|
||||
return self.get_catalog_data_by_source(node.id, 'lsscsi')
|
||||
return self.get_catalog_data_by_source(node.id, 'lsscsi');
|
||||
})
|
||||
.then(function (lsscsi) {
|
||||
if (!_.has(JSON.parse(lsscsi), 'data')) {
|
||||
@ -67,72 +79,73 @@ var MonorailWrapper = {
|
||||
}
|
||||
})
|
||||
.then(function () {
|
||||
return self.get_catalog_data_by_source(node.id, 'bmc')
|
||||
return self.get_catalog_data_by_source(node.id, 'bmc');
|
||||
})
|
||||
.then(function (bmc) {
|
||||
if (!_.has(JSON.parse(bmc), 'data')) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
.catch(function (err) {
|
||||
.catch(function () {
|
||||
return false;
|
||||
})
|
||||
});
|
||||
},
|
||||
nodeDiskSize: function nodeDiskSize(node) {
|
||||
var local_gb = 0;
|
||||
'use strict';
|
||||
var localGb = 0;
|
||||
var self = this;
|
||||
return self.get_catalog_data_by_source(node.id, 'lsscsi').
|
||||
then(function (scsi) {
|
||||
scsi = JSON.parse(scsi);
|
||||
if (scsi.data) {
|
||||
for (var elem in scsi.data) {
|
||||
var item = (scsi.data[elem]);
|
||||
if (item['peripheralType'] == 'disk') {
|
||||
local_gb += parseFloat(item['size'].replace('GB', '').trim());
|
||||
for (var elem = 0; elem < scsi.data.length; elem++) {
|
||||
var item = scsi.data[elem];
|
||||
if (item.peripheralType === 'disk') {
|
||||
localGb += parseFloat(item.size.replace('GB', '').trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.resolve(local_gb);
|
||||
return Promise.resolve(localGb);
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw err;
|
||||
})
|
||||
});
|
||||
},
|
||||
get_node_memory_cpu: function get_node_memory_cpu(computeNode) {
|
||||
getNodeMemoryCpu: function getNodeMemoryCpu(computeNode) {
|
||||
'use strict';
|
||||
var self = this;
|
||||
var dmiData = { cpus: 0, memory: 0 };
|
||||
return self.get_catalog_data_by_source(computeNode.id, 'dmi').
|
||||
then(function (dmi) {
|
||||
dmi = JSON.parse(dmi);
|
||||
if (dmi.data) {
|
||||
var dmi_total = 0;
|
||||
var dmiTotal = 0;
|
||||
if (dmi.data['Memory Device']) {
|
||||
var memory_device = dmi.data['Memory Device'];
|
||||
for (var elem in memory_device) {
|
||||
var item = memory_device[elem];
|
||||
var memoryDevice = dmi.data['Memory Device'];
|
||||
for (var elem = 0; elem < memoryDevice.length; elem++) {
|
||||
var item = memoryDevice[elem];
|
||||
//logger.info(item['Size']);
|
||||
if (item['Size'].indexOf('GB') > -1) {
|
||||
dmi_total += parseFloat(item['Size'].replace('GB', '').trim()) * 1000;
|
||||
if (item.Size.indexOf('GB') > -1) {
|
||||
dmiTotal += parseFloat(item.Size.replace('GB', '').trim()) * 1000;
|
||||
}
|
||||
if (item['Size'].indexOf('MB') > -1) {
|
||||
dmi_total += parseFloat(item['Size'].replace('MB', '').trim());
|
||||
if (item.Size.indexOf('MB') > -1) {
|
||||
dmiTotal += parseFloat(item.Size.replace('MB', '').trim());
|
||||
}
|
||||
}
|
||||
dmiData.memory = dmi_total;
|
||||
dmiData.memory = dmiTotal;
|
||||
}
|
||||
if (dmi['data'].hasOwnProperty('Processor Information')) {
|
||||
dmiData.cpus = dmi['data']['Processor Information'].length;
|
||||
if (dmi.data.hasOwnProperty('Processor Information')) {
|
||||
dmiData.cpus = dmi.data['Processor Information'].length;
|
||||
}
|
||||
}
|
||||
return Promise.resolve(dmiData);
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw err;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
module.exports = Object.create(MonorailWrapper);
|
||||
module.exports = Object.create(MonorailWrapper);
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Copyright 2015, EMC, Inc.
|
||||
|
||||
/*eslint-env node*/
|
||||
var config = require('./../../../config.json');
|
||||
var client = require('./../client');
|
||||
var Promise = require('bluebird');
|
||||
@ -13,13 +16,14 @@ var request = {
|
||||
};
|
||||
|
||||
/*
|
||||
* glance wrapper functions
|
||||
* glance wrapper functions
|
||||
*/
|
||||
var glanceWrapper = {
|
||||
get_images: function (token) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/images';
|
||||
return client.GetAsync(request);
|
||||
}
|
||||
};
|
||||
module.exports = Object.create(glanceWrapper);
|
||||
module.exports = Object.create(glanceWrapper);
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Copyright 2015, EMC, Inc.
|
||||
|
||||
/*eslint-env node*/
|
||||
var config = require('./../../../config.json');
|
||||
var client = require('./../client');
|
||||
var Promise = require('bluebird');
|
||||
@ -9,68 +12,82 @@ var request = {
|
||||
path: pfx,
|
||||
token: '',
|
||||
data: '',
|
||||
api: { 'name': 'X-OpenStack-Ironic-API-Version', 'version': '1.6' } /* TODO: set version from ironic */
|
||||
api: {
|
||||
'name': 'X-OpenStack-Ironic-API-Version',
|
||||
'version': '1.6'
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Ironic wrapper functions
|
||||
* Ironic wrapper functions
|
||||
*/
|
||||
var ironicWrapper = {
|
||||
get_chassis: function (token, ret) {
|
||||
get_chassis: function (token) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/chassis';
|
||||
return client.GetAsync(request);
|
||||
|
||||
},
|
||||
get_chassis_by_id: function (token, identifier, ret) {
|
||||
get_chassis_by_id: function (token, identifier) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/chassis/' + identifier;
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
get_node_list: function (token) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/nodes/detail';
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
get_node: function (token, identifier, ret) {
|
||||
get_node: function (token, identifier) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/nodes/' + identifier;
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
create_node: function (token, node, ret) {
|
||||
create_node: function (token, node) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/nodes';
|
||||
request.data = node;
|
||||
return client.PostAsync(request);
|
||||
},
|
||||
patch_node: function (token, identifier, data, ret) {
|
||||
patch_node: function (token, identifier, data) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/nodes/' + identifier;
|
||||
request.data = data;
|
||||
return client.PatchAsync(request);
|
||||
},
|
||||
delete_node: function (token, identifier, ret) {
|
||||
delete_node: function (token, identifier) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/nodes/' + identifier;
|
||||
return client.DeleteAsync(request);
|
||||
},
|
||||
get_port_list: function (token, ret) {
|
||||
get_port_list: function (token) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/ports';
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
get_port: function (token, identifier, ret) {
|
||||
get_port: function (token, identifier) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/ports/' + identifier;
|
||||
return client.GetAsync(request);;
|
||||
return client.GetAsync(request);
|
||||
},
|
||||
create_port: function (token, port, ret) {
|
||||
create_port: function (token, port) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/ports';
|
||||
request.data = port;
|
||||
return client.PostAsync(request);
|
||||
},
|
||||
set_power_state: function (token, identifier, state, ret) {
|
||||
set_power_state: function (token, identifier, state) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/nodes/' + identifier + '/states/power';
|
||||
if (state === 'off' || state === 'on') {
|
||||
@ -81,7 +98,8 @@ var ironicWrapper = {
|
||||
}
|
||||
return client.PutAsync(request);
|
||||
},
|
||||
get_driver_list: function (token, ret) {
|
||||
get_driver_list: function (token) {
|
||||
'use strict';
|
||||
request.token = token;
|
||||
request.path = pfx + '/drivers';
|
||||
return client.GetAsync(request);
|
||||
@ -89,6 +107,3 @@ var ironicWrapper = {
|
||||
};
|
||||
|
||||
module.exports = Object.create(ironicWrapper);
|
||||
|
||||
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Copyright 2015, EMC, Inc.
|
||||
|
||||
/*eslint-env node*/
|
||||
/* keystone authentication */
|
||||
var config = require('./../../../config.json');
|
||||
var client = require('./../client');
|
||||
@ -19,15 +22,15 @@ var request = {
|
||||
|
||||
var KeystoneAuthentication = {
|
||||
authenticatePassword: function (tenantName, username, password) {
|
||||
'use strict';
|
||||
var decrypted;
|
||||
try {
|
||||
decrypted = encryption.decrypt(password);
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
//return empty promise
|
||||
return (Promise.resolve());
|
||||
};
|
||||
return Promise.resolve();
|
||||
}
|
||||
request.data = JSON.stringify(
|
||||
{
|
||||
'auth': {
|
||||
@ -39,20 +42,21 @@ var KeystoneAuthentication = {
|
||||
}
|
||||
}
|
||||
});
|
||||
return (client.PostAsync(request));
|
||||
return client.PostAsync(request);
|
||||
},
|
||||
|
||||
authenticateToken: function (tenantName, username, token) {
|
||||
request.data = JSON.stringify(
|
||||
'use strict';
|
||||
request.data = JSON.stringify(
|
||||
{
|
||||
"auth": {
|
||||
"tenantName": tenantName,
|
||||
"token": {
|
||||
"id": token
|
||||
'auth': {
|
||||
'tenantName': tenantName,
|
||||
'token': {
|
||||
'id': token
|
||||
}
|
||||
}
|
||||
});
|
||||
return (client.PostAsync(request));
|
||||
return client.PostAsync(request);
|
||||
}
|
||||
}
|
||||
module.exports = Object.create(KeystoneAuthentication);
|
||||
};
|
||||
module.exports = Object.create(KeystoneAuthentication);
|
||||
|
@ -1,19 +1,20 @@
|
||||
var crypto = require('crypto')
|
||||
/*eslint-env node*/
|
||||
var crypto = require('crypto');
|
||||
var config = require('./../../config.json');
|
||||
|
||||
var CryptoFuncs = {
|
||||
|
||||
encrypt: function (text){
|
||||
var cipher = crypto.createCipher('aes-256-cbc', config.key);
|
||||
encrypt: function (text) {
|
||||
'use strict';
|
||||
var cipher = crypto.createCipher('aes-256-cbc', config.key);
|
||||
cipher.update(text, 'utf8', 'base64');
|
||||
return cipher.final('base64');
|
||||
},
|
||||
decrypt: function (text){
|
||||
decrypt: function (text) {
|
||||
'use strict';
|
||||
var decipher = crypto.createDecipher('aes-256-cbc', config.key);
|
||||
decipher.update(text, 'base64', 'utf8');
|
||||
return decipher.final('utf8');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Object.create(CryptoFuncs);
|
||||
module.exports = Object.create(CryptoFuncs);
|
||||
|
@ -1,9 +1,11 @@
|
||||
// Copyright 2015, EMC, Inc.
|
||||
|
||||
/*eslint-env node*/
|
||||
var winston = require('winston');
|
||||
|
||||
module.exports.Logger = function Logger(level) {
|
||||
var logger = new (winston.Logger)({
|
||||
'use strict';
|
||||
var logger = new winston.Logger({
|
||||
levels: {
|
||||
verbose: 5,
|
||||
debug: 4,
|
||||
@ -27,4 +29,4 @@ module.exports.Logger = function Logger(level) {
|
||||
timestamp: true
|
||||
});
|
||||
return logger;
|
||||
}
|
||||
};
|
||||
|
@ -1,15 +1,18 @@
|
||||
// Copyright 2015, EMC, Inc.
|
||||
|
||||
/*eslint-env node*/
|
||||
var monorail = require('./../api/monorail/monorail');
|
||||
var ironic = require('./../api/openstack/ironic');
|
||||
var keystone = require('./../api/openstack/keystone');
|
||||
var _ = require('underscore');
|
||||
var config = require('./../../config.json');
|
||||
var logger = require('./logger').Logger('info');
|
||||
var Promise = require('bluebird');
|
||||
|
||||
module.exports = Poller;
|
||||
var ironicConfig = config.ironic;
|
||||
function Poller(timeInterval) {
|
||||
'use strict';
|
||||
this._timeInterval = timeInterval;
|
||||
this._ironicToken = null;
|
||||
this._timeObj = null;
|
||||
@ -24,7 +27,7 @@ function Poller(timeInterval) {
|
||||
})
|
||||
.catch(function (err) {
|
||||
logger.error(err);
|
||||
return (null);
|
||||
return null;
|
||||
});
|
||||
};
|
||||
|
||||
@ -32,63 +35,63 @@ function Poller(timeInterval) {
|
||||
try {
|
||||
clearInterval(this.timeObj);
|
||||
this.timeObj = 0;
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
Poller.prototype.runPoller = function (ironic_nodes) {
|
||||
Poller.prototype.runPoller = function (ironicNodes) {
|
||||
var self = this;
|
||||
for (var i in ironic_nodes) {
|
||||
logger.info('Running poller on :' + ironic_nodes[i].uuid + ':');
|
||||
self.searchIronic(ironic_nodes[i]);
|
||||
if (ironicNodes !== null) {
|
||||
for (var i = 0; i < ironicNodes.length; i++) {
|
||||
logger.info('Running poller on :' + ironicNodes[i].uuid + ':');
|
||||
self.searchIronic(ironicNodes[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Poller.prototype.searchIronic = function (ironic_node) {
|
||||
Poller.prototype.searchIronic = function (ironicNode) {
|
||||
var self = this;
|
||||
var node_data = ironic_node;
|
||||
var nodeData = ironicNode;
|
||||
try {
|
||||
if (node_data != undefined &&
|
||||
node_data.extra && node_data.extra.timer) {
|
||||
if (!node_data.extra.timer.stop) {
|
||||
if (nodeData !== null &&
|
||||
nodeData.extra && nodeData.extra.timer) {
|
||||
if (!nodeData.extra.timer.stop) {
|
||||
var timeNow = new Date();
|
||||
var timeFinished = node_data.extra.timer.finish;
|
||||
var _timeInterval = node_data.extra.timer.timeInterval;
|
||||
var timeFinished = nodeData.extra.timer.finish;
|
||||
var _timeInterval = nodeData.extra.timer.timeInterval;
|
||||
var parsedDate = new Date(Date.parse(timeFinished));
|
||||
var newDate = new Date(parsedDate.getTime() + _timeInterval);
|
||||
if (newDate < timeNow) {
|
||||
node_data.extra.timer.start = new Date().toJSON();
|
||||
if (node_data.extra.timer.isDone) {
|
||||
node_data.extra.timer.isDone = false;
|
||||
return self.updateInfo(self._ironicToken, node_data).
|
||||
nodeData.extra.timer.start = new Date().toJSON();
|
||||
if (nodeData.extra.timer.isDone) {
|
||||
nodeData.extra.timer.isDone = false;
|
||||
return self.updateInfo(self._ironicToken, nodeData).
|
||||
then(function (data) {
|
||||
return self.patchData(node_data.uuid, JSON.stringify(data));
|
||||
return self.patchData(nodeData.uuid, JSON.stringify(data));
|
||||
}).
|
||||
then(function (result) {
|
||||
return (result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Poller.prototype.getNodes = function (token) {
|
||||
return ironic.get_node_list(token).
|
||||
then(function (result) {
|
||||
return (JSON.parse(result).nodes);
|
||||
return JSON.parse(result).nodes;
|
||||
})
|
||||
.catch(function (err) {
|
||||
logger.error(err);
|
||||
return (null);
|
||||
return null;
|
||||
});
|
||||
};
|
||||
|
||||
@ -97,75 +100,80 @@ function Poller(timeInterval) {
|
||||
return ironic.patch_node(self._ironicToken, uuid, data).
|
||||
then(function (result) {
|
||||
result = JSON.parse(result);
|
||||
if (result != undefined) {
|
||||
return (result.extra);
|
||||
if (typeof result !== 'undefined') {
|
||||
return result.extra;
|
||||
}
|
||||
return (null);
|
||||
return null;
|
||||
})
|
||||
.catch(function (err) {
|
||||
logger.error(err);
|
||||
return (null);
|
||||
return null;
|
||||
});
|
||||
};
|
||||
|
||||
Poller.prototype.updateInfo = function (token, node_data) {
|
||||
return this.getSeldata(node_data.extra.nodeid).
|
||||
Poller.prototype.updateInfo = function (token, nodeData) {
|
||||
return this.getSeldata(nodeData.extra.nodeid).
|
||||
then(function (result) {
|
||||
if (result != null) {
|
||||
var lastEvent = {};
|
||||
var lastEvent = {};
|
||||
if (result !== null) {
|
||||
result = JSON.parse(result);
|
||||
if (result[0] && result[0].hasOwnProperty('sel')) {
|
||||
if (node_data.extra.eventre != undefined) {
|
||||
if (nodeData.extra.eventre !== null) {
|
||||
var arr = result[0].sel;
|
||||
var events = _.where(arr, { event: node_data.extra.eventre });
|
||||
if (events != undefined) {
|
||||
var events = _.where(arr, { event: nodeData.extra.eventre });
|
||||
if (events !== null) {
|
||||
logger.info(events);
|
||||
node_data.extra.eventcnt = events.length;
|
||||
nodeData.extra.eventcnt = events.length;
|
||||
lastEvent = events[events.length - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//update finish time
|
||||
node_data.extra.timer.finish = new Date().toJSON();
|
||||
node_data.extra.timer.isDone = true;
|
||||
node_data.extra.events = lastEvent;
|
||||
var data = [{ 'path': '/extra', 'value': node_data.extra, 'op': 'replace' }];
|
||||
return (data);
|
||||
nodeData.extra.timer.finish = new Date().toJSON();
|
||||
nodeData.extra.timer.isDone = true;
|
||||
nodeData.extra.events = lastEvent;
|
||||
var data = [
|
||||
{
|
||||
'path': '/extra',
|
||||
'value': nodeData.extra,
|
||||
'op': 'replace'
|
||||
}];
|
||||
return data;
|
||||
})
|
||||
.catch(function (err) {
|
||||
logger.error(err);
|
||||
return (null);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Poller.prototype.getSeldata = function (identifier) {
|
||||
return monorail.request_poller_get(identifier).
|
||||
then(function (pollers) {
|
||||
if (typeof pollers !== 'undefined') {
|
||||
pollers = JSON.parse(pollers);
|
||||
for (var i in pollers) {
|
||||
if (pollers[i]['config']['command'] === 'sel') {
|
||||
return monorail.request_poller_data_get(pollers[i]['id']).
|
||||
then(function (data) {
|
||||
return (data);
|
||||
return Promise.filter(pollers, function (poller) {
|
||||
return poller.config.command === 'sel';
|
||||
})
|
||||
.then(function (sel) {
|
||||
if (sel.length > 0) {
|
||||
return monorail.request_poller_data_get(sel[0].id)
|
||||
.then(function (data) {
|
||||
return data;
|
||||
})
|
||||
.catch(function (e) {
|
||||
logger.error(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
else {
|
||||
return (null);
|
||||
});
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.catch(function (err) {
|
||||
logger.error(err);
|
||||
return (null);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Poller.prototype.startServer = function () {
|
||||
var self = this;
|
||||
@ -175,13 +183,12 @@ function Poller(timeInterval) {
|
||||
.then(function (token) {
|
||||
return self.getNodes(token);
|
||||
})
|
||||
.then(function (ironic_nodes) {
|
||||
return self.runPoller(ironic_nodes);
|
||||
.then(function (ironicNodes) {
|
||||
return self.runPoller(ironicNodes);
|
||||
});
|
||||
}, self._timeInterval);
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,35 @@
|
||||
{
|
||||
"name": "",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"swagger"
|
||||
],
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"connect": "^3.2.0",
|
||||
"swagger-tools": "0.8.*",
|
||||
"bluebird": ""
|
||||
},
|
||||
"devDependencies": {
|
||||
"should": "~7.0.1",
|
||||
"mocha": "^2.1.0",
|
||||
"sinon": "1.16.1",
|
||||
"supertest": "^0.15.0",
|
||||
"underscore": "^1.8.3",
|
||||
"xunit-file": "0.0.6",
|
||||
"winston": "2.1.1",
|
||||
"jsonfile": "2.2.3",
|
||||
"crypto": "0.0.3",
|
||||
"istanbul": "0.4.1",
|
||||
"nock": "3.6.0"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "scripts/post-install.sh",
|
||||
"start": "start shovel",
|
||||
"test": "istanbul cover -x '**/test/**' node_modules/mocha/bin/_mocha test/api/* test/services/* test/controllers/* && istanbul report cobertura"
|
||||
}
|
||||
"name": "Shovel",
|
||||
"version": "1.0.0",
|
||||
"description": "RackHD-OpenStack Coordinator",
|
||||
"main": "main.js",
|
||||
"keywords": [
|
||||
"swagger"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"bluebird": "3.1.1",
|
||||
"connect": "^3.2.0",
|
||||
"swagger-tools": "0.8.*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"should": "~7.0.1",
|
||||
"mocha": "^2.1.0",
|
||||
"sinon": "1.16.1",
|
||||
"supertest": "^0.15.0",
|
||||
"underscore": "^1.8.3",
|
||||
"xunit-file": "0.0.6",
|
||||
"winston": "2.1.1",
|
||||
"jsonfile": "2.2.3",
|
||||
"crypto": "0.0.3",
|
||||
"istanbul": "0.4.1",
|
||||
"nock": "3.6.0",
|
||||
"eslint-config-openstack": "~1.2.3",
|
||||
"eslint": "~1.10.3"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "scripts/post-install.sh",
|
||||
"start": "start shovel",
|
||||
"test": "istanbul cover -x '**/test/**' node_modules/mocha/bin/_mocha test/api/* test/services/* test/controllers/* && istanbul report cobertura"
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ describe('****Monorail Lib****',function(){
|
||||
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" }];
|
||||
var identifier = '123456789';
|
||||
|
||||
describe('monorail nodeDiskSize get_node_memory_cpu', function () {
|
||||
describe('monorail get_node_memory_cpu', function () {
|
||||
describe('monorail nodeDiskSize getNodeMemoryCpu', function () {
|
||||
describe('monorail getNodeMemoryCpu', function () {
|
||||
afterEach('teardown mocks', function () {
|
||||
//monorail
|
||||
monorail['get_catalog_data_by_source'].restore();
|
||||
@ -25,7 +25,7 @@ describe('****Monorail Lib****',function(){
|
||||
|
||||
it('response should returns an integer with value equal to memory size 2000MB and cpus=2', function (done) {
|
||||
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0])));
|
||||
return monorail.get_node_memory_cpu(rackhdNode).
|
||||
return monorail.getNodeMemoryCpu(rackhdNode).
|
||||
then(function (result) {
|
||||
result.cpus.should.be.exactly(2);
|
||||
result.memory.should.be.exactly(2000);
|
||||
|
@ -52,7 +52,7 @@ describe('****SHOVEL API Interface****', function () {
|
||||
sinon.stub(monorail, 'request_poller_data_get').returns(Promise.resolve(JSON.stringify(_sel)));
|
||||
sinon.stub(monorail, 'request_whitelist_del').returns(Promise.resolve(''));
|
||||
sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(0));
|
||||
sinon.stub(monorail, 'get_node_memory_cpu').returns(Promise.resolve(dmiData));
|
||||
sinon.stub(monorail, 'getNodeMemoryCpu').returns(Promise.resolve(dmiData));
|
||||
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0])));
|
||||
//glance
|
||||
sinon.stub(glance, 'get_images').returns(Promise.resolve(JSON.stringify(glanceImages)));
|
||||
@ -77,7 +77,7 @@ describe('****SHOVEL API Interface****', function () {
|
||||
monorail['lookupCatalog'].restore();
|
||||
monorail['request_whitelist_del'].restore();
|
||||
monorail['nodeDiskSize'].restore();
|
||||
monorail['get_node_memory_cpu'].restore();
|
||||
monorail['getNodeMemoryCpu'].restore();
|
||||
monorail['get_catalog_data_by_source'].restore();
|
||||
//ironic
|
||||
ironic['patch_node'].restore();
|
||||
@ -506,7 +506,7 @@ describe('****SHOVEL API Interface****', function () {
|
||||
afterEach('teardown mocks', function () {
|
||||
//monorail
|
||||
monorail['nodeDiskSize'].restore();
|
||||
monorail['get_node_memory_cpu'].restore();
|
||||
monorail['getNodeMemoryCpu'].restore();
|
||||
monorail['request_node_get'].restore();
|
||||
//keystone
|
||||
keystone['authenticatePassword'].restore();
|
||||
@ -517,7 +517,7 @@ describe('****SHOVEL API Interface****', function () {
|
||||
it('response in register should have property error_message when any of node info equal to 0 ', function (done) {
|
||||
sinon.stub(monorail, 'request_node_get').returns(Promise.resolve(JSON.stringify(rackhdNode[0])));
|
||||
sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(0));
|
||||
sinon.stub(monorail, 'get_node_memory_cpu').returns(Promise.resolve({ cpus: 0, memory: 0 }));
|
||||
sinon.stub(monorail, 'getNodeMemoryCpu').returns(Promise.resolve({ cpus: 0, memory: 0 }));
|
||||
|
||||
request(url)
|
||||
.post('/api/1.1/register')
|
||||
@ -535,7 +535,7 @@ describe('****SHOVEL API Interface****', function () {
|
||||
it('response in register should have property error_message create node return error in ironic', function (done) {
|
||||
sinon.stub(monorail, 'request_node_get').returns(Promise.resolve(JSON.stringify(rackhdNode[0])));
|
||||
sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(1));
|
||||
sinon.stub(monorail, 'get_node_memory_cpu').returns(Promise.resolve({ cpus: 1, memory: 1 }));
|
||||
sinon.stub(monorail, 'getNodeMemoryCpu').returns(Promise.resolve({ cpus: 1, memory: 1 }));
|
||||
|
||||
request(url)
|
||||
.post('/api/1.1/register')
|
||||
|
@ -98,8 +98,8 @@ describe('*****Shovel poller Class****', function () {
|
||||
});
|
||||
|
||||
it('pollerInstance.getSeldata() have property sensorNumber, event', function (done) {
|
||||
return pollerInstance.getSeldata(identifier).
|
||||
then(function (data) {
|
||||
return pollerInstance.getSeldata(identifier)
|
||||
.then(function (data) {
|
||||
var result = JSON.parse(data);
|
||||
result.should.have.property('sel');
|
||||
_.each(result[0], function (item) {
|
||||
@ -108,9 +108,9 @@ describe('*****Shovel poller Class****', function () {
|
||||
});
|
||||
done();
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw (err);
|
||||
});
|
||||
.catch(function (err) {
|
||||
throw (err);
|
||||
});
|
||||
});
|
||||
|
||||
it('Poller.prototype.updateInfo have property path, value', function (done) {
|
||||
|
Loading…
Reference in New Issue
Block a user