X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fmodels%2Fnetwork.py;h=c7a97a99d09c7437e921b629c2548a9f813f6abb;hb=451c4fc73c5fbb698af6e67e9488c1e7d167d209;hp=3c5a19b8bec6a35d9561c965cf45680e667cdc43;hpb=f4612de67d2f00fe21b3a4b161034259fdf8ab4d;p=plstackapi.git diff --git a/planetstack/core/models/network.py b/planetstack/core/models/network.py index 3c5a19b..c7a97a9 100644 --- a/planetstack/core/models/network.py +++ b/planetstack/core/models/network.py @@ -1,8 +1,9 @@ import os import socket +import sys from django.db import models -from core.models import PlCoreBase, Site, Slice, Sliver, Deployment -from core.models import DeploymentLinkManager,DeploymentLinkDeletionManager +from core.models import PlCoreBase, Site, Slice, Sliver, Controller +from core.models import ControllerLinkManager,ControllerLinkDeletionManager from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django.core.exceptions import ValidationError @@ -65,14 +66,33 @@ def ValidateNatList(ports): class NetworkTemplate(PlCoreBase): VISIBILITY_CHOICES = (('public', 'public'), ('private', 'private')) TRANSLATION_CHOICES = (('none', 'none'), ('NAT', 'NAT')) + TOPOLOGY_CHOICES = (('bigswitch', 'BigSwitch'), ('physical', 'Physical'), ('custom', 'Custom')) + CONTROLLER_CHOICES = ((None, 'None'), ('onos', 'ONOS'), ('custom', 'Custom')) name = models.CharField(max_length=32) description = models.CharField(max_length=1024, blank=True, null=True) - guaranteedBandwidth = models.IntegerField(default=0) + guaranteed_bandwidth = models.IntegerField(default=0) visibility = models.CharField(max_length=30, choices=VISIBILITY_CHOICES, default="private") translation = models.CharField(max_length=30, choices=TRANSLATION_CHOICES, default="none") - sharedNetworkName = models.CharField(max_length=30, blank=True, null=True) - sharedNetworkId = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum network") + shared_network_name = models.CharField(max_length=30, blank=True, null=True) + shared_network_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum network") + topology_kind = models.CharField(null=False, blank=False, max_length=30, choices=TOPOLOGY_CHOICES, default="BigSwitch") + controller_kind = models.CharField(null=True, blank=True, max_length=30, choices=CONTROLLER_CHOICES, default=None) + + def __init__(self, *args, **kwargs): + super(NetworkTemplate, self).__init__(*args, **kwargs) + + # somehow these got set wrong inside of the live database. Remove this + # code after all is well... + if (self.topology_kind=="BigSwitch"): + print >> sys.stderr, "XXX warning: topology_kind invalid case" + self.topology_kind="bigswitch" + elif (self.topology_kind=="Physical"): + print >> sys.stderr, "XXX warning: topology_kind invalid case" + self.topology_kind="physical" + elif (self.topology_kind=="Custom"): + print >> sys.stderr, "XXX warning: topology_kind invalid case" + self.toplogy_kind="custom" def __unicode__(self): return u'%s' % (self.name) @@ -84,12 +104,16 @@ class Network(PlCoreBase): labels = models.CharField(max_length=1024, blank=True, null=True) owner = models.ForeignKey(Slice, related_name="ownedNetworks", help_text="Slice that owns control of this Network") - guaranteedBandwidth = models.IntegerField(default=0) - permitAllSlices = models.BooleanField(default=False) - permittedSlices = models.ManyToManyField(Slice, blank=True, related_name="availableNetworks") + guaranteed_bandwidth = models.IntegerField(default=0) + permit_all_slices = models.BooleanField(default=False) + permitted_slices = models.ManyToManyField(Slice, blank=True, related_name="availableNetworks") slices = models.ManyToManyField(Slice, blank=True, related_name="networks", through="NetworkSlice") slivers = models.ManyToManyField(Sliver, blank=True, related_name="networks", through="NetworkSliver") + topology_parameters = models.TextField(null=True, blank=True) + controller_url = models.CharField(null=True, blank=True, max_length=1024) + controller_parameters = models.TextField(null=True, blank=True) + # for observer/manager network_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum network") router_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum router id") @@ -120,13 +144,13 @@ class Network(PlCoreBase): qs = Network.objects.filter(owner__in=slices) return qs -class NetworkDeployments(PlCoreBase): - objects = DeploymentLinkManager() - deleted_objects = DeploymentLinkDeletionManager() +class ControllerNetwork(PlCoreBase): + objects = ControllerLinkManager() + deleted_objects = ControllerLinkDeletionManager() - # Stores the openstack ids at various deployments - network = models.ForeignKey(Network, related_name='networkdeployments') - deployment = models.ForeignKey(Deployment, related_name='networkdeployments') + # Stores the openstack ids at various controllers + network = models.ForeignKey(Network, related_name='controllernetworks') + controller = models.ForeignKey(Controller, related_name='controllernetworks') net_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum network") router_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum router id") subnet_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum subnet id") @@ -138,11 +162,11 @@ class NetworkDeployments(PlCoreBase): @staticmethod def select_by_user(user): if user.is_admin: - qs = NetworkDeployments.objects.all() + qs = NetworkControllers.objects.all() else: slices = Slice.select_by_user(user) networks = Network.objects.filter(owner__in=slices) - qs = NetworkDeployments.objects.filter(network__in=networks) + qs = NetworkControllers.objects.filter(network__in=networks) return qs class NetworkSlice(PlCoreBase): @@ -154,7 +178,7 @@ class NetworkSlice(PlCoreBase): 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): + if (slice not in self.network.permitted_slices.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 @@ -185,7 +209,7 @@ class NetworkSliver(PlCoreBase): def save(self, *args, **kwds): slice = self.sliver.slice - if (slice not in self.network.permittedSlices.all()) and (slice != self.network.owner) and (not self.network.permitAllSlices): + if (slice not in self.network.permitted_slices.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