Updates for change in sioc.gifconf() semantics
authorAndy Bavier <acb@cs.princeton.edu>
Wed, 11 May 2011 19:23:49 +0000 (19:23 +0000)
committerAndy Bavier <acb@cs.princeton.edu>
Wed, 11 May 2011 19:23:49 +0000 (19:23 +0000)
topo.py

diff --git a/topo.py b/topo.py
index 63e707b..2f7b6dd 100755 (executable)
--- a/topo.py
+++ b/topo.py
@@ -13,6 +13,7 @@ import re
 import vserver
 import os
 from time import strftime
+import socket
 
 dryrun = 0
 vinidir = "/usr/share/vini/"
@@ -30,6 +31,33 @@ def run(cmd):
     else:
         return subprocess.call(cmd, shell=True);
 
+"""
+From old pyplnet, former semantics needed for VINI
+"""
+def gifconf():
+    try:
+        interfaces = os.listdir("/sys/class/net")
+    except:
+        interfaces = []
+    s = None
+    ret = {}
+    try:
+        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
+        for interface in interfaces:
+            try:
+                ifreq = fcntl.ioctl(s.fileno(), SIOCGIFADDR,
+                                    struct.pack("16sH14x", interface, socket.AF_INET))
+                (family, ip) = struct.unpack(SIOCGIFADDR_struct, ifreq)
+                if family == socket.AF_INET:
+                    ret[interface] = _format_ip(ip)
+                else:
+                    raise Exception
+            except:
+                ret[interface] = "0.0.0.0"
+    finally:
+        if s is not None:
+            s.close()
+    return ret
 
 """
 Subnet used for virtual interfaces by setup-egre-link script
@@ -389,7 +417,7 @@ Creating the virtual link depends on the contents of
 """
 def GetSlivers(data, config = None, plc = None):
     global ifaces, old_ifaces
-    ifaces = old_ifaces = sioc.gifconf()
+    ifaces = old_ifaces = gifconf()
 
     slicekeys = {}
     for sliver in data['slivers']: