X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=inspector%2Fvirt-inspector.pl;h=b2983b3d35664d74a8ef3d26c39ef3d6c3340f4f;hp=982d286c3e00788460b5e445145989098e66a9fe;hb=e4733575efff31742444b180cdcfbc2504b144c8;hpb=5ca50cbee961aa2f8592b3a38fba41e2a732b282 diff --git a/inspector/virt-inspector.pl b/inspector/virt-inspector.pl index 982d286..b2983b3 100755 --- a/inspector/virt-inspector.pl +++ b/inspector/virt-inspector.pl @@ -113,6 +113,8 @@ my $output = "text"; =item B<--xml> +=item B<--perl> + =item B<--fish> =item B<--ro-fish> @@ -122,6 +124,9 @@ Select the output format. The default is a readable text report. If you select I<--xml> then you get XML output which can be fed to other programs. +If you select I<--perl> then you get Perl structures output which +can be used directly in another Perl program. + If you select I<--fish> then we print a L command line which will automatically mount up the filesystems on the correct mount points. Try this for example: @@ -139,6 +144,7 @@ GetOptions ("help|?" => \$help, "connect|c=s" => \$uri, "force" => \$force, "xml" => sub { $output = "xml" }, + "perl" => sub { $output = "perl" }, "fish" => sub { $output = "fish" }, "guestfish" => sub { $output = "fish" }, "ro-fish" => sub { $output = "ro-fish" }, @@ -560,7 +566,7 @@ if ($output !~ /.*fish$/) { check_for_applications ($root_dev); check_for_kernels ($root_dev); - umount_all (); + $g->umount_all (); } } @@ -606,7 +612,105 @@ if ($output eq "fish" || $output eq "ro-fish") { print "\n" } +# Perl output. +elsif ($output eq "perl") { + print Dumper(\%oses); +} + +# Plain text output (the default). +elsif ($output eq "text") { + output_text (); +} + +# XML output. +elsif ($output eq "xml") { + output_xml (); +} + +sub output_text +{ + output_text_os ($oses{$_}) foreach sort keys %oses; +} + +sub output_text_os +{ + my $os = shift; + + print $os->{os}, " " if exists $os->{os}; + print $os->{distro}, " " if exists $os->{distro}; + print $os->{version}, " " if exists $os->{version}; + print "on ", $os->{root_device}, ":\n"; + + print " Mountpoints:\n"; + my $mounts = $os->{mounts}; + foreach (sort keys %$mounts) { + printf " %-30s %s\n", $mounts->{$_}, $_ + } + + print " Filesystems:\n"; + my $filesystems = $os->{filesystems}; + foreach (sort keys %$filesystems) { + print " $_:\n"; + print " label: $filesystems->{$_}{label}\n" + if exists $filesystems->{$_}{label}; + print " UUID: $filesystems->{$_}{uuid}\n" + if exists $filesystems->{$_}{uuid}; + print " type: $filesystems->{$_}{fstype}\n" + if exists $filesystems->{$_}{fstype}; + print " content: $filesystems->{$_}{content}\n" + if exists $filesystems->{$_}{content}; + } + + # XXX Applications. + # XXX Kernel. +} + +sub output_xml +{ + print "\n"; + output_xml_os ($oses{$_}) foreach sort keys %oses; + print "\n"; +} + +sub output_xml_os +{ + my $os = shift; + + print "\n"; + + print "", $os->{os}, "\n" if exists $os->{os}; + print "", $os->{distro}, "\n" if exists $os->{distro}; + print "", $os->{version}, "\n" if exists $os->{version}; + print "", $os->{root_device}, "\n"; + + print "\n"; + my $mounts = $os->{mounts}; + foreach (sort keys %$mounts) { + printf "%s\n", + $mounts->{$_}, $_ + } + print "\n"; + + print "\n"; + my $filesystems = $os->{filesystems}; + foreach (sort keys %$filesystems) { + print "\n"; + print "\n" + if exists $filesystems->{$_}{label}; + print "$filesystems->{$_}{uuid}\n" + if exists $filesystems->{$_}{uuid}; + print "$filesystems->{$_}{fstype}\n" + if exists $filesystems->{$_}{fstype}; + print "$filesystems->{$_}{content}\n" + if exists $filesystems->{$_}{content}; + print "\n"; + } + print "\n"; + # XXX Applications. + # XXX Kernel. + print "\n"; +} =head1 SEE ALSO