Correted a bug in the get_sliver_process() function in tools.py to
authorGuilherme Sperb Machado <gsm@machados.org>
Mon, 23 Mar 2015 22:17:09 +0000 (23:17 +0100)
committerGuilherme Sperb Machado <gsm@machados.org>
Mon, 23 Mar 2015 22:17:09 +0000 (23:17 +0100)
consider libvirt cgroup naming standards in Fedora 20 and later. Clean
up a bit ipv6.py and update_ipv6addr_slivertag.py, also correcting minor
bugs.

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

index c97f2ff..a4fb4c2 100644 (file)
@@ -3,7 +3,7 @@
 """
 Description: IPv6 Support and Management to Slices
 ipv6 nodemanager plugin
-Version: 0.7
+Version: 0.8
 Author: Guilherme Sperb Machado <gsm@machados.org>
 
 Requirements:
@@ -229,7 +229,7 @@ def GetSlivers(data, config, plc):
     interfaces = data['interfaces']
     logger.log(repr(interfaces))
     for interface in interfaces:
-        logger.log('ipv6: get interface: %r'%(interface))
+        #logger.log('ipv6: get interface: %r'%(interface))
         if 'interface_tag_ids' in interface:
             interface_tag_ids = "interface_tag_ids"
             interface_tag_id = "interface_tag_id"
@@ -240,17 +240,17 @@ def GetSlivers(data, config, plc):
                     ipv6addrprefix = setting['value'].split('/', 1)
                     ipv6addr = ipv6addrprefix[0]
                     valid_prefix = False
-                    logger.log("ipv6: len(ipv6addrprefix)=%s" % (len(ipv6addrprefix)) )
+                    #logger.log("ipv6: len(ipv6addrprefix)=%s" % (len(ipv6addrprefix)) )
                     if len(ipv6addrprefix)>1:
                         prefix = ipv6addrprefix[1]
-                        logger.log("ipv6: prefix=%s" % (prefix) )
+                        #logger.log("ipv6: prefix=%s" % (prefix) )
                         if int(prefix)>0 and int(prefix)<=64:
                             valid_prefix = True
                         else:
                             valid_prefix = False
                     else:
                         valid_prefix = False
-                    logger.log("ipv6: '%s'=%s" % (sliversipv6prefixtag,ipv6addr) )
+                    #logger.log("ipv6: '%s'=%s" % (sliversipv6prefixtag,ipv6addr) )
                     valid_ipv6 = tools.is_valid_ipv6(ipv6addr)
                     if not(valid_ipv6):
                         logger.log("ipv6: the 'sliversipv6prefix' tag presented a non-valid IPv6 address!")
index 302e500..d9e8094 100644 (file)
@@ -1,7 +1,7 @@
 """
 Description: Update the IPv6 Address sliver tag accordingly to the IPv6 address set
 update_ipv6addr_slivertag nodemanager plugin
-Version: 0.5
+Version: 0.6
 Author: Guilherme Sperb Machado <gsm@machados.org>
 """
 
@@ -42,9 +42,18 @@ def SetSliverTag(plc, data, tagname):
         return
 
     for slice in data['slivers']:
-#        logger.log("update_ipv6addr_slivertag: starting with slice=%s" % (slice['name']) )
+        #logger.log("update_ipv6addr_slivertag: starting with slice=%s" % (slice['name']) )
 
-        # TODO: what about the prefixlen? should we add on it as well?
+        # Check if the slice to be processed in a "system" slice
+        # If so, just loop to the next slice
+        system_slice = False
+        for attribute in slice['attributes']:
+            if attribute['tagname']=='system' and attribute['value']=='1':
+                system_slice = True
+                break
+        if system_slice: continue
+
+        # TODO: what about the prefixlen? Should we also inform the prefixlen?
         # here, I'm just taking the ipv6addr (value)
         value,prefixlen = tools.get_sliver_ipv6(slice['name'])
 
@@ -52,7 +61,7 @@ def SetSliverTag(plc, data, tagname):
         slivertags = plc.GetSliceTags({"name":slice['name'],"node_id":node_id,"tagname":tagname})
         #logger.log(repr(str(slivertags)))
         #for tag in slivertags:
-            #    logger.log(repr(str(tag)))
+        #    logger.log(repr(str(tag)))
 
         try:
             slivertag_id,ipv6addr = get_sliver_tag_id_value(slivertags)
@@ -95,9 +104,8 @@ def SetSliverTag(plc, data, tagname):
             if not result:
                 tools.remove_all_ipv6addr_hosts(slice['name'], data['hostname'])
                 tools.add_ipv6addr_hosts_line(slice['name'], data['hostname'], value)
-#        logger.log("update_ipv6addr_slivertag: finishing the update process for " +
-#               "slice=%s" % (slice['name']) )
+            #logger.log("update_ipv6addr_slivertag: finishing the update process for " +
+            #   "slice=%s" % (slice['name']) )
 
 def GetSlivers(data, config, plc):
     SetSliverTag(plc, data, ipv6addrtag)
-    logger.log("update_ipv6addr_slivertag: all done!")
index 1cef746..070fdec 100644 (file)
--- a/tools.py
+++ b/tools.py
@@ -215,7 +215,7 @@ class NMLock:
 # running ifconfig inside of the slice's context.
 
 def get_sliver_process(slice_name, process_cmdline):
-    """ 
+    """
     Utility function to find a process inside of an LXC sliver. Returns
     (cgroup_fn, pid). cgroup_fn is the filename of the cgroup file for
     the process, for example /proc/2592/cgroup. Pid is the process id of
@@ -238,10 +238,24 @@ def get_sliver_process(slice_name, process_cmdline):
             comp = l.rsplit(':')[-1]
             slice_name_check = comp.rsplit('/')[-1]
             # the lines below were added by Guilherme <gsm@machados.org>
-            # due to the ipv6 plugin requirements (LXC)
+            # due to the LXC requirements
+            # What we have to consider here is that libervirt on Fedora 18
+            # uses the following line:
+            # /proc/1253/cgroup:6:freezer:/machine.slice/auto_sirius.libvirt-lxc
+            # While the libvirt on Fedora 20 and 21 uses the following line:
+            # /proc/1253/cgroup:6:freezer:/machine.slice/machine-lxc\x2del_sirius.scope
+            # Further documentation on:
+            # https://libvirt.org/cgroups.html#systemdScope
             virt=get_node_virt()
             if virt=='lxc':
-                slice_name_check = slice_name_check.rsplit('.')[0]
+                # This is for Fedora 20 or later
+                regexf20orlater = re.compile(r'machine-lxc\\x2d(.+).scope')
+                isf20orlater = regexf20orlater.search(slice_name_check)
+                if isf20orlater:
+                    slice_name_check = isf20orlater.group(1)
+                else:
+                    # This is for Fedora 18
+                    slice_name_check = slice_name_check.rsplit('.')[0]
 
             if (slice_name_check == slice_name):
                 slice_path = path
@@ -281,7 +295,7 @@ except:
 ###################################################
 
 def get_sliver_ifconfig(slice_name, device="eth0"):
-    """ 
+    """
     return the output of "ifconfig" run from inside the sliver.
 
     side effects: adds "/usr/sbin" to sys.path
@@ -449,8 +463,8 @@ def search_ipv6addr_hosts(slicename, ipv6addr):
                     valid = is_valid_ipv6(ipv6candidatestrip)
                     if valid:
                         found=True
-            fileinput.close()
-            return found
+        fileinput.close()
+        return found
     except:
         logger.log("tools: FAILED to search %s in /etc/hosts file of slice=%s" % \
                    (ipv6addr, slicename) )