more of create
This commit is contained in:
@@ -73,12 +73,13 @@ var Docker = function() {
|
||||
|
||||
var _containers = this;
|
||||
|
||||
var Status = Object.freeze({
|
||||
this.Status = Object.freeze({
|
||||
Error: {color: "red", action1: "start", action2: "remove", bash: false},
|
||||
Terminated: {color: "yellow", action1: "start", action2: "remove", bash: false},
|
||||
Restarting: {color: "lightblue", action1: "start", action2: "remove", bash: false},
|
||||
Paused: {color: "lightgrey", action1: "unpause", action2: null, bash: false},
|
||||
Running: {color: "lightgreen", action1: "pause", action2: "stop", bash: true}
|
||||
Paused: {color: "grey", action1: "unpause", action2: null, bash: false},
|
||||
Running: {color: "lightgreen", action1: "pause", action2: "stop", bash: true},
|
||||
Preview: {color: "lightgrey"}
|
||||
});
|
||||
var containers = [];
|
||||
var nodes = [];
|
||||
@@ -93,7 +94,7 @@ var Docker = function() {
|
||||
return false;
|
||||
}
|
||||
function getIps(n, ips) {
|
||||
n.ports.forEach(function(p) {
|
||||
if (n.ports) n.ports.forEach(function(p) {
|
||||
if (!ips[p.ip]) ips[p.ip] = [];
|
||||
ips[p.ip].push(p);
|
||||
});
|
||||
@@ -119,32 +120,33 @@ var Docker = function() {
|
||||
res+="}\n";
|
||||
return res;
|
||||
}
|
||||
function graphNode(n) {
|
||||
function graphNode(n, omitstats) {
|
||||
var res = "";
|
||||
var label = n.image.name+'\\n'+n.name+'\\ncpu: ????? mem: ?????';
|
||||
var label = n.image.name+'\\n'+n.name
|
||||
+(omitstats?'':'\\ncpu: ????? mem: ?????');
|
||||
res += '"'+n.name+'"'
|
||||
+' [label="'+label
|
||||
+'",URL="#'+n.name
|
||||
+'",style=filled,fillcolor='+n.status.color+"];\n";
|
||||
n.ports.forEach(function(p) {
|
||||
if (n.ports) n.ports.forEach(function(p) {
|
||||
res += '"'+(p.ip?p.ip+":":"")+p.external+'" -> "'+n.name
|
||||
+'" [label="'+p.internal+'"];\n';
|
||||
});
|
||||
n.links.forEach(function(l) {
|
||||
if (n.links) n.links.forEach(function(l) {
|
||||
res += '"'+n.name+'" -> "'+l.container+'" [label="link: '+l.name+'"];\n'
|
||||
});
|
||||
return res;
|
||||
}
|
||||
function graphVolumesInside(n) {
|
||||
var res = "";
|
||||
n.volumes.forEach(function(v) {
|
||||
if (n.volumes) n.volumes.forEach(function(v) {
|
||||
res += '"'+v.id+'" [label="'+v.inside+'",shape=box];\n';
|
||||
});
|
||||
return res;
|
||||
}
|
||||
function graphVolumesOutside(n) {
|
||||
var res = "";
|
||||
n.volumes.forEach(function(v) {
|
||||
if (n.volumes) n.volumes.forEach(function(v) {
|
||||
if (v.host)
|
||||
res += '"'+v.outside+'" [label="'+v.host+'",shape=box];\n';
|
||||
});
|
||||
@@ -152,23 +154,23 @@ var Docker = function() {
|
||||
}
|
||||
function graphVolumesConnections(n) {
|
||||
var res = "";
|
||||
n.volumes.forEach(function(v) {
|
||||
if (n.volumes) n.volumes.forEach(function(v) {
|
||||
if (v.host)
|
||||
res += '"'+v.id+'" -> "'+v.outside+'" [label="mounted from"]\n';
|
||||
res += '"'+n.name+'" -> "'+v.id+'" [label="volume/'+v.rw+'"]\n';
|
||||
});
|
||||
n.volumesfrom.forEach(function(o) {
|
||||
if (n.volumesfrom) n.volumesfrom.forEach(function(o) {
|
||||
res += '"'+n.name+'" -> "'+nodes[o].name+'" [label="volumes from"]\n';
|
||||
});
|
||||
return res;
|
||||
}
|
||||
this.graph = function(n) {
|
||||
this.graph = function(n, omitstats) {
|
||||
var res = "";
|
||||
var ips = [];
|
||||
n = n || nodes;
|
||||
for (name in n) getIps(n[name], ips);
|
||||
res += graphIpClusters(ips);
|
||||
for (name in n) res += graphNode(n[name]);
|
||||
for (name in n) res += graphNode(n[name], omitstats);
|
||||
res += "{rank=same;\n";
|
||||
for (name in n) res += graphVolumesInside(n[name]);
|
||||
res+="}\n";
|
||||
@@ -179,28 +181,28 @@ var Docker = function() {
|
||||
return res;
|
||||
}
|
||||
function addNodes(ns, name) {
|
||||
var n = nodes[name];
|
||||
var n = nodes[name] || ns[name];
|
||||
ns[name] = n;
|
||||
n.links.forEach(function(peer) {
|
||||
if (n.links) n.links.forEach(function(peer) {
|
||||
if (!ns[peer.container]) addNodes(ns, peer.container);
|
||||
});
|
||||
n.usedby.forEach(function(peer) {
|
||||
if (n.usedby) n.usedby.forEach(function(peer) {
|
||||
if (!ns[peer]) addNodes(ns, peer);
|
||||
});
|
||||
n.volumesfrom.forEach(function(peer) {
|
||||
if (n.volumesfrom) n.volumesfrom.forEach(function(peer) {
|
||||
if (!ns[peer]) addNodes(ns, peer);
|
||||
});
|
||||
n.volumesto.forEach(function(peer) {
|
||||
if (n.volumesto) n.volumesto.forEach(function(peer) {
|
||||
if (!ns[peer]) addNodes(ns, peer);
|
||||
});
|
||||
}
|
||||
this.subnet = function(name) {
|
||||
var ns = {};
|
||||
this.subnet = function(name, nodes) {
|
||||
var ns = nodes || {};
|
||||
addNodes(ns, name);
|
||||
return ns;
|
||||
}
|
||||
this.subgraph = function(name) {
|
||||
return this.graph(this.subnet(name));
|
||||
this.subgraph = function(name, nodes) {
|
||||
return this.graph(this.subnet(name, nodes), nodes);
|
||||
}
|
||||
this.configuration = function(name) {
|
||||
var ns = this.subnet(name);
|
||||
@@ -303,11 +305,11 @@ var Docker = function() {
|
||||
ip: ip
|
||||
});
|
||||
}
|
||||
if (c.State.Paused) nodes[name].status = Status.Paused;
|
||||
else if (c.State.Running) nodes[name].status = Status.Running;
|
||||
else if (c.State.Restarting) nodes[name].status = Status.Restarting;
|
||||
else if (c.State.ExitCode == 0) nodes[name].status = Status.Terminated;
|
||||
else nodes[name].status = Status.Error;
|
||||
if (c.State.Paused) nodes[name].status = _containers.Status.Paused;
|
||||
else if (c.State.Running) nodes[name].status = _containers.Status.Running;
|
||||
else if (c.State.Restarting) nodes[name].status = _containers.Status.Restarting;
|
||||
else if (c.State.ExitCode == 0) nodes[name].status = _containers.Status.Terminated;
|
||||
else nodes[name].status = _containers.Status.Error;
|
||||
nodes[name].volumes = [];
|
||||
var volumes = c.Volumes || c.Config.Volumes;
|
||||
nodes[name].volumes = [];
|
||||
|
||||
Reference in New Issue
Block a user