-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)
-
-