UNPKG

kaanalnet

Version:

Virtual Network Emulator Lab for SDN and traditional networks

96 lines (87 loc) 3.06 kB
// Generated by CoffeeScript 1.9.3 (function() { var async, enableBonding, exec, execute, fs, util; util = require('util'); exec = require('child_process').exec; async = require('async'); fs = require('fs'); execute = function(command, callback) { if (command == null) { callback(false); } util.log("executing " + command + "..."); return exec(command, (function(_this) { return function(error, stdout, stderr) { if (error) { return callback(false); } else { return callback(true); } }; })(this)); }; enableBonding = function(callback) { var bondifs; bondifs = ["bond1", "bond2", "bond3", "bond4"]; return async.series([ (function(_this) { return function(callback) { var command, filename, text; console.log("create bonding interface"); filename = "/etc/modprobe.d/bonding.conf"; text = "alias bond0 bonding \noptions bonding mode=4\n"; fs.writeFileSync(filename, text); command = "modprobe bonding"; return execute(command, function(result) { console.log("Result ", result); if (result === false) { return callback(new Error('load bonding driver failed')); } else { return callback(null, "load bonding driver success"); } }); }; })(this), (function(_this) { return function(callback) { console.log("creating a multiple bond interfaces"); console.log(bondifs); return async.each(bondifs, function(ifname, callback) { var command; console.log("interface " + ifname); command = "echo \"+" + ifname + "\" > /sys/class/net/bonding_masters"; return execute(command, function(result) { command = "echo \"4\" > /sys/class/net/" + ifname + "/bonding/mode"; return execute(command, function(result) { console.log("Result ", result); if (result === false) { return callback(new Error('create bond interface failed')); } else { return callback(null); } }); }); }, function(err) { if (err) { console.log("creating multiple bond inferfaces failed - error occured " + JSON.stringify(err)); return callback(err); } else { console.log("creating muliple bond interfaces - success "); return callback(null, "creating multiple bond interfaces - success"); } }); }; })(this) ], (function(_this) { return function(err, result) { console.log("Bonding - RUN result is %s ", result); if (err) { return callback(false); } if (!err) { return callback(true); } }; })(this)); }; module.exports = enableBonding; }).call(this);