summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dashboard/tasks.py3
-rw-r--r--src/resource_inventory/models.py20
-rw-r--r--src/resource_inventory/resource_manager.py7
3 files changed, 23 insertions, 7 deletions
diff --git a/src/dashboard/tasks.py b/src/dashboard/tasks.py
index b980799..50e64c8 100644
--- a/src/dashboard/tasks.py
+++ b/src/dashboard/tasks.py
@@ -14,7 +14,6 @@ from django.utils import timezone
from booking.models import Booking
from notifier.manager import NotificationHandler
from api.models import Job, JobStatus, SoftwareRelation, HostHardwareRelation, HostNetworkRelation, AccessRelation
-from resource_inventory.resource_manager import ResourceManager
from resource_inventory.models import ConfigState
@@ -75,4 +74,4 @@ def free_hosts():
resource__isnull=False
)
for booking in bookings:
- ResourceManager.getInstance().deleteResourceBundle(booking.resource)
+ booking.resource.release()
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):
diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py
index 9300040..81f4747 100644
--- a/src/resource_inventory/resource_manager.py
+++ b/src/resource_inventory/resource_manager.py
@@ -102,7 +102,7 @@ class ResourceManager:
phys_res.config = config
resources.append(phys_res)
- self.configureNetworking(phys_res, vlan_map)
+ self.configureNetworking(resource_bundle, phys_res, vlan_map)
phys_res.save()
except Exception as e:
@@ -111,7 +111,7 @@ class ResourceManager:
return resource_bundle
- def configureNetworking(self, resource, vlan_map):
+ def configureNetworking(self, resource_bundle, resource, vlan_map):
for physical_interface in resource.interfaces.all():
# assign interface configs
@@ -128,7 +128,8 @@ class ResourceManager:
for connection in iface_config.connections.all():
physicalNetwork = PhysicalNetwork.objects.create(
vlan_id=vlan_map[connection.network.name],
- generic_network=connection.network
+ generic_network=connection.network,
+ bundle=resource_bundle,
)
physical_interface.config.add(
Vlan.objects.create(