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
resource__isnull=False
)
for booking in bookings:
- ResourceManager.getInstance().deleteResourceBundle(booking.resource)
+ booking.resource.release()
# 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 ""
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):
"""
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):
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:
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
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(