X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=net.py;h=100720c3e5e3c87ada0d667a2785bedf57c1e43b;hb=854fdfe526baa82adf31f14cac8a62223b310050;hp=45dee4ba421879e9c129069483d713a32daa9989;hpb=74a8cfb9d2eac39ae02e5323e1fb5b1d33297981;p=nodemanager.git diff --git a/net.py b/net.py index 45dee4b..100720c 100644 --- a/net.py +++ b/net.py @@ -1,6 +1,3 @@ -# $Id$ -# $URL$ - """network configuration""" # system provided modules @@ -12,21 +9,40 @@ import sioc, plnet # local modules import bwlimit, logger, iptables, tools +# we can't do anything without a network +priority=1 + dev_default = tools.get_default_if() -def start(options, conf): + +def start(): logger.log("net: plugin starting up...") def GetSlivers(data, config, plc): + # added by caglar + # band-aid for short period as old API returns networks instead of interfaces + global KEY_NAME + KEY_NAME = "interfaces" + ################# + logger.verbose("net: GetSlivers called.") - if not 'interfaces' in data: - logger.log_missing_data('net.GetSlivers','interfaces') - return + if not 'interfaces' in data: + # added by caglar + # band-aid for short period as old API returns networks instead of interfaces + # logger.log_missing_data('net.GetSlivers','interfaces') + # return + if not 'networks' in data: + logger.log_missing_data('net.GetSlivers','interfaces') + return + else: + KEY_NAME = "networks" + ################## + plnet.InitInterfaces(logger, plc, data) - if 'OVERRIDES' in dir(config): + if 'OVERRIDES' in dir(config): if config.OVERRIDES.get('net_max_rate') == '-1': logger.log("net: Slice and node BW Limits disabled.") - if len(bwlimit.tc("class show dev %s" % dev_default)): + if len(bwlimit.tc("class show dev %s" % dev_default)): logger.verbose("net: *** DISABLING NODE BW LIMITS ***") bwlimit.stop() else: @@ -47,7 +63,7 @@ def InitNodeLimit(data): for dev in devs: macs[sioc.gifhwaddr(dev).lower()] = dev - for interface in data['interfaces']: + for interface in data[KEY_NAME]: # Get interface name preferably from MAC address, falling # back on IP address. hwaddr=interface['mac'] @@ -94,7 +110,7 @@ def InitI2(plc, data): # and add IPs that don't exist in the set rather than # just recreateing the set. bwlimit.exempt_init('Internet2', i2nodes) - + # set the iptables classification rule if it doesnt exist. cmd = '-A POSTROUTING -m set --set Internet2 dst -j CLASSIFY --set-class 0001:2000 --add-mark' rules = [] @@ -106,7 +122,7 @@ def InitI2(plc, data): os.popen("/sbin/iptables -t mangle " + cmd) def InitNAT(plc, data): - + # query running network interfaces devs = sioc.gifconf() ips = dict(zip(devs.values(), devs.keys())) @@ -115,7 +131,7 @@ def InitNAT(plc, data): macs[sioc.gifhwaddr(dev).lower()] = dev ipt = iptables.IPTables() - for interface in data['interfaces']: + for interface in data[KEY_NAME]: # Get interface name preferably from MAC address, falling # back on IP address. hwaddr=interface['mac'] @@ -153,6 +169,3 @@ def InitNAT(plc, data): fields['source'] = "0.0.0.0/0" ipt.add_pf(fields) ipt.commit() - -def start(options, config): - pass