ipv6.py adapted to check if the node's virtualization is LXC or VS,
authorGuilherme Sperb Machado <gsm@machados.org>
Mon, 29 Sep 2014 13:37:24 +0000 (15:37 +0200)
committerGuilherme Sperb Machado <gsm@machados.org>
Mon, 29 Sep 2014 13:37:24 +0000 (15:37 +0200)
update_ipv6_slivertag.py adapted to not always remove ipv6 addrs on
/etc/hosts, and tools.py adapted related to import's and search of ipv6
addrs.

plugins/ipv6.py
plugins/update_ipv6addr_slivertag.py
tools.py

index 4f5d39f..a9df0e7 100644 (file)
@@ -216,6 +216,9 @@ def start_radvd():
 def GetSlivers(data, config, plc):
 
     type = 'sliver.LXC'
+    virt=tools.get_node_virt()
+    if virt!='lxc':
+        return
 
     interfaces = data['interfaces']
     logger.log(repr(interfaces))
index 3f63c2d..859b13d 100644 (file)
@@ -62,8 +62,10 @@ def SetSliverTag(plc, data, tagname):
                     except:
                         logger.log("update_ipv6addr_slivertag: slice tag not deleted for slice=%s" % \
                                (slice['name']) )
-            # if there's no ipv6 address anymore, then remove everything from the /etc/hosts
-            tools.remove_all_ipv6addr_hosts(slice['name'], data['hostname'])
+            result = tools.search_ipv6addr_hosts(slice['name'], value)
+            if result:
+                # if there's any ipv6 address, then remove everything from the /etc/hosts
+                tools.remove_all_ipv6addr_hosts(slice['name'], data['hostname'])
         else:
             # if the ipv6 addr set on the slice does not exist yet, so, let's add it
             if (ipv6addr is None) and len(value)>0:
index 42d63d1..7dc2d1e 100644 (file)
--- a/tools.py
+++ b/tools.py
@@ -262,9 +262,12 @@ def get_sliver_process(slice_name, process_cmdline):
 # Added by Guilherme Sperb Machado <gsm@machados.org>
 ###################################################
 
-import re
-import socket
-import fileinput
+try:
+    import re
+    import socket
+    import fileinput
+except:
+    logger.log("Could not import 're', 'socket', or 'fileinput' python packages.")
 
 # TODO: is there anything better to do if the "libvirt", "sliver_libvirt",
 # and "sliver_lxc" are not in place?
@@ -273,7 +276,7 @@ try:
     from sliver_libvirt import Sliver_Libvirt
     import sliver_lxc
 except:
-    logger.log("Could not import sliver_lxc or libvirt or sliver_libvirt -- which is required here.")
+    logger.log("Could not import 'sliver_lxc' or 'libvirt' or 'sliver_libvirt'.")
 ###################################################
 
 def get_sliver_ifconfig(slice_name, device="eth0"):
@@ -425,16 +428,27 @@ def get_hosts_file_path(slicename):
 ###################################################
 # Search if there is a specific ipv6 address in the
 # /etc/hosts file of a given slice
+# If the parameter 'ipv6addr' is None, then search
+# for any ipv6 address
 ###################################################
 def search_ipv6addr_hosts(slicename, ipv6addr):
     hostsFilePath = get_hosts_file_path(slicename)
     found=False
     try:
         for line in fileinput.input(r'%s' % (hostsFilePath)):
-            if re.search(r'%s' % (ipv6addr), line):
-                found=True
-        fileinput.close()
-        return found
+            if ipv6addr is not None:
+                if re.search(r'%s' % (ipv6addr), line):
+                    found=True
+            else:
+                search = re.search(r'^(.*)\s+.*$', line)
+                if search:
+                    ipv6candidate = search.group(1)
+                    ipv6candidatestrip = ipv6candidate.strip()
+                    valid = is_valid_ipv6(ipv6candidatestrip)
+                    if valid:
+                        found=True
+            fileinput.close()
+            return found
     except:
         logger.log("tools: FAILED to search %s in /etc/hosts file of slice=%s" % \
                    (ipv6addr, slicename) )