This commit is contained in:
William Mantly 2016-02-04 13:50:29 -05:00
parent 7794e4b2ca
commit f46c99c9a8
2 changed files with 32 additions and 8 deletions

35
lxc.js
View File

@ -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]});
@ -94,7 +116,8 @@ var lxc = {
output = output.slice(0).slice(0,-1);
for(var i in output){
if(output[i].match(/^-/)) continue;
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){

View File

@ -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({});
}
});
});