X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fupdate_ipv6addr_slivertag.py;h=d9e8094f474b13ff3c2f0681f90e798d6aa34cbe;hb=bedf4d3c114fa912a3533d325a366abfb458a36e;hp=3f63c2d39fbe131754aa63e8f35658a645d3f2f5;hpb=6694af7c6aae1c0274a8e67b690d4d38e36e7eac;p=nodemanager.git diff --git a/plugins/update_ipv6addr_slivertag.py b/plugins/update_ipv6addr_slivertag.py index 3f63c2d..d9e8094 100644 --- a/plugins/update_ipv6addr_slivertag.py +++ b/plugins/update_ipv6addr_slivertag.py @@ -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 """ @@ -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,10 +37,23 @@ 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']) ) + #logger.log("update_ipv6addr_slivertag: starting with slice=%s" % (slice['name']) ) + + # 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 add on it as well? + # 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']) @@ -42,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) @@ -62,8 +81,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: @@ -83,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!")