update code to use renamed network fields
[plstackapi.git] / planetstack / core / models / network.py
index d2e6411..554bbf5 100644 (file)
@@ -70,13 +70,28 @@ class NetworkTemplate(PlCoreBase):
 
     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")
-    topologyKind = models.CharField(null=False, blank=False, max_length=30, choices=TOPOLOGY_CHOICES, default="BigSwitch")
-    controllerKind = models.CharField(null=True, blank=True, max_length=30, choices=CONTROLLER_CHOICES, default=None)
+    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 "XXX warning: topology_kind invalid case"
+            self.topology_kind="bigswitch"
+        elif (self.topology_kind=="Physical"):
+            print "XXX warning: topology_kind invalid case"
+            self.topology_kind="physical"
+        elif (self.topology_kind=="Custom"):
+            print "XXX warning: topology_kind invalid case"
+            self.toplogy_kind="custom"
 
     def __unicode__(self):  return u'%s' % (self.name)
 
@@ -88,15 +103,15 @@ 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")
 
-    topologyParameters = models.TextField(null=True, blank=True)
-    controllerUrl = models.CharField(null=True, blank=True, max_length=1024)
-    controllerParameters = models.TextField(null=True, blank=True)
+    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")
@@ -162,7 +177,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
@@ -193,7 +208,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