Change the Clone Job button to show options to keep the specific
metahost assignments.

Signed-off-by: James Ren <jamesren@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@2090 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index bb9e464..279ca15 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -409,17 +409,30 @@
     return rpc_utils.prepare_for_serialization(jobs)
 
 
-def get_info_for_clone(id):
+def get_info_for_clone(id, preserve_metahosts):
     """\
     Retrieves all the information needed to clone a job.
     """
     info = {}
     job = models.Job.objects.get(id=id)
     query = job.hostqueueentry_set.filter(deleted=False)
-    hosts = [queue_entry.host for queue_entry
-             in query if queue_entry.host and not queue_entry.meta_host]
-    meta_hosts = [queue_entry.meta_host.name for queue_entry
-                  in query if queue_entry.meta_host]
+
+    hosts = []
+    meta_hosts = []
+
+    # For each queue entry, if the entry contains a host, add the entry into the
+    # hosts list if either:
+    #     It is not a metahost.
+    #     It was an assigned metahost, and the user wants to keep the specific
+    #         assignments.
+    # Otherwise, add the metahost to the metahosts list.
+    for queue_entry in query:
+        if (queue_entry.host and (preserve_metahosts
+                                  or not queue_entry.meta_host)):
+            hosts.append(queue_entry.host)
+        else:
+            meta_hosts.append(queue_entry.meta_host.name)
+
     host_dicts = []
 
     for host in hosts: