Generate egre-keys.txt file from slice tags
Andy Bavier [Wed, 27 May 2009 17:19:43 +0000 (17:19 +0000)]
NodeManager-topo.spec
topo.py

index c8590ef..a04871e 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:          NodeManager-topo
 Version:       0.5
-Release:       2
+Release:       3
 Summary:       Plugin supporting creating a default virtual topology.
 
 Group:         System Environment/Daemons
diff --git a/topo.py b/topo.py
index 5cdc7c1..a86ea81 100755 (executable)
--- a/topo.py
+++ b/topo.py
@@ -351,7 +351,28 @@ def update_hosts(slicename, hosts):
     f.close()
     return
 
+"""
+Write /etc/vini/egre-keys.txt, used by vsys topo scripts
+"""
+def write_egre_keys(slicekeys):
+    vini_dir = "/etc/vini" 
+    if not os.path.exists(vini_dir):
+        try:
+            os.mkdir(vini_dir)
+        except os.error:
+            logger.log("topo: could not create %s\n" % vini_dir)
+            return
+    keys_file = "%s/egre-keys.txt" % vini_dir
+    f = open(keys_file, 'w')
+    for slice in slicekeys:
+        f.write("%s %s\n" % (slice, slicekeys[slice]))
+    f.close()
+    return
+
 
+"""
+Executed on NM startup
+"""
 def start(options, config):
     run ("echo 1 > /proc/sys/net/ipv4/ip_forward")
     pass
@@ -368,10 +389,14 @@ def GetSlivers(data):
     global ifaces, old_ifaces
     ifaces = old_ifaces = sioc.gifconf()
 
+    slicekeys = {}
     for sliver in data['slivers']:
         attrs = {}
-        for attribute in sliver['attributes']:
-            attrs[attribute['tagname']] = attribute['value']
+        for tag in sliver['attributes']:
+            attrs[tag['tagname']] = tag['value']
+            if tag['tagname'] == 'egre_key':
+                slicekeys[sliver['name']] = tag['value']
+                
 
         if 'netns' in attrs:
             netns = int(attrs['netns'])
@@ -395,6 +420,7 @@ def GetSlivers(data):
                            sliver['name'])
 
     clean_up_old_virtual_links()
+    write_egre_keys(slicekeys)
     return