- test = is_adjacent(adjacencies, site, adj)
- except Exception, e:
- print "Error: ", e, " Fix adjacencies!"
- return
-
-
-def get_site(nodeid):
- if nodes[nodeid]:
- return nodes[nodeid]['site_id']
- raise Exception("Nodeid %s not found." % nodeid)
-
-
-def get_ipaddr(nodeid):
- if nodes[nodeid]:
- return socket.gethostbyname(nodes[nodeid]['hostname'])
- raise Exception("Nodeid %s not found." % nodeid)
-
-
-def get_sitenodes(siteid):
- if sites[siteid]:
- return sites[siteid]['node_ids']
- raise Exception("Siteid %s not found." % siteid)
-
-
-def get_virt_ip(myid, nodeid):
- """
- Find the IP address assigned to a virtual interface in the topology
- (for creating /etc/hosts)
- """
- if myid < nodeid:
- virtip = "10.%d.%d.2" % (myid, nodeid)
- else:
- virtip = "10.%d.%d.3" % (nodeid, myid)
- return virtip
+ key = free_egre_key(slicetags)
+ self.update_tag('egre_key', key, slicetags)
+ except:
+ # Should handle this case...
+ pass
+ return
+
+ def turn_on_netns(self, slicetags):
+ tag = self.get_tag('netns', slicetags)
+ if (not tag) or (tag.value != '1'):
+ self.update_tag('netns', '1', slicetags)
+ return
+
+ def turn_off_netns(self, slicetags):
+ tag = self.get_tag('netns', slicetags)
+ if tag and (tag.value != '0'):
+ tag.delete()
+ return
+
+ def add_cap_net_admin(self, slicetags):
+ tag = self.get_tag('capabilities', slicetags)
+ if tag:
+ caps = tag.value.split(',')
+ for cap in caps:
+ if cap == "CAP_NET_ADMIN":
+ return
+ else:
+ newcaps = "CAP_NET_ADMIN," + tag.value
+ self.update_tag('capabilities', newcaps, slicetags)
+ else:
+ self.add_tag('capabilities', 'CAP_NET_ADMIN', slicetags)
+ return
+
+ def remove_cap_net_admin(self, slicetags):
+ tag = self.get_tag('capabilities', slicetags)
+ if tag:
+ caps = tag.value.split(',')
+ newcaps = []
+ for cap in caps:
+ if cap != "CAP_NET_ADMIN":
+ newcaps.append(cap)
+ if newcaps:
+ value = ','.join(newcaps)
+ self.update_tag('capabilities', value, slicetags)
+ else:
+ tag.delete()
+ return
+
+ # Update the vsys/setup-link and vsys/setup-nat slice tags.
+ def add_vsys_tags(self, slicetags):
+ link = nat = False
+ for i in self.slice_tag_ids:
+ tag = slicetags[i]
+ if tag.tagname == 'vsys':
+ if tag.value == 'setup-link':
+ link = True
+ elif tag.value == 'setup-nat':
+ nat = True
+ if not link:
+ self.add_tag('vsys', 'setup-link', slicetags)
+ if not nat:
+ self.add_tag('vsys', 'setup-nat', slicetags)
+ return
+
+
+class Slicetag:
+ newid = -1
+ def __init__(self, tag):
+ self.id = tag['slice_tag_id']
+ if not self.id:
+ # Make one up for the time being...
+ self.id = Slicetag.newid
+ Slicetag.newid -= 1
+ self.slice_id = tag['slice_id']
+ self.tagname = tag['tagname']
+ self.value = tag['value']
+ self.node_id = tag['node_id']
+ self.updated = False
+ self.changed = False
+ self.deleted = False
+
+ # Mark a tag as deleted
+ def delete(self):
+ self.deleted = True
+ self.updated = True
+
+ def write(self, slices, nodes, dryrun):
+ if not dryrun:
+ if self.changed:
+ if int(self.id) > 0:
+ UpdateSliceTag(self.id, self.value)
+ else:
+ AddSliceTag(self.slice_id, self.tagname, self.value, self.node_id)
+ elif self.deleted and int(self.id) > 0:
+ try:
+ DeleteSliceTag(self.id)
+ except:
+ print "[%s] %s: could not delete" % (self.id, self.tagname)
+ else:
+ try:
+ slice = slices[self.slice_id].name
+ except:
+ return
+ if self.node_id:
+ node = nodes[tag.node_id].hostname
+ if self.updated:
+ if self.deleted:
+ self.value = "deleted"
+ elif not self.changed:
+ self.value = "no change"
+ if int(self.id) < 0:
+ self.id = "new"
+ if self.node_id:
+ print "[%s] %s: %s (%s, %s)" % (self.id, self.tagname, self.value, slice, node)
+ else:
+ print "[%s] %s: %s (%s)" % (self.id, self.tagname, self.value, slice)