In this series of posts I want to cover some of the upcoming features in libguestfs 1.6. Of course you don’t need to wait for 1.6 to be released, you can try them out now from the development branch (source) or in these Fedora 14 testing builds
If I give you a virtual machine (or its disk image — almost the same thing), how do you know what’s in it? Is it a copy of Windows or Linux? In libguestfs you can use virt-inspector to give you a report. But in older versions what you couldn’t do was the same thing from the API. Virt-inspector is written as a Perl library, so that information is only available to Perl tools.
In libguestfs 1.6 we have rewritten this code in C and made it available to all the language bindings.
The example below is an OCaml program that inspects a disk image to reveal the product name. You can just save it to a file, chmod +x the file, and run it from the command line like this:
$ ./inspect.ml disk.img Fedora release 13 (Goddard) $ sudo ./inspect.ml /dev/vg_pin/Win7x32 Windows 7 Enterprise
#!/usr/bin/ocamlrun /usr/bin/ocaml #use "topfind";; #require "guestfs";; module G = Guestfs let () = let filename = Sys.argv.(1) in let g = G.create () in G.add_drive_ro g filename; G.launch g; let roots = G.inspect_os g in print_endline (G.inspect_get_product_name g roots.(0))
