aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2020-07-28 16:12:39 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2020-07-28 16:29:25 -0400
commitaddc7325e82f7b011180219b6d218798780b7180 (patch)
tree63ea59e9b7bd64cdfce425532de464a9d1d9ec80
parent32909ee3b27f964efd33f9c4b5607d9b1309e9c7 (diff)
Fix vlan allocation for reserved vlans and multiple allocation
This also fixes quick booking duplication for this case Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> Change-Id: Ibad51fbeca8529c0f4f38cfcdf0ab0f5e4b7bf31 Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
-rw-r--r--src/account/models.py31
-rw-r--r--src/booking/quick_deployer.py2
2 files changed, 24 insertions, 9 deletions
diff --git a/src/account/models.py b/src/account/models.py
index 03b31df..5d83ddf 100644
--- a/src/account/models.py
+++ b/src/account/models.py
@@ -16,6 +16,8 @@ import random
from collections import Counter
+from dashboard.exceptions import ResourceAvailabilityException
+
class LabStatus(object):
"""
@@ -87,13 +89,24 @@ class VlanManager(models.Model):
"""
allocated = []
vlans = json.loads(self.vlans)
- for i in range(count):
- new_vlan = vlans.index(1) # will throw if none available
- vlans[new_vlan] = 0
- allocated.append(new_vlan)
- if count == 1:
- return allocated[0]
- return allocated
+ reserved = json.loads(self.reserved_vlans)
+
+ for i in range(0, len(vlans) - 1):
+ if len(allocated) >= count:
+ break
+
+ if vlans[i] == 0 and self.allow_overlapping is False:
+ continue
+
+ if reserved[i] == 1:
+ continue
+
+ # vlan is available and not reserved, so safe to add
+ allocated.append(i)
+ continue
+
+ if len(allocated) != count:
+ raise ResourceAvailabilityException("can't allocate the vlans requested")
def get_public_vlan(self):
"""Return reference to an available public network without reserving it."""
@@ -171,6 +184,8 @@ class VlanManager(models.Model):
"""
my_vlans = json.loads(self.vlans)
+ reserved = json.loads(self.reserved_vlans)
+
try:
iter(vlans)
except Exception:
@@ -179,7 +194,7 @@ class VlanManager(models.Model):
vlans = set(vlans)
for vlan in vlans:
- if my_vlans[vlan] == 0:
+ if my_vlans[vlan] == 0 or reserved[vlan] == 1:
raise ValueError("vlan " + str(vlan) + " is not available")
my_vlans[vlan] = 0
diff --git a/src/booking/quick_deployer.py b/src/booking/quick_deployer.py
index 0d4e5ea..8b3af6c 100644
--- a/src/booking/quick_deployer.py
+++ b/src/booking/quick_deployer.py
@@ -87,7 +87,7 @@ def update_template(old_template, image, hostname, user):
Network.objects.create(
name=old_network.name,
bundle=template,
- is_public=False
+ is_public=old_network.is_public
)
# We are assuming there is only one opnfv config per public resource template
old_opnfv = template.opnfv_config.first()