+ #################### provisioning vlan_ids
+ # retrieve all alive slices
+ alive_slices=Slices(self.api,{},['slice_id','name','slice_tag_ids'])
+ # build the list of their ids
+ alive_slices_ids = [ s['slice_id'] for s in alive_slices ]
+ # retrieve all the 'vlan_id' slice tags applying to these slice_ids
+ vlan_slice_tags = SliceTags (self.api,{'slice_id':alive_slices_ids,'tagname':'vlan_id'})
+ # hash them by the slice_tag_id
+ vlan_slice_tags_hashed_by_id = { slice_tag['slice_tag_id']:slice_tag for slice_tag in vlan_slice_tags }
+ # build the set of allocated vlans
+ allocated_vlan_ids = set()
+ for alive_slice in alive_slices:
+ # scan all slice tags attached to that slice
+ for slice_tag_id in alive_slice['slice_tag_ids']:
+ # discard the one that are not 'vlan_id'
+ if slice_tag_id not in vlan_slice_tags_hashed_by_id: continue
+ # retrive value and convert to int
+ slice_tag = vlan_slice_tags_hashed_by_id[slice_tag_id]
+ if slice_tag['tagname']=='vlan_id':
+ try:
+ allocated_vlan_ids.add(int(slice_tag['value']))
+ except:
+ import traceback
+ traceback.print_exc()
+ pass
+ # find a free vlan_id
+ available=set(VLAN_RANGE) - allocated_vlan_ids
+ try:
+ assigned=available.pop()
+ # piggybacking the code below that sets tags; tags value need to be strings..
+ tags['vlan_id']=str(assigned)
+ except:
+ raise Exception,"Cannot allocate slice %s, ran out of vlan_ids"%name
+