>From 528b9108a91449b1689265aff55a9b2667a33066 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 11 Apr 2012 13:25:36 +0100 Subject: [PATCH] sysprep: Print some logging by default. It can be disabled using the --quiet option. The logging looks like: Examining the guest ... Performing "cron-spool" ... Performing "dhcp-client-state" ... Performing "dhcp-server-state" ... Performing "hostname" ... Performing "logfiles" ... Performing "mail-spool" ... Performing "net-hwaddr" ... Performing "random-seed" ... Performing "rhn-systemid" ... Performing "script" ... Performing "smolt-uuid" ... Performing "ssh-hostkeys" ... Performing "udev-persistent-net" ... Performing "utmp" ... Performing "yum-uuid" ... --- sysprep/main.ml | 14 +++++++++++--- sysprep/sysprep_operation.ml | 5 +++-- sysprep/sysprep_operation.mli | 2 +- sysprep/virt-sysprep.pod | 8 ++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/sysprep/main.ml b/sysprep/main.ml index d06b0d2..cd7aa57 100644 --- a/sysprep/main.ml +++ b/sysprep/main.ml @@ -29,12 +29,13 @@ let () = Sysprep_operation.bake () (* Command line argument parsing. *) let prog = Filename.basename Sys.executable_name -let debug_gc, operations, g, selinux_relabel = +let debug_gc, operations, g, selinux_relabel, quiet = let debug_gc = ref false in let domain = ref None in let dryrun = ref false in let files = ref [] in let format = ref "auto" in + let quiet = ref false in let libvirturi = ref "" in let operations = ref None in let selinux_relabel = ref `Auto in @@ -105,6 +106,8 @@ let debug_gc, operations, g, selinux_relabel = "--enable", Arg.String set_enable, "operations Enable specific operations"; "--format", Arg.Set_string format, "format Set format (default: auto)"; "--list-operations", Arg.Unit list_operations, " List supported operations"; + "-q", Arg.Set quiet, " Don't print log messages"; + "--quiet", Arg.Set quiet, " Don't print log messages"; "--selinux-relabel", Arg.Unit force_selinux_relabel, " Force SELinux relabel"; "--no-selinux-relabel", Arg.Unit no_force_selinux_relabel, " Never do SELinux relabel"; "-v", Arg.Set verbose, " Enable debugging messages"; @@ -159,10 +162,14 @@ read the man page virt-sysprep(1). let debug_gc = !debug_gc in let dryrun = !dryrun in let operations = !operations in + let quiet = !quiet in let selinux_relabel = !selinux_relabel in let trace = !trace in let verbose = !verbose in + if not quiet then + printf "Examining the guest ...\n%!"; + (* Connect to libguestfs. *) let g = new G.guestfs () in if trace then g#set_trace true; @@ -170,7 +177,7 @@ read the man page virt-sysprep(1). add g dryrun; g#launch (); - debug_gc, operations, g, selinux_relabel + debug_gc, operations, g, selinux_relabel, quiet let () = (* Inspection. *) @@ -194,7 +201,8 @@ let () = ) mps; (* Perform the operations. *) - let flags = Sysprep_operation.perform_operations ?operations g root in + let flags = + Sysprep_operation.perform_operations ?operations ~quiet g root in (* Parse flags. *) let relabel = ref false in diff --git a/sysprep/sysprep_operation.ml b/sysprep/sysprep_operation.ml index 3fd8afc..fedf9a0 100644 --- a/sysprep/sysprep_operation.ml +++ b/sysprep/sysprep_operation.ml @@ -169,7 +169,7 @@ let list_operations () = *) List.iter (fun op -> print_endline op.name ) !ops -let perform_operations ?operations g root = +let perform_operations ?operations ?(quiet = false) g root = assert !baked; let ops = @@ -181,7 +181,8 @@ let perform_operations ?operations g root = let flags = List.map ( fun op -> - (* eprintf "calling %S.perform g %S\n" op.name root; *) + if not quiet then + printf "Performing %S ...\n%!" op.name; op.perform g root ) ops in diff --git a/sysprep/sysprep_operation.mli b/sysprep/sysprep_operation.mli index 5fe035f..0f58510 100644 --- a/sysprep/sysprep_operation.mli +++ b/sysprep/sysprep_operation.mli @@ -95,5 +95,5 @@ val add_to_set : string -> set -> set Note that this will raise [Not_found] if [name] is not a valid operation name. *) -val perform_operations : ?operations:set -> Guestfs.guestfs -> string -> flag list +val perform_operations : ?operations:set -> ?quiet:bool -> Guestfs.guestfs -> string -> flag list (** Perform all operations, or the subset listed in the [operations] set. *) diff --git a/sysprep/virt-sysprep.pod b/sysprep/virt-sysprep.pod index 8120c78..a8cffb6 100755 --- a/sysprep/virt-sysprep.pod +++ b/sysprep/virt-sysprep.pod @@ -124,6 +124,14 @@ security problem with malicious guests (CVE-2010-3851). List the operations supported by the virt-sysprep program. +=item B<-q> + +=item B<--quiet> + +Don't print log messages. + +To enable detailed logging of individual file operations, use I<-x>. + =item B<--selinux-relabel> =item B<--no-selinux-relabel> -- 1.7.9.3