reguire gnupg1 on f>=31; sense the system to use gpg1 when installed
[nodemanager.git] / plugins / ipv6.py
index a9ab96e..28e138f 100644 (file)
@@ -3,8 +3,19 @@
 """
 Description: IPv6 Support and Management to Slices
 ipv6 nodemanager plugin
-Version: 0.5
+Version: 0.8
 Author: Guilherme Sperb Machado <gsm@machados.org>
+
+Requirements:
+* The 'sliversipv6prefix' tag must have this format:
+  ipv6_address/prefix -- e.g., 2002:1000::1/64
+* The prefix specified on 'sliversipv6prefix' tag must be at least 64
+  It should vary between 1 and 64, since it is the minimum amount of bits to
+  have native IPv6 auto-configuration.
+* The ipv6_address in 'sliversipv6prefix' tag value can be any valid IPv6 address.
+  E.g., 2002:1000:: or 2002:1000::1
+* It is the node manager/admin responsibility to properly set the IPv6 routing,
+  since slivers should receive/send any kind of traffic.
 """
 
 import logger
@@ -13,11 +24,17 @@ import socket
 import re
 
 import tools
-import libvirt
 import uuid
-from sliver_libvirt import Sliver_Libvirt
 from xml.dom.minidom import parseString
 
+# TODO: is there anything better to do if the "libvirt", "sliver_libvirt",
+# and are not in place in the VS distro?
+try:
+    import libvirt
+    from sliver_libvirt import Sliver_Libvirt
+except:
+    logger.log("Could not import 'sliver_lxc' or 'libvirt'.")
+
 priority=4
 
 radvd_conf_file = '/etc/radvd.conf'
@@ -136,7 +153,7 @@ def check_if_ipv6_is_different(dom, ipv6addr, prefix):
             if ip.getAttribute('family')=='ipv6' and \
                    not ( re.match(r'fe80(.*)', ip.getAttribute("address"), re.I) ) and \
                    (ip.getAttribute('address')!=ipv6addr or ip.getAttribute('prefix')!=prefix) :
-                logger.log("ipv6: the IPv6 address or prefix are different. Change detected!")
+                logger.log("ipv6: IPv6 address or prefix are different. Change detected!")
                 return True
     return False
 
@@ -153,7 +170,7 @@ def set_up(networkLibvirt, connLibvirt, networkElem, ipv6addr, prefix):
     #logger.log(networkElem.toxml())
     #ret = dir(conn)
     #for method in ret:
-    #  logger.log(repr(method))
+    #    logger.log(repr(method))
     networkLibvirt.undefine()
     networkLibvirt.destroy()
     connLibvirt.networkCreateXML(newXml)
@@ -176,11 +193,11 @@ interface virbr0
 
 };
 """ % locals()
-    with open(radvd_conf_file,'w') as f:
+    with open(radvd_conf_file, 'w') as f:
         f.write(configRadvd)
     kill_radvd()
     start_radvd()
-    logger.log("ipv6: set up process finalized. Enabled IPv6 address to the slivers!")
+    logger.log("ipv6: set up process finalized -- enabled IPv6 address to the slivers!")
 
 def clean_up(networkLibvirt, connLibvirt, networkElem):
     dom = remove_ipv6(networkElem)
@@ -205,11 +222,14 @@ 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))
     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"
@@ -220,21 +240,23 @@ def GetSlivers(data, config, plc):
                     ipv6addrprefix = setting['value'].split('/', 1)
                     ipv6addr = ipv6addrprefix[0]
                     valid_prefix = False
+                    #logger.log("ipv6: len(ipv6addrprefix)=%s" % (len(ipv6addrprefix)) )
                     if len(ipv6addrprefix)>1:
                         prefix = ipv6addrprefix[1]
-                        if prefix>0 and prefix<=64:
+                        #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!")
                     elif not(valid_prefix):
-                            logger.log("ipv6: the '%s' tag does not present a valid prefix " +
-                                   "(e.g., '/64', '/58')!" % (sliversipv6prefixtag) )
+                            logger.log("ipv6: the '%s' tag does not present a valid prefix (e.g., '/64', '/58')!" % \
+                                       (sliversipv6prefixtag))
                     else:
                         # connecting to the libvirtd
                         connLibvirt = Sliver_Libvirt.getConnection(type)
@@ -255,7 +277,7 @@ def GetSlivers(data, config, plc):
                                     tools.reboot_slivers()
                             else:
                                 logger.log("ipv6: starting to redefine the virtual network...")
-                                #network_elem = buildLibvirtDefaultNetConfig(dom,ipv6addr,prefix)
+                                #network_elem = buildLibvirtDefaultNetConfig(dom, ipv6addr, prefix)
                                 network_elem = add_ipv6(dom, ipv6addr, prefix)
                                 set_up(networkLibvirt, connLibvirt, network_elem, ipv6addr, prefix)
                                 logger.log("ipv6: trying to reboot the slivers...")