From 1cf89568b7108a6c909f5edb1a841e219d8ab871 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:14:53 -0500 Subject: [PATCH 01/20] runner --- package.json | 3 ++- routes/api.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 598161a..b1becda 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "morgan": "~1.6.1", "serve-favicon": "~2.3.0", "node.extend": "~1.1.5", - "redis": "~2.4.2" + "redis": "~2.4.2", + "request": "~2.69.0" } } diff --git a/routes/api.js b/routes/api.js index cc9b3b8..ece605d 100644 --- a/routes/api.js +++ b/routes/api.js @@ -5,6 +5,7 @@ var router = express.Router(); var extend = require('node.extend'); var redis = require("redis"); var client = redis.createClient(); +var request = require('request'); var lxc = require('../lxc'); router.get('/start/:name', function(req, res, next){ @@ -83,4 +84,26 @@ router.get('/list', function(req, res, next) { }); }); +router.get('/run/:ip?', function(req, res, next){ + var runner = function(res, req, ip){ + request.post({url:'http://'+ip, body:req.post}, function(error, response, body){ + body = JSON.parse(body); + body['ip'] = ip.replace('10.0.', '') + return res.json(body) + }) + }; + + + if(req.params.ip){ + var ip = '10.0.'+ req.params.ip; + return runner(res, req, ip); + }else{ + var name = 'u1-'+(Math.random()*100).toString().replace('.','') + lxc.startEphemeral(name, 'u1', function(data){ + return runner(res, req, data.ip); + }); + } + +}); + module.exports = router; From e976bd3ad0606bf7ae1086ce20e1b436299146d3 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:20:14 -0500 Subject: [PATCH 02/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index ece605d..a3613cc 100644 --- a/routes/api.js +++ b/routes/api.js @@ -84,7 +84,7 @@ router.get('/list', function(req, res, next) { }); }); -router.get('/run/:ip?', function(req, res, next){ +router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ request.post({url:'http://'+ip, body:req.post}, function(error, response, body){ body = JSON.parse(body); From 1a1cc2815804210333dd9e20b00418a90c6f800c Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:22:39 -0500 Subject: [PATCH 03/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index a3613cc..0a8f72e 100644 --- a/routes/api.js +++ b/routes/api.js @@ -84,7 +84,7 @@ router.get('/list', function(req, res, next) { }); }); -router.post('/run/:ip?', function(req, res, next){ +router.post('/run', function(req, res, next){ var runner = function(res, req, ip){ request.post({url:'http://'+ip, body:req.post}, function(error, response, body){ body = JSON.parse(body); From 3bc57876ad8e157d58350cbcc14816ccf7805c13 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:26:35 -0500 Subject: [PATCH 04/20] runner --- routes/api.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 0a8f72e..2f6ad79 100644 --- a/routes/api.js +++ b/routes/api.js @@ -84,9 +84,10 @@ router.get('/list', function(req, res, next) { }); }); -router.post('/run', function(req, res, next){ +router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ request.post({url:'http://'+ip, body:req.post}, function(error, response, body){ + console.log('runner body:', body) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') return res.json(body) From f2a0f7cfa7b90a9012c63ccafff6fcf75be22ccf Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:28:48 -0500 Subject: [PATCH 05/20] runner --- routes/api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/api.js b/routes/api.js index 2f6ad79..9926ce3 100644 --- a/routes/api.js +++ b/routes/api.js @@ -86,6 +86,7 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ + console.log('req body', req.body) request.post({url:'http://'+ip, body:req.post}, function(error, response, body){ console.log('runner body:', body) body = JSON.parse(body); From a6a951f3336eac65e13866291d2da5ea2cf5f901 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:29:56 -0500 Subject: [PATCH 06/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 9926ce3..4d39beb 100644 --- a/routes/api.js +++ b/routes/api.js @@ -86,7 +86,7 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ - console.log('req body', req.body) + console.log('req body:', req.body); request.post({url:'http://'+ip, body:req.post}, function(error, response, body){ console.log('runner body:', body) body = JSON.parse(body); From a0b72ed700a6426b97417003474c829ba3a51fba Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:30:55 -0500 Subject: [PATCH 07/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 4d39beb..9b9297e 100644 --- a/routes/api.js +++ b/routes/api.js @@ -87,7 +87,7 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ console.log('req body:', req.body); - request.post({url:'http://'+ip, body:req.post}, function(error, response, body){ + request.post({url:'http://'+ip, body:req.body}, function(error, response, body){ console.log('runner body:', body) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') From 61f7e74c91f525edbfb1b24dc46c44f6c0ede342 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:32:28 -0500 Subject: [PATCH 08/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 9b9297e..5c90dbf 100644 --- a/routes/api.js +++ b/routes/api.js @@ -87,7 +87,7 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ console.log('req body:', req.body); - request.post({url:'http://'+ip, body:req.body}, function(error, response, body){ + request.post('http://'+ip, req.body, function(error, response, body){ console.log('runner body:', body) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') From 82cb526a578d4dfd5f6f341a2de4855e18d94213 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:37:09 -0500 Subject: [PATCH 09/20] runner --- routes/api.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/routes/api.js b/routes/api.js index 5c90dbf..8bff7f6 100644 --- a/routes/api.js +++ b/routes/api.js @@ -86,9 +86,8 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ - console.log('req body:', req.body); - request.post('http://'+ip, req.body, function(error, response, body){ - console.log('runner body:', body) + request.post({url:'http://'+ip, body: req.body}, function(error, response, body){ + console.log('request args:', arguments) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') return res.json(body) From 5d43be91230264ed51024285312f33345ab3a4a9 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:38:47 -0500 Subject: [PATCH 10/20] runner --- routes/api.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 8bff7f6..c708c25 100644 --- a/routes/api.js +++ b/routes/api.js @@ -99,7 +99,8 @@ router.post('/run/:ip?', function(req, res, next){ var ip = '10.0.'+ req.params.ip; return runner(res, req, ip); }else{ - var name = 'u1-'+(Math.random()*100).toString().replace('.','') + var name = 'u1-'+(Math.random()*100).toString().replace('.',''); + console.log('new VM', name); lxc.startEphemeral(name, 'u1', function(data){ return runner(res, req, data.ip); }); From e4e4c71ce18eb805a6c3df8fb0eb4bba193743f8 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 13:58:00 -0500 Subject: [PATCH 11/20] runner --- routes/api.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/routes/api.js b/routes/api.js index c708c25..6cbb7c0 100644 --- a/routes/api.js +++ b/routes/api.js @@ -33,65 +33,66 @@ router.get('/start/:name', function(req, res, next){ }); router.get('/live/:template/:name', function(req, res, next){ - lxc.startEphemeral(req.params.name, req.params.template, function (data) { + return lxc.startEphemeral(req.params.name, req.params.template, function (data) { console.log('live', arguments); - res.json(data); + return res.json(data); }); }); router.get('/stop/:name', function(req, res, next){ - lxc.stop(req.params.name, function(data){ + return lxc.stop(req.params.name, function(data){ console.log('stop', arguments); if(data){ - res.json({status: 500, name: req.params.name, message: data}); + return res.json({status: 500, name: req.params.name, message: data}); }else{ - res.json({status: 200}); + return res.json({status: 200}); } }); }); router.get('/clone/:template/:name', function(req, res, next){ - lxc.clone(req.params.name, req.params.template, function(data){ + return lxc.clone(req.params.name, req.params.template, function(data){ console.log('clone', arguments); if( data.match(/Created container/) ){ - res.json({status: 200}); + return res.json({status: 200}); }else{ - res.json({status: 500, message: data}); + return res.json({status: 500, message: data}); } }); }); router.get('/destroy/:name', function(req, res, next){ - lxc.destroy(req.params.name, function(data){ + return lxc.destroy(req.params.name, function(data){ console.log('destroy', arguments); if(data){ - res.json({status: 500, message: data}); + return res.json({status: 500, message: data}); }else{ - res.json({status: 200}); + return res.json({status: 200}); } }); }); router.get('/info/:name', function(req, res, next){ - lxc.info(req.params.name, function(data){ - res.json(data); + return lxc.info(req.params.name, function(data){ + return res.json(data); }); }); router.get('/list', function(req, res, next) { - lxc.list(function(data){ - res.json(data); + return lxc.list(function(data){ + return res.json(data); }); }); router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ - request.post({url:'http://'+ip, body: req.body}, function(error, response, body){ + console.log('runner on', ip); + return request.post({url:'http://'+ip, body: req.body}, function(error, response, body){ console.log('request args:', arguments) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') return res.json(body) - }) + }); }; @@ -101,7 +102,7 @@ router.post('/run/:ip?', function(req, res, next){ }else{ var name = 'u1-'+(Math.random()*100).toString().replace('.',''); console.log('new VM', name); - lxc.startEphemeral(name, 'u1', function(data){ + return lxc.startEphemeral(name, 'u1', function(data){ return runner(res, req, data.ip); }); } From 0ba86e19d0aa66c1ff4eea8328d127c6fed062a7 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 14:01:08 -0500 Subject: [PATCH 12/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 6cbb7c0..5049e11 100644 --- a/routes/api.js +++ b/routes/api.js @@ -87,7 +87,7 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ console.log('runner on', ip); - return request.post({url:'http://'+ip, body: req.body}, function(error, response, body){ + return request.post({url:'http://'+ip, json: req.body}, function(error, response, body){ console.log('request args:', arguments) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') From d51720a01caef787df8a5ef0de838c5cb701d5a0 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 14:02:48 -0500 Subject: [PATCH 13/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 5049e11..7379e18 100644 --- a/routes/api.js +++ b/routes/api.js @@ -86,7 +86,7 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ - console.log('runner on', ip); + console.log('runner on', ip,'with body:\n', req.body); return request.post({url:'http://'+ip, json: req.body}, function(error, response, body){ console.log('request args:', arguments) body = JSON.parse(body); From ec85940bcb0a6211cd562d4668ea05c0e3b41618 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 14:12:09 -0500 Subject: [PATCH 14/20] runner --- routes/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/api.js b/routes/api.js index 7379e18..787844f 100644 --- a/routes/api.js +++ b/routes/api.js @@ -86,9 +86,9 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ - console.log('runner on', ip,'with body:\n', req.body); + console.log('runner on', ip,'with body:\n', typeof req.body); return request.post({url:'http://'+ip, json: req.body}, function(error, response, body){ - console.log('request args:', arguments) + // console.log('request args:', arguments) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') return res.json(body) From 9a46cbfd9af0d5bacbe9a5354cea621da65669d8 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 14:14:10 -0500 Subject: [PATCH 15/20] runner --- routes/api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/api.js b/routes/api.js index 787844f..8a829c3 100644 --- a/routes/api.js +++ b/routes/api.js @@ -85,6 +85,7 @@ router.get('/list', function(req, res, next) { }); router.post('/run/:ip?', function(req, res, next){ + var runner = function(res, req, ip){ console.log('runner on', ip,'with body:\n', typeof req.body); return request.post({url:'http://'+ip, json: req.body}, function(error, response, body){ From 9b5ed13bdd7e001db70abac04f533720ff08f798 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 14:15:07 -0500 Subject: [PATCH 16/20] runner --- routes/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/api.js b/routes/api.js index 8a829c3..4fee5db 100644 --- a/routes/api.js +++ b/routes/api.js @@ -85,10 +85,10 @@ router.get('/list', function(req, res, next) { }); router.post('/run/:ip?', function(req, res, next){ - + var runner = function(res, req, ip){ console.log('runner on', ip,'with body:\n', typeof req.body); - return request.post({url:'http://'+ip, json: req.body}, function(error, response, body){ + return request.post({url:'http://'+ip, body: JSON.stringify(req.body)}, function(error, response, body){ // console.log('request args:', arguments) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') From 5894e42a64152f9d54841ab3ce33199a99546288 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 14:16:03 -0500 Subject: [PATCH 17/20] runner --- routes/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/api.js b/routes/api.js index 4fee5db..90ca4dd 100644 --- a/routes/api.js +++ b/routes/api.js @@ -87,9 +87,9 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ - console.log('runner on', ip,'with body:\n', typeof req.body); + console.log('runner on', ip,'with body:\n', JSON.stringify(req.body)); return request.post({url:'http://'+ip, body: JSON.stringify(req.body)}, function(error, response, body){ - // console.log('request args:', arguments) + console.log('request args:', arguments) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') return res.json(body) From 374c5dec47420f2a48afafbc4553fb83fcf9bd83 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 14:19:39 -0500 Subject: [PATCH 18/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 90ca4dd..e8e4da0 100644 --- a/routes/api.js +++ b/routes/api.js @@ -88,7 +88,7 @@ router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ console.log('runner on', ip,'with body:\n', JSON.stringify(req.body)); - return request.post({url:'http://'+ip, body: JSON.stringify(req.body)}, function(error, response, body){ + return request.post({url:'http://'+ip, postData: JSON.stringify(req.body)}, function(error, response, body){ console.log('request args:', arguments) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') From 32ddcfba7dd8f8f1d656545044dc417f6b26ba26 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 14:24:51 -0500 Subject: [PATCH 19/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index e8e4da0..81177ff 100644 --- a/routes/api.js +++ b/routes/api.js @@ -88,7 +88,7 @@ router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ console.log('runner on', ip,'with body:\n', JSON.stringify(req.body)); - return request.post({url:'http://'+ip, postData: JSON.stringify(req.body)}, function(error, response, body){ + return request.post({url:'http://'+ip, postData: req.body}, function(error, response, body){ console.log('request args:', arguments) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '') From 1d8fa99ddc7d780e176ae13d0b39c26d6b51cde6 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 2 Feb 2016 14:26:42 -0500 Subject: [PATCH 20/20] runner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 81177ff..942c4ee 100644 --- a/routes/api.js +++ b/routes/api.js @@ -88,7 +88,7 @@ router.post('/run/:ip?', function(req, res, next){ var runner = function(res, req, ip){ console.log('runner on', ip,'with body:\n', JSON.stringify(req.body)); - return request.post({url:'http://'+ip, postData: req.body}, function(error, response, body){ + return request.post({url:'http://'+ip, form: req.body}, function(error, response, body){ console.log('request args:', arguments) body = JSON.parse(body); body['ip'] = ip.replace('10.0.', '')