"""
-IPv6 test! version: 0.3
+Description: IPv6 Support and Management to Slices
+ipv6 nodemanager plugin
+Version: 0.5
+Author: Guilherme Sperb Machado <gsm@machados.org>
"""
import logger
priority=4
radvdConfFile = '/etc/radvd.conf'
-ipv6addrtag = 'ipv6_address'
def start():
logger.log("ipv6: plugin starting up...")
# build the whole thing
natElem.appendChild(portElem)
forwardElem.appendChild(natElem)
-
+
dhcpElem.appendChild(rangeElem)
ipElem0.appendChild(dhcpElem)
networkElem.appendChild(nameElem)
logger.log("ipv6: the configuration already have an IPv6 address/prefix set for the slivers! %s/%s" % (ip.getAttribute('address'), ip.getAttribute('prefix')) )
hasIPv6 = True
return hasIPv6
-
+
def addIPv6(defaultNetworkConfig, ipv6addr, prefix):
ip.setAttribute("address", ipv6addr)
ip.setAttribute("prefix", prefix)
return dom
-
+
def removeIPv6(dom):
networks = dom.getElementsByTagName('network')
if ip.getAttribute("family")=='ipv6':
network.removeChild(ip)
return dom
-
+
def checkIfIPv6IsDifferent(dom, ipv6addr, prefix):
netnodes = dom.getElementsByTagName('network')
logger.log("ipv6: set up process finalized. Enabled IPv6 address to the slivers!")
def cleanUp(networkLibvirt, connLibvirt, networkElem):
- dom = removeIPv6(networkElem)
- newXml = dom.toxml()
- networkLibvirt.undefine()
- networkLibvirt.destroy()
- # TODO: set autostart for the network
- connLibvirt.networkCreateXML(newXml)
- networkDefault = connLibvirt.networkDefineXML(newXml)
- setAutostart(networkDefault)
- killRadvd()
- logger.log("ipv6: cleanup process finalized. The IPv6 support on the slivers was removed.")
+ dom = removeIPv6(networkElem)
+ newXml = dom.toxml()
+ networkLibvirt.undefine()
+ networkLibvirt.destroy()
+ # TODO: set autostart for the network
+ connLibvirt.networkCreateXML(newXml)
+ networkDefault = connLibvirt.networkDefineXML(newXml)
+ setAutostart(networkDefault)
+ killRadvd()
+ logger.log("ipv6: cleanup process finalized. The IPv6 support on the slivers was removed.")
def killRadvd():
- commandKillRadvd = ['killall', 'radvd']
- logger.log_call(commandKillRadvd, timeout=15*60)
+ commandKillRadvd = ['killall', 'radvd']
+ logger.log_call(commandKillRadvd, timeout=15*60)
def startRadvd():
commandRadvd = ['radvd']
logger.log_call(commandRadvd, timeout=15*60)
-def getSliverTagId(slivertags):
- for slivertag in slivertags:
- if slivertag['tagname']==ipv6addrtag:
- return slivertag['slice_tag_id']
-
-
-def SetSliverTag(plc, data, tagname):
-
- for sliver in data['slivers']:
- # TODO: what about the prefixlen? should we add on it as well?
- # here, I'm just taking the ipv6addr (value)
- value,prefixlen = tools.get_sliver_ipv6(sliver['name'])
-
- node_id = tools.node_id()
- logger.log("ipv6: slice %s" % (slice) )
- logger.log("ipv6: nodeid %s" % (node_id) )
- 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)))
-
- ipv6addr = plc.GetSliceIPv6Address(slice['name'])
- # if the value to set is null...
- if value is None:
- if ipv6addr is not None or len(ipv6addr)==0:
- # then, let's remove the slice tag
- slivertag_id = getSliverTagId(slivertags)
- plc.DeleteSliceTag(slivertag_id)
- else:
- # if the ipv6 addr set on the slice does not exist yet, so, let's add it
- if (len(ipv6addr)==0 or ipv6addr is None) and len(value)>0:
- try:
- slivertag_id=plc.AddSliceTag(slice['name'],tagname,value,node_id)
- logger.log("ipv6: slice tag added to slice %s" % (slice['name']) )
- except:
- logger.log_exc ("ipv6: could not set ipv6 addr tag to the slive. slice=%(slice['name'])s tag=%(tagname)s node_id=%(node_id)d" % locals() )
- # if the ipv6 addr set on the slice is different on the value provided, let's update it
- if len(value)>0 and ipv6addr!=value:
- #slivertag_id=slivertags[0]['slice_tag_id']
- slivertag_id = getSliverTagId(slivertags)
- plc.UpdateSliceTag(slivertag_id,value)
-
-
def GetSlivers(data, config, plc):
#return
#logger.log("tools: result=%s" % (str(result)) )
#tools.remove_all_ipv6addr_hosts(sliver['name'], data['hostname'])
#return
-
+
type = 'sliver.LXC'
logger.log('ipv6: get interface 1: %r'%(interface))
if 'interface_tag_ids' in interface:
interface_tag_ids = "interface_tag_ids"
- interface_tag_id = "interface_tag_id"
- settings = plc.GetInterfaceTags({interface_tag_id:interface[interface_tag_ids]})
- isSliversIPv6PrefixSet = False
- for setting in settings:
+ interface_tag_id = "interface_tag_id"
+ settings = plc.GetInterfaceTags({interface_tag_id:interface[interface_tag_ids]})
+ isSliversIPv6PrefixSet = False
+ for setting in settings:
#logger.log(repr(setting))
+ # TODO: create a static variable to describe the "sliversipv6prefix" tag
if setting['tagname']=='sliversipv6prefix':
ipv6addrprefix = setting['value'].split('/', 1)
ipv6addr = ipv6addrprefix[0]
logger.log("ipv6: trying to reboot the slivers...")
tools.reboot_sliver('blah')
isSliversIPv6PrefixSet = True
- if not(isSliversIPv6PrefixSet):
+ if not(isSliversIPv6PrefixSet):
# connecting to the libvirtd
connLibvirt = Sliver_Libvirt.getConnection(type)
list = connLibvirt.listAllNetworks()