+sub output_xml
+{
+ print "<operatingsystems>\n";
+ output_xml_os ($oses{$_}) foreach sort keys %oses;
+ print "</operatingsystems>\n";
+}
+
+sub output_xml_os
+{
+ my $os = shift;
+
+ print "<operatingsystem>\n";
+
+ print "<os>", $os->{os}, "</os>\n" if exists $os->{os};
+ print "<distro>", $os->{distro}, "</distro>\n" if exists $os->{distro};
+ print "<version>", $os->{version}, "</version>\n" if exists $os->{version};
+ print "<root>", $os->{root_device}, "</root>\n";
+
+ print "<mountpoints>\n";
+ my $mounts = $os->{mounts};
+ foreach (sort keys %$mounts) {
+ printf "<mountpoint dev='%s'>%s</mountpoint>\n",
+ $mounts->{$_}, $_
+ }
+ print "</mountpoints>\n";
+
+ print "<filesystems>\n";
+ my $filesystems = $os->{filesystems};
+ foreach (sort keys %$filesystems) {
+ print "<filesystem dev='$_'>\n";
+ print "<label>$filesystems->{$_}{label}</label>\n"
+ if exists $filesystems->{$_}{label};
+ print "<uuid>$filesystems->{$_}{uuid}</uuid>\n"
+ if exists $filesystems->{$_}{uuid};
+ print "<type>$filesystems->{$_}{fstype}</type>\n"
+ if exists $filesystems->{$_}{fstype};
+ print "<content>$filesystems->{$_}{content}</content>\n"
+ if exists $filesystems->{$_}{content};
+ print "</filesystem>\n";
+ }
+ print "</filesystems>\n";
+
+ if (exists $os->{modprobe_aliases}) {
+ my %aliases = %{$os->{modprobe_aliases}};
+ my @keys = sort keys %aliases;
+ if (@keys) {
+ print "<modprobealiases>\n";
+ foreach (@keys) {
+ printf "<alias device=\"%s\">%s</alias>\n", $_, $aliases{$_}
+ }
+ print "</modprobealiases>\n";
+ }
+ }
+
+ if (exists $os->{initrd_modules}) {
+ my %modvers = %{$os->{initrd_modules}};
+ my @keys = sort keys %modvers;
+ if (@keys) {
+ print "<initrds>\n";
+ foreach (@keys) {
+ my @modules = @{$modvers{$_}};
+ print "<initrd version=\"$_\">\n";
+ print "<module>$_</module>\n" foreach @modules;
+ print "</initrd>\n";
+ }
+ print "</initrds>\n";
+ }
+ }
+
+ print "<applications>\n";
+ my @apps = @{$os->{apps}};
+ foreach (@apps) {
+ print "<application>\n";
+ print "<name>$_->{name}</name><version>$_->{version}</version>\n";
+ print "</application>\n";
+ }
+ print "</applications>\n";
+
+ print "<kernels>\n";
+ my @kernels = @{$os->{kernels}};
+ foreach (@kernels) {
+ print "<kernel>\n";
+ print "<version>$_->{version}</version>\n";
+ print "<modules>\n";
+ my @modules = @{$_->{modules}};
+ foreach (@modules) {
+ print "<module>$_</module>\n";
+ }
+ print "</modules>\n";
+ print "</kernel>\n";
+ }
+ print "</kernels>\n";
+
+ print "</operatingsystem>\n";
+}
+
+=head1 QUERY MODE
+
+When you use C<virt-inspector --query>, the output is a series of
+lines of the form:
+
+ windows=no
+ linux=yes
+ fullvirt=yes
+ xen_pv_drivers=no
+
+(each answer is usually C<yes> or C<no>, or the line is completely
+missing if we could not determine the answer at all).
+
+If the guest is multiboot, you can get apparently conflicting answers
+(eg. C<windows=yes> and C<linux=yes>, or a guest which is both
+fullvirt and has a Xen PV kernel). This is normal, and just means
+that the guest can do both things, although it might require operator
+intervention such as selecting a boot option when the guest is
+booting.
+
+This section describes the full range of answers possible.
+
+=over 4
+
+=cut
+
+sub output_query
+{
+ output_query_windows ();
+ output_query_linux ();
+ output_query_rhel ();
+ output_query_fedora ();
+ output_query_debian ();
+ output_query_fullvirt ();
+ output_query_xen_domU_kernel ();
+ output_query_xen_pv_drivers ();
+ output_query_virtio_drivers ();
+}
+
+=item windows=(yes|no)
+
+Answer C<yes> if Microsoft Windows is installed in the guest.
+
+=cut
+
+sub output_query_windows
+{
+ my $windows = "no";
+ foreach my $os (keys %oses) {
+ $windows="yes" if $oses{$os}->{os} eq "windows";
+ }
+ print "windows=$windows\n";
+}
+
+=item linux=(yes|no)
+
+Answer C<yes> if a Linux kernel is installed in the guest.
+
+=cut
+
+sub output_query_linux
+{
+ my $linux = "no";
+ foreach my $os (keys %oses) {
+ $linux="yes" if $oses{$os}->{os} eq "linux";
+ }
+ print "linux=$linux\n";
+}
+
+=item rhel=(yes|no)
+
+Answer C<yes> if the guest contains Red Hat Enterprise Linux.
+
+=cut
+
+sub output_query_rhel
+{
+ my $rhel = "no";
+ foreach my $os (keys %oses) {
+ $rhel="yes" if $oses{$os}->{os} eq "linux" && $oses{$os}->{distro} eq "redhat";
+ }
+ print "rhel=$rhel\n";
+}
+
+=item fedora=(yes|no)