From: Richard W.M. Jones Date: Sun, 28 Aug 2011 08:25:52 +0000 (+0100) Subject: resize: Add --machine-readable option for machine friendly output. X-Git-Tag: 1.12.5~4 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=51578f3d64f66e1737f9edf1d9da996e881f3509;p=libguestfs.git resize: Add --machine-readable option for machine friendly output. Use virt-resize --machine-readable to print a list of facts about what this version of virt-resize supports. This includes parts of commit 09a7545649e6cac0de2c4421cb64b659164174ee from the development branch, but doesn't include the machine-readable progress bar. --- diff --git a/resize/resize.ml b/resize/resize.ml index d4455eb..8ee6faa 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -57,6 +57,7 @@ let infile, outfile, copy_boot_loader, debug, deletes, dryrun, let format = ref "" in let ignores = ref [] in let lv_expands = ref [] in + let machine_readable = ref false in let ntfsresize_force = ref false in let output_format = ref "" in let quiet = ref false in @@ -83,6 +84,7 @@ let infile, outfile, copy_boot_loader, debug, deletes, dryrun, "--LV-expand", Arg.String (add lv_expands), "lv -\"-"; "--lvexpand", Arg.String (add lv_expands), "lv -\"-"; "--LVexpand", Arg.String (add lv_expands), "lv -\"-"; + "--machine-readable", Arg.Set machine_readable, " Make output machine readable"; "-n", Arg.Set dryrun, " Don't perform changes"; "--dryrun", Arg.Set dryrun, " -\"-"; "--dry-run", Arg.Set dryrun, " -\"-"; @@ -125,6 +127,7 @@ read the man page virt-resize(1). let format = match !format with "" -> None | str -> Some str in let ignores = List.rev !ignores in let lv_expands = List.rev !lv_expands in + let machine_readable = !machine_readable in let ntfsresize_force = !ntfsresize_force in let output_format = match !output_format with "" -> None | str -> Some str in let quiet = !quiet in @@ -132,6 +135,25 @@ read the man page virt-resize(1). let resizes_force = List.rev !resizes_force in let shrink = match !shrink with "" -> None | str -> Some str in + (* No arguments and machine-readable mode? Print out some facts + * about what this binary supports. We only need to print out new + * things added since this option, or things which depend on features + * of the appliance. + *) + if !disks = [] && machine_readable then ( + printf "virt-resize\n"; + printf "ntfsresize-force\n"; + printf "32bitok\n"; + let g = new G.guestfs () in + g#add_drive_opts "/dev/null"; + g#launch (); + if feature_available g [| "ntfsprogs"; "ntfs3g" |] then + printf "ntfs\n"; + if feature_available g [| "btrfs" |] then + printf "btrfs\n"; + exit 0 + ); + (* Verify we got exactly 2 disks. *) let infile, outfile = match List.rev !disks with diff --git a/resize/virt-resize.pod b/resize/virt-resize.pod index 3a6af18..72b4620 100644 --- a/resize/virt-resize.pod +++ b/resize/virt-resize.pod @@ -349,6 +349,12 @@ You can give this option multiple times, I it doesn't make sense to do this unless the logical volumes you specify are all in different volume groups. +=item B<--machine-readable> + +This option is used to make the output more machine friendly +when being parsed by other programs. See +L below. + =item B<-n> =item B<--dryrun> @@ -483,6 +489,25 @@ Display version number and exit. =back +=head1 MACHINE READABLE OUTPUT + +The I<--machine-readable> option can be used to make the output more +machine friendly, which is useful when calling virt-resize from other +programs, GUIs etc. + +Use the option on its own to query the capabilities of the virt-resize +binary. Typical output looks like this: + + $ virt-resize --machine-readable + virt-resize + ntfsresize-force + 32bitok + ntfs + btrfs + +A list of features is printed, one per line, and the program exits +with status 0. + =head1 NOTES =head2 "Partition 1 does not end on cylinder boundary."