aboutsummaryrefslogtreecommitdiffstats
path: root/src/resource_inventory/models.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2020-08-07 14:49:11 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2020-08-07 15:11:53 -0400
commit0c71a0ce238a1ca816cec35b62e228a97102aa6a (patch)
treedec4a4c7b921548c8595744eeb66793c18cd1eeb /src/resource_inventory/models.py
parent7a202d78ab96e86acf9727edb908c0e9e24ea551 (diff)
Fix vlan deallocation and ownership
Change-Id: I74bd2d062611ba1ca997cfb50a91d2396e70526b Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory/models.py')
-rw-r--r--src/resource_inventory/models.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/resource_inventory/models.py b/src/resource_inventory/models.py
index 7a1f259..c918513 100644
--- a/src/resource_inventory/models.py
+++ b/src/resource_inventory/models.py
@@ -199,6 +199,13 @@ class ResourceBundle(models.Model):
# TODO
pass
+ def release(self):
+ for pn in PhysicalNetwork.objects.filter(bundle=self).all():
+ pn.release()
+
+ for resource in self.get_resources():
+ resource.release()
+
def get_template_name(self):
if not self.template:
return ""
@@ -401,6 +408,7 @@ class Network(models.Model):
class PhysicalNetwork(models.Model):
vlan_id = models.IntegerField()
generic_network = models.ForeignKey(Network, on_delete=models.CASCADE)
+ bundle = models.ForeignKey(ResourceBundle, null=True, on_delete=models.CASCADE)
def get_configuration(self, state):
"""
@@ -412,11 +420,19 @@ class PhysicalNetwork(models.Model):
def reserve(self):
"""Reserve vlan(s) associated with this network."""
- # vlan_manager = self.bundle.lab.vlan_manager
return False
def release(self):
- # vlan_manager = self.bundle.lab.vlan_manager
+ from booking.models import Booking
+
+ booking = Booking.objects.get(resource=self.bundle)
+ lab = booking.lab
+ vlan_manager = lab.vlan_manager
+
+ if self.generic_network.is_public:
+ vlan_manager.release_public_vlan(self.vlan_id)
+ else:
+ vlan_manager.release_vlans([self.vlan_id])
return False
def __str__(self):