only cosmetic
[nodemanager.git] / plugins / update_ipv6addr_slivertag.py
index 3f63c2d..ccf9490 100644 (file)
@@ -11,11 +11,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=150
 
 ipv6addrtag = 'ipv6_address'
@@ -31,6 +37,10 @@ def get_sliver_tag_id_value(slivertags):
 
 def SetSliverTag(plc, data, tagname):
 
+    virt=tools.get_node_virt()
+    if virt!='lxc':
+        return
+
     for slice in data['slivers']:
         logger.log("update_ipv6addr_slivertag: starting with slice=%s" % (slice['name']) )
 
@@ -62,8 +72,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: