Cut out unneeded stuff
[nodemanager.git] / net.py
diff --git a/net.py b/net.py
index a2b28ca..70b1b4b 100644 (file)
--- a/net.py
+++ b/net.py
@@ -2,13 +2,15 @@
 
 # system provided modules
 import os, string, time, socket
+from socket import inet_aton
 
 # PlanetLab system modules
 import sioc, plnet
 
 # local modules
-import bwlimitlxc as bwlimit
+import plnode.bwlimit as bwlimit
 import logger, iptables, tools
+import subprocess
 
 # we can't do anything without a network
 priority=1
@@ -40,6 +42,8 @@ def GetSlivers(data, config, plc):
         ##################
 
     plnet.InitInterfaces(logger, plc, data)
+    
+    """
     if 'OVERRIDES' in dir(config):
         if config.OVERRIDES.get('net_max_rate') == '-1':
             logger.log("net: Slice and node BW Limits disabled.")
@@ -53,8 +57,8 @@ def GetSlivers(data, config, plc):
         InitNodeLimit(data)
         InitI2(plc, data)
     InitNAT(plc, data)
-
-
+    """
+    
 def InitNodeLimit(data):
 
     # query running network interfaces
@@ -170,3 +174,32 @@ def InitNAT(plc, data):
                         fields['source'] = "0.0.0.0/0"
                     ipt.add_pf(fields)
     ipt.commit()
+
+# Helper functions for converting to CIDR notation
+def get_net_size(netmask):
+    binary_str = ''
+    for octet in netmask:
+        binary_str += bin(int(octet))[2:].zfill(8)
+    return str(len(binary_str.rstrip('0')))
+
+def to_cidr(ipaddr, netmask):
+    # validate input
+    inet_aton(ipaddr)
+    inet_aton(netmask)
+
+    ipaddr = ipaddr.split('.')
+    netmask = netmask.split('.')
+
+    net_start = [str(int(ipaddr[x]) & int(netmask[x])) for x in range(0,4)]
+    return '.'.join(net_start) + '/' + get_net_size(netmask)
+
+def ipaddr_range(network, broadcast):
+    start = network.split('.')
+    end = broadcast.split('.')
+
+    # Assume interface always claims the first address in the block
+    start[3] = str(int(start[3]) + 2)
+    end[3] = str(int(end[3]) - 1)
+
+    return '.'.join(start) + ',' + '.'.join(end)
+