]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Make the output of 'xe host-get-vms-which-prevent-evacuation' more uniform
authorDavid Scott <dave.scott@eu.citrix.com>
Fri, 18 Jun 2010 21:54:18 +0000 (22:54 +0100)
committerDavid Scott <dave.scott@eu.citrix.com>
Fri, 18 Jun 2010 21:54:18 +0000 (22:54 +0100)
Now the regular output looks like this:

# xe host-get-vms-which-prevent-evacuation uuid=b82bf253-1494-40f2-9c3d-34f5bd17012d
uuid ( RO)          : 1d4eba84-9c04-962b-8fd3-f9fb5d597b64
    name-label ( RW): oim2
        reason ( RO): VM_MISSING_PV_DRIVERS,OpaqueRef:1ea1dad3-3b5c-4a51-2e9b-128688585769

uuid ( RO)          : 6a97a613-bfa2-088d-f415-cf49bbb4bb95
    name-label ( RW): oim
        reason ( RO): VM_MISSING_PV_DRIVERS,OpaqueRef:e8eeb830-36ac-fa4b-5703-d8a7bb551331

The --minimal output looks like this:

# xe host-get-vms-which-prevent-evacuation uuid=b82bf253-1494-40f2-9c3d-34f5bd17012d --minimal
6a97a613-bfa2-088d-f415-cf49bbb4bb95,1d4eba84-9c04-962b-8fd3-f9fb5d597b64

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
ocaml/xapi/cli_operations.ml

index 7c302112ac0c819a4873c80006abb441b9f6cd50..1fd94daa09921bbf72654f93d8bcafddc09036dd 100644 (file)
@@ -2593,10 +2593,17 @@ let host_get_vms_which_prevent_evacuation printer rpc session_id params =
   let uuid = List.assoc "uuid" params in
   let host = Client.Host.get_by_uuid rpc session_id uuid in
   let vms = Client.Host.get_vms_which_prevent_evacuation rpc session_id host in
-  let table = List.map (fun (vm, result) -> 
-                         Printf.sprintf "%s (%s)" (Client.VM.get_uuid rpc session_id vm) (Client.VM.get_name_label rpc session_id vm),
-                         print_assert_exception (Api_errors.Server_error(List.hd result, List.tl result))) vms in
-  printer (Cli_printer.PTable [ ("VM", "Error") :: table ])  
+
+  let op (vm, error) = 
+    let error = String.concat "," error in
+    let record = vm_record rpc session_id vm in
+    let extra_field = make_field ~name:"reason" ~get:(fun () -> error) () in
+    let record = { record with fields = record.fields @ [ extra_field ] } in
+    let selected = List.hd (select_fields params [record] [ "uuid"; "name-label"; "reason"]) in
+    let table = List.map print_field selected in
+    printer (Cli_printer.PTable [table])
+  in
+  ignore(List.iter op vms)
 
 let host_get_uncooperative_vms printer rpc session_id params = 
   let uuid = List.assoc "uuid" params in