From bf13ea4e6d585afcad789a7b56956469453a2f73 Mon Sep 17 00:00:00 2001 From: Parker Berberian Date: Wed, 23 Jan 2019 13:47:56 -0500 Subject: Fix Reimaging Hosts When a User wants to reimage a host, the dashboard needs to also refresh the network and ssh configurations. Otherwise a host is reimaged and becomes unreachable. Change-Id: I534f200498c9217bda81190861021c482e052a81 Signed-off-by: Parker Berberian --- dashboard/src/api/models.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'dashboard/src/api') diff --git a/dashboard/src/api/models.py b/dashboard/src/api/models.py index e4016aa..b14ea2f 100644 --- a/dashboard/src/api/models.py +++ b/dashboard/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 @@ -703,6 +703,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() -- cgit 1.2.3-korg