aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/models.py29
-rw-r--r--src/booking/views.py11
-rw-r--r--src/templates/base.html5
3 files changed, 32 insertions, 13 deletions
diff --git a/src/api/models.py b/src/api/models.py
index e4016aa..b14ea2f 100644
--- a/src/api/models.py
+++ b/src/api/models.py
@@ -604,7 +604,7 @@ class SnapshotConfig(TaskConfig):
def get_task(task_id):
- for taskclass in [AccessRelation, SoftwareRelation, HostHardwareRelation, HostNetworkRelation]:
+ for taskclass in [AccessRelation, SoftwareRelation, HostHardwareRelation, HostNetworkRelation, SnapshotRelation]:
try:
ret = taskclass.objects.get(task_id=task_id)
return ret
@@ -704,6 +704,33 @@ class SnapshotRelation(TaskRelation):
class JobFactory(object):
@classmethod
+ def reimageHost(cls, new_image, booking, host):
+ """
+ This method will make all necessary changes to make a lab
+ reimage a host.
+ """
+ job = Job.objects.get(booking=booking)
+ # make hardware task new
+ hardware_relation = HostHardwareRelation.objects.get(host=host, job=job)
+ hardware_relation.config.set_image(new_image.lab_id)
+ hardware_relation.config.save()
+ hardware_relation.status = JobStatus.NEW
+
+ # re-apply networking after host is reset
+ net_relation = HostNetworkRelation.objects.get(host=host, job=job)
+ net_relation.status = JobStatus.NEW
+
+ # re-apply ssh access after host is reset
+ ssh_relation = AccessRelation.objects.get(job=job, config__access_type="ssh")
+ ssh_relation.status = JobStatus.NEW
+
+ # save them all at once to reduce the chance
+ # of a lab polling and only seeing partial change
+ hardware_relation.save()
+ net_relation.save()
+ ssh_relation.save()
+
+ @classmethod
def makeSnapshotTask(cls, image, booking, host):
relation = SnapshotRelation()
job = Job.objects.get(booking=booking)
diff --git a/src/booking/views.py b/src/booking/views.py
index 3be9c7b..1e14b8e 100644
--- a/src/booking/views.py
+++ b/src/booking/views.py
@@ -23,7 +23,7 @@ from account.models import Lab
from booking.models import Booking
from booking.stats import StatisticsManager
from booking.forms import HostReImageForm
-from api.models import HostHardwareRelation, JobStatus
+from api.models import JobFactory
from workflow.views import login
from booking.forms import QuickBookingForm
from booking.quick_deployer import create_from_form, drop_filter
@@ -179,12 +179,9 @@ def booking_modify_image(request, booking_id):
return HttpResponse("unauthorized")
new_image = Image.objects.get(id=form.cleaned_data['image_id'])
host = Host.objects.get(id=form.cleaned_data['host_id'])
- relation = HostHardwareRelation.objects.get(host=host, job__booking=booking)
- config = relation.config
- config.set_image(new_image.lab_id)
- config.save()
- relation.status = JobStatus.NEW
- relation.save()
+ host.config.image = new_image
+ host.config.save()
+ JobFactory.reimageHost(new_image, booking, host)
return HttpResponse(new_image.name)
return HttpResponse("error")
diff --git a/src/templates/base.html b/src/templates/base.html
index f7fa7cd..02c67dc 100644
--- a/src/templates/base.html
+++ b/src/templates/base.html
@@ -158,11 +158,6 @@
class="fa fa-fw"></i>Booking Statistics</a>
</li>
<li>
- <a href="{% url 'api-root' %}"><i
- class="fa fa-fw"></i>API
- </a>
- </li>
- <li>
<a href="{% url 'account:my-account' %}"><i
class="fa fa-fw"></i>Account
</a>