UNPKG

kaanalnet

Version:

Virtual Network Emulator Lab for SDN and traditional networks

89 lines (80 loc) 2.48 kB
// Generated by CoffeeScript 1.9.3 var GetContainerNames, destroyContainer, exec, stopContainer, util; util = require('util'); exec = require('child_process').exec; console.log("clean up container"); destroyContainer = function(container, cb) { var command; command = "lxc-destroy -n " + container; console.log("executing " + command + "..."); return exec(command, (function(_this) { return function(error, stdout, stderr) { console.log("Destroying the container - Error : " + error); console.log("Destroying the container - stdout : " + stdout); console.log("Destroying the container - stderr : " + stderr); if (error != null) { return cb(false); } else { return cb(true); } }; })(this)); }; GetContainerNames = function(cb) { var command; command = "lxc-ls"; return exec(command, (function(_this) { return function(error, stdout, stderr) { console.log("Error : " + error); console.log("stdout : " + stdout); console.log("stderr : " + stderr); if (error != null) { return cb(false); } else { return cb(stdout.toString()); } }; })(this)); }; stopContainer = function(container, cb) { var command; command = "lxc-stop -n " + container; console.log("Exec command ", command); return exec(command, (function(_this) { return function(error, stdout, stderr) { console.log("Error : " + error); console.log("stdout : " + stdout); console.log("stderr : " + stderr); if (error != null) { return cb(false); } else { return cb(stdout.toString()); } }; })(this)); }; console.log("Installing LXC ubuntu base image"); GetContainerNames((function(_this) { return function(result) { var i, len, n, results, tmparr; result.trim(); console.log("GetContainerNames completed - result " + result); tmparr = result.split("\n"); results = []; for (i = 0, len = tmparr.length; i < len; i++) { n = tmparr[i]; n = n.trim(); if (n !== 'nodeimg') { results.push(stopContainer(n, function(result) { console.log("stopContainer result ", result); return destroyContainer(n, function(result1) { return console.log("destroyContainer result ", result1); }); })); } else { results.push(console.log("found exluced list", n)); } } return results; }; })(this));