From f46c99c9a80e15c0aa1122c21d93a7c09230ed89 Mon Sep 17 00:00:00 2001 From: william Date: Thu, 4 Feb 2016 13:50:29 -0500 Subject: [PATCH 1/4] runner --- lxc.js | 37 ++++++++++++++++++++++++++++++------- routes/api.js | 3 ++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lxc.js b/lxc.js index 6f8a66c..c392780 100644 --- a/lxc.js +++ b/lxc.js @@ -13,6 +13,29 @@ function sysExec(command, callback){ })(callback)); }; +var Container = function(config){ + this.name = config.name; + this.state = config.state; + this.ip = config.ip || (config.ipv4 || '').replace('-', '') || null ; +} + +Container.prototype.autoShutDown = function(time) { + time = time || 600000; + + this.__shutDownTimeout = setTimeout(function(){}, this.autoShutDown): +}; + +var lxcORM = function(){ + var orm = {} + lxc.list(function(data){ + for(var idx = data.length; idx--){ + orm[data[idx].name] = new Container(data); + } + }); + + return orm +}; + var lxc = { create: function(name, template, config, callback){ return sysExec('lxc-create -n '+name+' -t '+template, callback); @@ -27,13 +50,12 @@ var lxc = { var info = data.match(/Destroyed container/); console.log('destroy info:', info); var args = [true].concat(Array.prototype.slice.call(arguments, 1)); - callback.apply(this, args); + return callback.apply(this, args); }); }, start: function(name, callback){ - var cmd = 'lxc-start --name '+name+' --daemon'; - return sysExec(cmd, callback); + return sysExec('lxc-start --name '+name+' --daemon', callback); }, startEphemeral: function(name, base_name, callback){ @@ -43,8 +65,8 @@ var lxc = { if(data.match("doesn't exist.")){ return callback({status: 500, error: "doesn't exist."}); } - if(data.match("already exists.")){ - return callback({status: 500, error: "already exists"}); + if(data.match('already exists.')){ + return callback({status: 500, error: 'already exists'}); } if(data.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)){ return callback({status: 200, state:'RUNNING', ip: data.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)[0]}); @@ -93,8 +115,9 @@ var lxc = { keys = keys.map(function(v){return v.toLowerCase()}); output = output.slice(0).slice(0,-1); - for(var i in output){ - if(output[i].match(/^-/)) continue; + for(var i in output){ + if(output[i].match(/^-/)) continue; // compatibility with 1.x and 2.x output + var aIn = output[i].split(/\s+/).slice(0,-1); var mapOut = {}; aIn.map(function(value,idx){ diff --git a/routes/api.js b/routes/api.js index a7d6887..4fb20de 100644 --- a/routes/api.js +++ b/routes/api.js @@ -15,6 +15,7 @@ var runner = function(req, res, ip){ return res.json(body); }); }; + var addToRedis = function(){ lxc.info(req.params.name, null, function(data){ var domain = req.query.domain || 'vm42.us'; @@ -35,7 +36,7 @@ router.get('/start/:name', function(req, res, next){ if(!data){ return res.json({status: 500, name: req.params.name, message: data}); }else{ - res.json({}) + res.json({}); } }); }); From 5136d5495b6b7a65c7416a887dab098d4e66fda8 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 5 Feb 2016 23:32:36 -0500 Subject: [PATCH 2/4] runner --- lxc.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lxc.js b/lxc.js index c392780..71ff40f 100644 --- a/lxc.js +++ b/lxc.js @@ -22,13 +22,13 @@ var Container = function(config){ Container.prototype.autoShutDown = function(time) { time = time || 600000; - this.__shutDownTimeout = setTimeout(function(){}, this.autoShutDown): + // this.__shutDownTimeout = setTimeout(function(){}, this.autoShutDown): }; var lxcORM = function(){ var orm = {} lxc.list(function(data){ - for(var idx = data.length; idx--){ + for(var idx = data.length; idx--;){ orm[data[idx].name] = new Container(data); } }); @@ -133,3 +133,6 @@ var lxc = { }; module.exports = lxc; + +var orm = lxcORM() +setTimeout(function(){}) From 0af7ea05f5dccb290207dff8653292e0e627486d Mon Sep 17 00:00:00 2001 From: william Date: Fri, 5 Feb 2016 23:57:57 -0500 Subject: [PATCH 3/4] runner --- lxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index 71ff40f..b256cd6 100644 --- a/lxc.js +++ b/lxc.js @@ -135,4 +135,4 @@ var lxc = { module.exports = lxc; var orm = lxcORM() -setTimeout(function(){}) +setTimeout(function(){console.log(orm)}, 5000) From 44c94636b6f423019925bb0eb4d93a31a6b4e26f Mon Sep 17 00:00:00 2001 From: william Date: Sat, 6 Feb 2016 00:00:31 -0500 Subject: [PATCH 4/4] runner --- lxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index b256cd6..a54a942 100644 --- a/lxc.js +++ b/lxc.js @@ -29,7 +29,7 @@ var lxcORM = function(){ var orm = {} lxc.list(function(data){ for(var idx = data.length; idx--;){ - orm[data[idx].name] = new Container(data); + orm[data[idx].name] = new Container(data[idx]); } });