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=%s" % (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
70 logger.log("update_ipv6addr_slivertag: slice=%s getSliceIPv6Address=%s" % \
71 (slice['name'],ipv6addr) )
72 # if the value to set is null...
74 if ipv6addr is not None:
75 # then, let's remove the slice tag
78 plc.DeleteSliceTag(slivertag_id)
79 logger.log("update_ipv6addr_slivertag: slice tag deleted for slice=%s" % \
82 logger.log("update_ipv6addr_slivertag: slice tag not deleted for slice=%s" % \
84 result = tools.search_ipv6addr_hosts(slice['name'], value)
86 # if there's any ipv6 address, then remove everything from the /etc/hosts
87 tools.remove_all_ipv6addr_hosts(slice['name'], data['hostname'])
89 # if the ipv6 addr set on the slice does not exist yet, so, let's add it
90 if (ipv6addr is None) and len(value)>0:
92 logger.log("update_ipv6addr_slivertag: slice name=%s" % (slice['name']) )
93 slivertag_id=plc.AddSliceTag(slice['name'],tagname,value,node_id)
94 logger.log("update_ipv6addr_slivertag: slice tag added to slice %s" % \
97 logger.log("update_ipv6addr_slivertag: could not set ipv6 addr tag to sliver. "+
98 "slice=%s tag=%s node_id=%d" % (slice['name'],tagname,node_id) )
99 # if the ipv6 addr set on the slice is different on the value provided, let's update it
100 if (ipv6addr is not None) and (len(value)>0) and (ipv6addr!=value):
101 plc.UpdateSliceTag(slivertag_id,value)
102 # ipv6 entry on /etc/hosts of each slice
103 result = tools.search_ipv6addr_hosts(slice['name'], value)
105 tools.remove_all_ipv6addr_hosts(slice['name'], data['hostname'])
106 tools.add_ipv6addr_hosts_line(slice['name'], data['hostname'], value)
107 #logger.log("update_ipv6addr_slivertag: finishing the update process for " +
108 # "slice=%s" % (slice['name']) )
110 def GetSlivers(data, config, plc):
111 SetSliverTag(plc, data, ipv6addrtag)