2 Description: Update the IPv6 Address sliver tag accordingly to the IPv6 address set
3 update_ipv6addr_slivertag nodemanager plugin
5 Author: Guilherme Sperb Machado <gsm@machados.org>
15 #from xml.dom.minidom import parseString
17 # TODO: is there anything better to do if the "libvirt", "sliver_libvirt",
18 # and are not in place in the VS distro?
21 from sliver_libvirt import Sliver_Libvirt
23 logger.log("Could not import 'sliver_lxc' or 'libvirt'.")
27 ipv6addrtag = 'ipv6_address'
30 logger.log("update_ipv6addr_slivertag: plugin starting up...")
33 def get_sliver_tag_id_value(slivertags):
34 for slivertag in slivertags:
35 if slivertag['tagname']==ipv6addrtag:
36 return slivertag['slice_tag_id'], slivertag['value']
38 def SetSliverTag(plc, data, tagname):
40 virt=tools.get_node_virt()
44 for slice in data['slivers']:
45 #logger.log("update_ipv6addr_slivertag: starting with slice={}".format(slice['name']))
47 # Check if the slice to be processed in a "system" slice
48 # If so, just loop to the next slice
50 for attribute in slice['attributes']:
51 if attribute['tagname']=='system' and attribute['value']=='1':
54 if system_slice: continue
56 # TODO: what about the prefixlen? Should we also inform the prefixlen?
57 # here, I'm just taking the ipv6addr (value)
58 value, prefixlen = tools.get_sliver_ipv6(slice['name'])
60 node_id = tools.node_id()
61 slivertags = plc.GetSliceTags({"name":slice['name'], "node_id":node_id, "tagname":tagname})
62 #logger.log(repr(str(slivertags)))
63 #for tag in slivertags:
64 # logger.log(repr(str(tag)))
67 slivertag_id, ipv6addr = get_sliver_tag_id_value(slivertags)
69 slivertag_id, ipv6addr = None, None
71 logger.log("update_ipv6addr_slivertag: slice={} getSliceIPv6Address={}"
72 .format(slice['name'], ipv6addr))
73 # if the value to set is null...
75 if ipv6addr is not None:
76 # then, let's remove the slice tag
79 plc.DeleteSliceTag(slivertag_id)
80 logger.log("update_ipv6addr_slivertag: slice tag deleted for slice={}"
81 .format(slice['name']))
83 logger.log("update_ipv6addr_slivertag: slice tag not deleted for slice={}"
84 .format(slice['name']))
85 result = tools.search_ipv6addr_hosts(slice['name'], value)
87 # if there's any ipv6 address, then remove everything from the /etc/hosts
88 tools.remove_all_ipv6addr_hosts(slice['name'], data['hostname'])
90 # if the ipv6 addr set on the slice does not exist yet, so, let's add it
91 if (ipv6addr is None) and len(value)>0:
93 logger.log("update_ipv6addr_slivertag: slice name={}".format(slice['name']))
94 slivertag_id=plc.AddSliceTag(slice['name'], tagname, value, node_id)
95 logger.log("update_ipv6addr_slivertag: slice tag added to slice {}"
96 .format(slice['name']))
98 logger.log("update_ipv6addr_slivertag: could not set ipv6 addr tag to sliver. "
99 "slice={} tag={} node_id={}".format(slice['name'], tagname, node_id))
100 # if the ipv6 addr set on the slice is different on the value provided, let's update it
101 if (ipv6addr is not None) and (len(value) > 0) and (ipv6addr != value):
102 plc.UpdateSliceTag(slivertag_id, value)
103 # ipv6 entry on /etc/hosts of each slice
104 result = tools.search_ipv6addr_hosts(slice['name'], value)
106 tools.remove_all_ipv6addr_hosts(slice['name'], data['hostname'])
107 tools.add_ipv6addr_hosts_line(slice['name'], data['hostname'], value)
108 #logger.log("update_ipv6addr_slivertag: finishing the update process for "
109 # "slice={}".format(slice['name']))
111 def GetSlivers(data, config, plc):
112 SetSliverTag(plc, data, ipv6addrtag)