enforce choices in network.access
diff --git a/xos/core/models/network.py b/xos/core/models/network.py
index bb11307..a019091 100644
--- a/xos/core/models/network.py
+++ b/xos/core/models/network.py
@@ -110,7 +110,7 @@
access = models.CharField(max_length=30, null=True, blank=True, choices=ACCESS_CHOICES, help_text="Advertise this network as a means for other slices to contact this slice")
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")
+ 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):
@@ -128,6 +128,10 @@
print >> sys.stderr, "XXX warning: topology_kind invalid case"
self.toplogy_kind="custom"
+ def save(self, *args, **kwargs):
+ self.enforce_choices(self.access, self.ACCESS_CHOICES)
+ super(NetworkTemplate, self).save(*args, **kwargs)
+
def __unicode__(self): return u'%s' % (self.name)
class Network(PlCoreBase, ParameterMixin):
diff --git a/xos/core/models/plcorebase.py b/xos/core/models/plcorebase.py
index 1a2c37c..5878fff 100644
--- a/xos/core/models/plcorebase.py
+++ b/xos/core/models/plcorebase.py
@@ -132,6 +132,13 @@
else:
return ("error", html_escape(self.backend_status, quote=True))
+ def enforce_choices(self, field, choices):
+ choices = [x[0] for x in choices]
+ for choice in choices:
+ if field==choice:
+ return
+ raise Exception("Field value %s is not in %s" % (field, str(choices)))
+
class PlCoreBase(models.Model, PlModelMixIn):
objects = PlCoreBaseManager()
deleted_objects = PlCoreBaseDeletionManager()