aboutsummaryrefslogtreecommitdiffstats
path: root/src/resource_inventory/resource_manager.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2021-10-15 17:03:58 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2021-10-28 15:32:26 -0400
commit104470ee008817df4a3b78d24e524e8c92eac9a0 (patch)
treea4a6b70043f34c37b568bbe6a4b6e72d8c619716 /src/resource_inventory/resource_manager.py
parentafcee3cad5c091e78e909b83f8df49accf1af5b6 (diff)
WIP merge of master into cobblercobbler
Squashed commit of the following: commit 35b9f39178cc502a5283a1b37a65f7dd0838ae05 Author: Sawyer Bergeron <sbergeron@iol.unh.edu> Date: Fri Oct 15 14:14:46 2021 -0400 Merge User Booking API Rev 1 (Try 3) Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> Change-Id: Ie1eee0a59929f8da39f16bb6bc17ae3de4f1cba9 Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> commit b3ed8ebcf536c021330e7ccbc0376f6b89189348 Author: Jacob Hodgdon <jhodgdon@iol.unh.edu> Date: Tue Jul 20 09:55:04 2021 -0400 Additional changes for rebrand Signed-off-by: Jacob Hodgdon <jhodgdon@iol.unh.edu> Change-Id: Ibd525f966b3ed3aebdbe688e5ee5daa4ea1cf294 Signed-off-by: Jacob Hodgdon <jhodgdon@iol.unh.edu> Signed-off-by: Raven Hodgdon <jhodgdon@iol.unh.edu> commit 17b6c7809771ac8bf3879add033d2169f671591a Author: Jacob Hodgdon <jhodgdon@iol.unh.edu> Date: Fri May 14 15:42:56 2021 -0400 Color fixes for rebrand Signed-off-by: Jacob Hodgdon <jhodgdon@iol.unh.edu> Change-Id: I5cf4ede598afa377db7ecec17d8dfef085e130ac Change-Id: I55494d24bcef74def85236b09168508e428d368e Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory/resource_manager.py')
-rw-r--r--src/resource_inventory/resource_manager.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py
index 14a118c..77fc3f8 100644
--- a/src/resource_inventory/resource_manager.py
+++ b/src/resource_inventory/resource_manager.py
@@ -6,20 +6,28 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import annotations
+
import re
+from typing import Optional
from django.db.models import Q
from dashboard.exceptions import ResourceAvailabilityException
from resource_inventory.models import (
+ Resource,
ResourceBundle,
ResourceTemplate,
+ ResourceConfiguration,
Network,
Vlan,
PhysicalNetwork,
InterfaceConfiguration,
)
+from account.models import Lab
+from django.contrib.auth.models import User
+
class ResourceManager:
@@ -29,19 +37,19 @@ class ResourceManager:
pass
@staticmethod
- def getInstance():
+ def getInstance() -> ResourceManager:
if ResourceManager.instance is None:
ResourceManager.instance = ResourceManager()
return ResourceManager.instance
- def getAvailableResourceTemplates(self, lab, user=None):
+ def getAvailableResourceTemplates(self, lab: Lab, user: Optional[User] = None) -> list[ResourceTemplate]:
filter = Q(public=True)
if user:
filter = filter | Q(owner=user)
filter = filter & Q(temporary=False) & Q(lab=lab)
return ResourceTemplate.objects.filter(filter)
- def templateIsReservable(self, resource_template):
+ def templateIsReservable(self, resource_template: ResourceTemplate):
"""
Check if the required resources to reserve this template is available.
@@ -63,13 +71,16 @@ class ResourceManager:
return True
# public interface
- def deleteResourceBundle(self, resourceBundle):
+ def deleteResourceBundle(self, resourceBundle: ResourceBundle):
raise NotImplementedError("Resource Bundle Deletion Not Implemented")
- def releaseResourceBundle(self, resourceBundle):
+ def releaseResourceBundle(self, resourceBundle: ResourceBundle):
resourceBundle.release()
- def get_vlans(self, resourceTemplate):
+ def get_vlans(self, resourceTemplate: ResourceTemplate) -> dict[str, int]:
+ """
+ returns: dict from network name to the associated vlan number (backend vlan id)
+ """
networks = {}
vlan_manager = resourceTemplate.lab.vlan_manager
for network in resourceTemplate.networks.all():
@@ -85,7 +96,7 @@ class ResourceManager:
networks[network.name] = vlans[0]
return networks
- def instantiateTemplate(self, resource_template):
+ def instantiateTemplate(self, resource_template: ResourceTemplate):
"""
Convert a ResourceTemplate into a ResourceBundle.
@@ -114,16 +125,18 @@ class ResourceManager:
return resource_bundle
- def configureNetworking(self, resource_bundle, resource, vlan_map):
+ def configureNetworking(self, resource_bundle: ResourceBundle, resource: Resource, vlan_map: dict[str, int]):
+ """
+ @vlan_map: dict from network name to the associated vlan number (backend vlan id)
+ """
for physical_interface in resource.interfaces.all():
- # assign interface configs
- iface_configs = InterfaceConfiguration.objects.filter(
+ # assign interface configs
+ iface_config = InterfaceConfiguration.objects.get(
profile=physical_interface.profile,
resource_config=resource.config
)
- iface_config = iface_configs.first()
physical_interface.acts_as = iface_config
physical_interface.acts_as.save()
@@ -144,7 +157,7 @@ class ResourceManager:
)
# private interface
- def acquireHost(self, resource_config):
+ def acquireHost(self, resource_config: ResourceConfiguration) -> Resource:
resources = resource_config.profile.get_resources(
lab=resource_config.template.lab,
unreserved=True