From ad7886822b481c5fb93a2933fbcbdfbd7bb979f2 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 23 Mar 2015 22:16:57 +0000 Subject: [PATCH] boot: Add --console and --viewer parameters. These allow the serial and/or graphical consoles to be opened when creating a guest. --- Makefile.am | 2 +- mclu.pod | 10 ++++++++++ mclu_boot.ml | 33 ++++++++++++++++++++++++--------- mclu_console.mli | 2 ++ mclu_viewer.mli | 2 ++ 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Makefile.am b/Makefile.am index 329e29b..a7f9d66 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,11 +49,11 @@ SOURCES_ML = \ mclu_list.ml \ mclu_status.ml \ mclu_onoff.ml \ - mclu_boot.ml \ mclu_destroy.ml \ mclu_reboot.ml \ mclu_console.ml \ mclu_viewer.ml \ + mclu_boot.ml \ mclu.ml OCAMLPACKAGES = -package unix,pcre,libvirt diff --git a/mclu.pod b/mclu.pod index 3817afd..570aef3 100644 --- a/mclu.pod +++ b/mclu.pod @@ -66,6 +66,11 @@ control resources using the following options: =over 4 +=item B<--console> + +Open the serial console immediately after booting the guest. This is +the same as using the C subcommand, but quicker. + =item B<--memory nnG> Specify the amount of memory (RAM) to give this guest. You can use @@ -76,6 +81,11 @@ a number followed by a unit, eg. C<--memory=4G> Specify the number of virtual CPUs to give to the guest. The default is the number of physical CPUs, but not more than 4. +=item B<--viewer> + +Open the graphical console immediately after booting the guest. This is +the same as using the C subcommand, but quicker. + =back =item B diff --git a/mclu_boot.ml b/mclu_boot.ml index 43ab049..adae6de 100644 --- a/mclu_boot.ml +++ b/mclu_boot.ml @@ -35,11 +35,16 @@ Try something like --memory 1G\n" s; exit 1 let vcpus = ref 0 (* 0 = choose for me *) +let open_console = ref false +let open_viewer = ref false + let get_arg_speclist () = Arg.align [ + "--console", Arg.Set open_console, " Open the serial console"; "--cpus", Arg.Set_int vcpus, "n Number of virtual CPUs"; "--memory", Arg.String set_memory, "nnG Amount of RAM to give guest"; "--ram", Arg.String set_memory, "nnG Amount of RAM to give guest"; "--vcpus", Arg.Set_int vcpus, "n Number of virtual CPUs"; + "--viewer", Arg.Set open_viewer, " Open the graphical console"; ] let boot ~verbose template name = @@ -259,15 +264,25 @@ output=%s \ ); (* Start the guest. *) - try - let conn = - let name = node.MS.node_status.MS.node.Mclu_conf.libvirt_uri in - C.connect ~name () in - let dom = D.create_xml conn xml [] in - printf "mclu: %s:%s started\n" hostname (D.get_name dom) - with Libvirt.Virterror msg -> - eprintf "mclu: %s: %s\n" hostname (Libvirt.Virterror.to_string msg); - exit 1 + let dom = + try + let conn = + let name = node.MS.node_status.MS.node.Mclu_conf.libvirt_uri in + C.connect ~name () in + let dom = D.create_xml conn xml [] in + printf "mclu: %s:%s started\n" hostname (D.get_name dom); + dom + with Libvirt.Virterror msg -> + eprintf "mclu: %s: %s\n" hostname (Libvirt.Virterror.to_string msg); + exit 1 in + + (* Graphical console? *) + if !open_viewer then + Mclu_viewer.viewer ~verbose ~host:hostname (D.get_name dom); + + (* Serial console? (Interactive, so run it last) *) + if !open_console then + Mclu_console.console ~verbose ~host:hostname (D.get_name dom) let run ~verbose = function | [ template; name ] -> diff --git a/mclu_console.mli b/mclu_console.mli index 46ae35e..486cca0 100644 --- a/mclu_console.mli +++ b/mclu_console.mli @@ -19,3 +19,5 @@ val get_arg_speclist : unit -> (Arg.key * Arg.spec * Arg.doc) list val run : verbose:bool -> string list -> unit + +val console : verbose:bool -> ?host:string -> string -> unit diff --git a/mclu_viewer.mli b/mclu_viewer.mli index 46ae35e..48ae363 100644 --- a/mclu_viewer.mli +++ b/mclu_viewer.mli @@ -19,3 +19,5 @@ val get_arg_speclist : unit -> (Arg.key * Arg.spec * Arg.doc) list val run : verbose:bool -> string list -> unit + +val viewer : verbose:bool -> ?host:string -> string -> unit -- 1.8.3.1