+class NetworkSlice(PlCoreBase):
+ # This object exists solely so we can implement the permission check when
+ # adding slices to networks. It adds no additional fields to the relation.
+
+ network = models.ForeignKey(Network)
+ slice = models.ForeignKey(Slice)
+
+ def save(self, *args, **kwds):
+ slice = self.slice
+ if (slice not in self.network.permittedSlices.all()) and (slice != self.network.owner) and (not self.network.permitAllSlices):
+ # to add a sliver to the network, then one of the following must be true:
+ # 1) sliver's slice is in network's permittedSlices list,
+ # 2) sliver's slice is network's owner, or
+ # 3) network's permitAllSlices is true
+ raise ValueError("Slice %s is not allowed to connect to network %s" % (str(slice), str(self.network)))
+
+ super(NetworkSlice, self).save(*args, **kwds)
+
+ def __unicode__(self): return u'%s-%s' % (self.network.name, self.slice.name)
+