aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2020-10-22 13:06:39 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2020-10-22 14:45:02 -0400
commit9f426a2ab31b60383e1c73fb2948c06656435ba3 (patch)
treeccb691918d0da26cd8cc17f7f2f6208b5f9f7b62
parentf7ae02595a6f84ecfa4e5bbac91a0b17f275482a (diff)
Fix quick booking allocation of private vlans for pods
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> Change-Id: Ie515da2c28fcbc51d8fa87e24a3ff64c234d1bee Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
-rw-r--r--src/account/models.py6
-rw-r--r--src/dashboard/testing_utils.py8
-rw-r--r--src/resource_inventory/resource_manager.py7
-rw-r--r--src/workflow/resource_bundle_workflow.py2
4 files changed, 12 insertions, 11 deletions
diff --git a/src/account/models.py b/src/account/models.py
index 2d0293f..40de4d8 100644
--- a/src/account/models.py
+++ b/src/account/models.py
@@ -80,12 +80,12 @@ class VlanManager(models.Model):
# if they use QinQ or a vxlan overlay, for example
allow_overlapping = models.BooleanField()
- def get_vlan(self, count=1):
+ def get_vlans(self, count=1):
"""
- Return the ID of available vlans, but does not reserve them.
+ Return the IDs of available vlans as a list[int], but does not reserve them.
Will throw index exception if not enough vlans are available.
- If count == 1, the return value is an int. Otherwise, it is a list of ints.
+ Always returns a list of ints
"""
allocated = []
vlans = json.loads(self.vlans)
diff --git a/src/dashboard/testing_utils.py b/src/dashboard/testing_utils.py
index d7a346e..5be6379 100644
--- a/src/dashboard/testing_utils.py
+++ b/src/dashboard/testing_utils.py
@@ -96,11 +96,11 @@ def make_network(name, lab, grb, public):
lab.vlan_manager.reserve_public_vlan(public_net.vlan)
network.vlan_id = public_net.vlan
else:
- private_net = lab.vlan_manager.get_vlan()
- if not private_net:
+ private_nets = lab.vlan_manager.get_vlans(count=1)
+ if not private_nets:
raise Exception("No more generic vlans are available")
- lab.vlan_manager.reserve_vlans([private_net])
- network.vlan_id = private_net
+ lab.vlan_manager.reserve_vlans(private_nets)
+ network.vlan_id = private_nets[0]
network.save()
return network
diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py
index 81f4747..140cc09 100644
--- a/src/resource_inventory/resource_manager.py
+++ b/src/resource_inventory/resource_manager.py
@@ -77,9 +77,10 @@ class ResourceManager:
vlan_manager.reserve_public_vlan(public_net.vlan)
networks[network.name] = public_net.vlan
else:
- vlan = vlan_manager.get_vlan()
- vlan_manager.reserve_vlans(vlan)
- networks[network.name] = vlan
+ # already throws if can't get requested count, so can always index in @ 0
+ vlans = vlan_manager.get_vlans(count=1)
+ vlan_manager.reserve_vlans(vlans[0])
+ networks[network.name] = vlans[0]
return networks
def instantiateTemplate(self, resource_template):
diff --git a/src/workflow/resource_bundle_workflow.py b/src/workflow/resource_bundle_workflow.py
index 404224e..63a9519 100644
--- a/src/workflow/resource_bundle_workflow.py
+++ b/src/workflow/resource_bundle_workflow.py
@@ -294,7 +294,7 @@ class Define_Nets(WorkflowStep):
if lab is None or lab.vlan_manager is None:
return None
try:
- vlans = lab.vlan_manager.get_vlan(count=lab.vlan_manager.block_size)
+ vlans = lab.vlan_manager.get_vlans(count=lab.vlan_manager.block_size)
self.repo_put(self.repo.VLANS, vlans)
return vlans
except Exception: