first part of create neew nodes
This commit is contained in:
@@ -2,6 +2,7 @@ module.exports = function(io) {
|
||||
|
||||
var pty = require('pty.js');
|
||||
var proc = require('child_process');
|
||||
var docker = require(__dirname+'/../docker')();
|
||||
|
||||
var module={};
|
||||
var idtoname = {};
|
||||
@@ -22,8 +23,9 @@ module.exports = function(io) {
|
||||
return fail("inspect docker containers failed", {
|
||||
error: error, stderr: stderr, stdout: stdout
|
||||
});
|
||||
idtoname = {};
|
||||
JSON.parse(stdout).forEach(function(n) {
|
||||
idtoname[n.Id] = n.Name.replace(/^\//, '');;
|
||||
if (n.State.Running) idtoname[n.Id] = n.Name.replace(/^\//, '');
|
||||
});
|
||||
if (oldcontainer && oldcontainer==stdout) return; // do not resend same containers
|
||||
oldcontainer = stdout;
|
||||
@@ -98,10 +100,17 @@ module.exports = function(io) {
|
||||
exec("docker "+cmd+" "+name, updatecontainers);
|
||||
}
|
||||
|
||||
function modify(cmd, name) {
|
||||
if (!name.match(/^[a-z0-9][-_:.+a-z0-9]*$/i))
|
||||
return fail("illegal instance name");
|
||||
exec("docker "+cmd+" "+name, updatecontainers);
|
||||
function createContainer(cmds) {
|
||||
if (cmds.length>0)
|
||||
exec(cmds.shift(), function(error, stdout, stderr) {
|
||||
if (error || stderr)
|
||||
return fail("create container failed", {
|
||||
error: error, stderr: stderr, stdout: stdout
|
||||
});
|
||||
createContainer(cmds);
|
||||
})
|
||||
else
|
||||
updatecontainers();
|
||||
}
|
||||
|
||||
function containers() {
|
||||
@@ -141,6 +150,13 @@ module.exports = function(io) {
|
||||
modify("rm", name);
|
||||
}
|
||||
|
||||
function create(data) {
|
||||
console.log("-> create");
|
||||
var d = new docker.Docker();
|
||||
var dc = new d.Containers();
|
||||
createContainer(dc.creation(data));
|
||||
}
|
||||
|
||||
function logs(name) {
|
||||
console.log("-> logs("+name+")");
|
||||
var l = proc.spawn("docker", ["logs", "-f", name])
|
||||
@@ -195,6 +211,7 @@ module.exports = function(io) {
|
||||
.on("pause", pause)
|
||||
.on("unpause", unpause)
|
||||
.on("remove", remove)
|
||||
.on("create", create)
|
||||
.on('logs', logs)
|
||||
.on('bash-start', bash_start)
|
||||
.on('bash-input', bash_input)
|
||||
|
Reference in New Issue
Block a user