]> xenbits.xensource.com Git - xenclient/toolstack.git/commitdiff
add support for optional argument.
authorVincent Hanquez <vincent.hanquez@eu.citrix.com>
Tue, 21 Jul 2009 09:00:32 +0000 (10:00 +0100)
committerVincent Hanquez <vincent.hanquez@eu.citrix.com>
Tue, 21 Jul 2009 09:00:32 +0000 (10:00 +0100)
live, delete, forced will have a default value now.

xenvm/xenvm.ml

index 200b4dfe83f2f7e4eb731eaf902de788982d13ae..cbafc59894dcbfc2861dbacc66fad5756f6f13bf 100644 (file)
@@ -393,6 +393,10 @@ let reread_config state path =
        state.vm_next_cfg <- Some cfg
 
 let do_task quit state (task, args) =
+       let optional_arg default f args s =
+               try f args s with Tasks.Argument_not_found _ -> default
+               in
+
        let task_desc = List.assoc task Tasks.actions_table in
        (*maybe assert_vmstate task_vmstate_required;*)
        match task with
@@ -402,14 +406,14 @@ let do_task quit state (task, args) =
                do_help ();
        | Tasks.Destroy -> with_xcs (fun xc xs -> Vmact.stop_vm xc xs state); Xenvmlib.Ok
        | Tasks.Halt ->
-               let force = Tasks.args_get_bool args "forced" in
+               let force = optional_arg false Tasks.args_get_bool args "forced" in
                with_xcs (fun xc xs ->
                        Misc.with_xal (fun xal -> Vmact.shutdown_vm xc xs xal state force Domain.Halt);
                        Vmact.stop_vm xc xs state;
                );
                Xenvmlib.Ok
        | Tasks.Reboot ->
-               let force = Tasks.args_get_bool args "forced" in
+               let force = optional_arg false Tasks.args_get_bool args "forced" in
                with_xcs (fun xc xs ->
                        Misc.with_xal (fun xal -> Vmact.shutdown_vm xc xs xal state force Domain.Reboot);
                        Vmact.stop_vm xc xs state;
@@ -421,7 +425,7 @@ let do_task quit state (task, args) =
        | Tasks.Unpause -> with_xc (fun xc -> Vmact.unpause_vm xc state); Xenvmlib.Ok
        | Tasks.Suspend ->
                let file = Tasks.args_get_string args "file" in
-               let live = Tasks.args_get_bool args "live" in
+               let live = optional_arg false Tasks.args_get_bool args "live" in
                state.vm_on_suspend_action <- ActionSuspend;
                with_xcs (fun xc xs ->
                        Vmact.suspend xc xs state (if live then [ Domain.Live ] else [])
@@ -431,7 +435,7 @@ let do_task quit state (task, args) =
                Xenvmlib.Ok
        | Tasks.Restore ->
                let file = Tasks.args_get_string args "file" in
-               let delete = Tasks.args_get_bool args "delete" in
+               let delete = optional_arg true Tasks.args_get_bool args "delete" in
                Vmact.change_vmstate state VmRestoring;
                with_xcs (fun xc xs -> Vmact.restore xc xs state delete (with_datadir state.vm_cfg file));
                Xenvmlib.Ok