aboutsummaryrefslogtreecommitdiffstats
path: root/src/dashboard
diff options
context:
space:
mode:
Diffstat (limited to 'src/dashboard')
-rw-r--r--src/dashboard/tasks.py40
-rw-r--r--src/dashboard/testing_utils.py3
-rw-r--r--src/dashboard/utils.py2
3 files changed, 9 insertions, 36 deletions
diff --git a/src/dashboard/tasks.py b/src/dashboard/tasks.py
index ac4d36f..b980799 100644
--- a/src/dashboard/tasks.py
+++ b/src/dashboard/tasks.py
@@ -15,43 +15,15 @@ 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
@shared_task
def booking_poll():
- def cleanup_hardware(qs):
+ def cleanup_resource_task(qs):
for hostrelation in qs:
- config = hostrelation.config
- config.clear_delta()
- config.power = "off"
- config.save()
- hostrelation.status = JobStatus.NEW
- hostrelation.save()
-
- def cleanup_network(qs):
- for hostrelation in qs:
- network = hostrelation.config
- network.interfaces.clear()
- host = hostrelation.host
- network.clear_delta()
- vlans = []
- for interface in host.interfaces.all():
- for vlan in interface.config.all():
- if vlan.public:
- try:
- host.lab.vlan_manager.release_public_vlan(vlan.vlan_id)
- except Exception: # will fail if we already released in this loop
- pass
- else:
- vlans.append(vlan.vlan_id)
-
- # release all vlans
- if len(vlans) > 0:
- host.lab.vlan_manager.release_vlans(vlans)
-
- interface.config.clear()
- network.add_interface(interface)
- network.save()
+ hostrelation.config.state = ConfigState.CLEAN
+ hostrelation.config.save()
hostrelation.status = JobStatus.NEW
hostrelation.save()
@@ -78,8 +50,8 @@ def booking_poll():
if not booking.job.complete:
job = booking.job
cleanup_software(SoftwareRelation.objects.filter(job=job))
- cleanup_hardware(HostHardwareRelation.objects.filter(job=job))
- cleanup_network(HostNetworkRelation.objects.filter(job=job))
+ cleanup_resource_task(HostHardwareRelation.objects.filter(job=job))
+ cleanup_resource_task(HostNetworkRelation.objects.filter(job=job))
cleanup_access(AccessRelation.objects.filter(job=job))
job.complete = True
job.save()
diff --git a/src/dashboard/testing_utils.py b/src/dashboard/testing_utils.py
index 506e998..b7272ea 100644
--- a/src/dashboard/testing_utils.py
+++ b/src/dashboard/testing_utils.py
@@ -277,7 +277,7 @@ def make_os(installers=None, name="test OS"):
def make_server(host_profile, lab, labid="test_host", name="test_host",
- booked=False, working=True, config=None, template=None,
+ booked=False, working=True, config=None,
bundle=None, model="Model 1", vendor="ACME"):
return Server.objects.create(
lab=lab,
@@ -286,7 +286,6 @@ def make_server(host_profile, lab, labid="test_host", name="test_host",
booked=booked,
working=working,
config=config,
- template=template,
bundle=bundle,
model=model,
vendor=vendor
diff --git a/src/dashboard/utils.py b/src/dashboard/utils.py
index 3d63366..d6b697a 100644
--- a/src/dashboard/utils.py
+++ b/src/dashboard/utils.py
@@ -34,6 +34,8 @@ class AbstractModelQuery():
for model in cls.model_list:
result += list(model.objects.filter(*args, **kwargs))
+ return result
+
@classmethod
def get(cls, *args, **kwargs):
try: