X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=inspector%2Fvirt-inspector.pl;h=17c63759f4d96306905135db0ac66528c14a8c4a;hb=72c829395bb6a4800516d4f535e18af48195585b;hp=7ab808b8c6d163bdf8bcfa402a29e62405180dee;hpb=22528e9bc486cbb6357192bd758c417c61bba955;p=libguestfs.git
diff --git a/inspector/virt-inspector.pl b/inspector/virt-inspector.pl
index 7ab808b..17c6375 100755
--- a/inspector/virt-inspector.pl
+++ b/inspector/virt-inspector.pl
@@ -26,8 +26,8 @@ use Sys::Guestfs::Lib qw(open_guest get_partitions resolve_windows_path
use Pod::Usage;
use Getopt::Long;
use Data::Dumper;
-use File::Temp qw/tempdir/;
use XML::Writer;
+use Locale::TextDomain 'libguestfs';
# Optional:
eval "use YAML::Any;";
@@ -89,6 +89,14 @@ Display brief help.
=cut
+my $version;
+
+=item B<--version>
+
+Display version number and exit.
+
+=cut
+
my $uri;
=item B<--connect URI> | B<-c URI>
@@ -102,18 +110,6 @@ then libvirt is not used at all.
=cut
-my $force;
-
-=item B<--force>
-
-Force reading a particular guest even if it appears to be active. In
-earlier versions of virt-inspector, this could be dangerous (for
-example, corrupting the guest's disk image). However in more recent
-versions, it should not cause corruption, but might cause
-virt-inspector to crash or produce incorrect results.
-
-=cut
-
my $output = "text";
=back
@@ -185,8 +181,8 @@ default.
=cut
GetOptions ("help|?" => \$help,
+ "version" => \$version,
"connect|c=s" => \$uri,
- "force" => \$force,
"text" => sub { $output = "text" },
"none" => sub { $output = "none" },
"xml" => sub { $output = "xml" },
@@ -200,15 +196,26 @@ GetOptions ("help|?" => \$help,
"windows-registry" => \$windows_registry,
) or pod2usage (2);
pod2usage (1) if $help;
-pod2usage ("$0: no image or VM names given") if @ARGV == 0;
+if ($version) {
+ my $g = Sys::Guestfs->new ();
+ my %h = $g->version ();
+ print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
+ exit
+}
+pod2usage (__"virt-inspector: no image or VM names given") if @ARGV == 0;
my $rw = 0;
$rw = 1 if $output eq "fish";
my $g;
+my @images;
if ($uri) {
- $g = open_guest (\@ARGV, rw => $rw, address => $uri);
+ my ($conn, $dom);
+ ($g, $conn, $dom, @images) =
+ open_guest (\@ARGV, rw => $rw, address => $uri);
} else {
- $g = open_guest (\@ARGV, rw => $rw);
+ my ($conn, $dom);
+ ($g, $conn, $dom, @images) =
+ open_guest (\@ARGV, rw => $rw);
}
$g->launch ();
@@ -292,7 +299,7 @@ if ($output !~ /.*fish$/) {
if ($output eq "fish" || $output eq "ro-fish") {
my @osdevs = keys %$oses;
# This only works if there is a single OS.
- die "--fish output is only possible with a single OS\n" if @osdevs != 1;
+ die __"--fish output is only possible with a single OS\n" if @osdevs != 1;
my $root_dev = $osdevs[0];
@@ -300,13 +307,13 @@ if ($output eq "fish" || $output eq "ro-fish") {
print "--ro ";
}
- print "-a $_ " foreach @ARGV;
+ print "-a $_ " foreach @images;
my $mounts = $oses->{$root_dev}->{mounts};
# Have to mount / first. Luckily '/' is early in the ASCII
# character set, so this should be OK.
foreach (sort keys %$mounts) {
- print "-m $mounts->{$_}:$_ " if $_ ne "swap";
+ print "-m $mounts->{$_}:$_ " if $_ ne "swap" && $_ ne "none";
}
print "\n"
}
@@ -318,7 +325,7 @@ elsif ($output eq "perl") {
# YAML output
elsif ($output eq "yaml") {
- die "virt-inspector: no YAML support\n"
+ die __"virt-inspector: no YAML support\n"
unless exists $INC{"YAML/Any.pm"};
print Dump(%$oses);
@@ -350,16 +357,19 @@ sub output_text_os
print $os->{os}, " " if exists $os->{os};
print $os->{distro}, " " if exists $os->{distro};
- print $os->{version}, " " if exists $os->{version};
+ print $os->{arch}, " " if exists $os->{arch};
+ print $os->{major_version} if exists $os->{major_version};
+ print ".", $os->{minor_version} if exists $os->{minor_version};
+ print " ";
print "on ", $os->{root_device}, ":\n";
- print " Mountpoints:\n";
+ print __" Mountpoints:\n";
my $mounts = $os->{mounts};
foreach (sort keys %$mounts) {
printf " %-30s %s\n", $mounts->{$_}, $_
}
- print " Filesystems:\n";
+ print __" Filesystems:\n";
my $filesystems = $os->{filesystems};
foreach (sort keys %$filesystems) {
print " $_:\n";
@@ -377,7 +387,7 @@ sub output_text_os
my %aliases = %{$os->{modprobe_aliases}};
my @keys = sort keys %aliases;
if (@keys) {
- print " Modprobe aliases:\n";
+ print __" Modprobe aliases:\n";
foreach (@keys) {
printf " %-30s %s\n", $_, $aliases{$_}->{modulename}
}
@@ -388,7 +398,7 @@ sub output_text_os
my %modvers = %{$os->{initrd_modules}};
my @keys = sort keys %modvers;
if (@keys) {
- print " Initrd modules:\n";
+ print __" Initrd modules:\n";
foreach (@keys) {
my @modules = @{$modvers{$_}};
print " $_:\n";
@@ -397,16 +407,16 @@ sub output_text_os
}
}
- print " Applications:\n";
+ print __" Applications:\n";
my @apps = @{$os->{apps}};
foreach (@apps) {
print " $_->{name} $_->{version}\n"
}
- print " Kernels:\n";
+ print __" Kernels:\n";
my @kernels = @{$os->{kernels}};
foreach (@kernels) {
- print " $_->{version}\n";
+ print " $_->{version} ($_->{arch})\n";
my @modules = @{$_->{modules}};
foreach (@modules) {
print " $_\n";
@@ -414,7 +424,7 @@ sub output_text_os
}
if (exists $os->{root}->{registry}) {
- print " Windows Registry entries:\n";
+ print __" Windows Registry entries:\n";
# These are just lumps of text - dump them out.
foreach (@{$os->{root}->{registry}}) {
print "$_\n";
@@ -441,7 +451,11 @@ sub output_xml_os
foreach ( [ "name" => "os" ],
[ "distro" => "distro" ],
- [ "version" => "version" ],
+ [ "arch" => "arch" ],
+ [ "major_version" => "major_version" ],
+ [ "minor_version" => "minor_version" ],
+ [ "package_format" => "package_format" ],
+ [ "package_management" => "package_management" ],
[ "root" => "root_device" ] ) {
$xml->dataElement($_->[0], $os->{$_->[1]}) if exists $os->{$_->[1]};
}
@@ -516,16 +530,41 @@ sub output_xml_os
}
$xml->endTag("applications");
+ if(defined($os->{boot}) && defined($os->{boot}->{configs})) {
+ my $default = $os->{boot}->{default};
+ my $configs = $os->{boot}->{configs};
+
+ $xml->startTag("boot");
+ for(my $i = 0; $i < scalar(@$configs); $i++) {
+ my $config = $configs->[$i];
+
+ my @attrs = ();
+ push(@attrs, ("default" => 1)) if($default == $i);
+ $xml->startTag("config", @attrs);
+ $xml->dataElement("title", $config->{title});
+ $xml->dataElement("kernel", $config->{kernel}->{version})
+ if(defined($config->{kernel}));
+ $xml->dataElement("cmdline", $config->{cmdline})
+ if(defined($config->{cmdline}));
+ $xml->endTag("config");
+ }
+ $xml->endTag("boot");
+ }
+
$xml->startTag("kernels");
my @kernels = @{$os->{kernels}};
foreach (@kernels) {
- $xml->startTag("kernel", "version" => $_->{version});
+ $xml->startTag("kernel",
+ "version" => $_->{version},
+ "arch" => $_->{arch});
$xml->startTag("modules");
my @modules = @{$_->{modules}};
foreach (@modules) {
$xml->dataElement("module", $_);
}
$xml->endTag("modules");
+ $xml->dataElement("path", $_->{path}) if(defined($_->{path}));
+ $xml->dataElement("package", $_->{package}) if(defined($_->{package}));
$xml->endTag("kernel");
}
$xml->endTag("kernels");
@@ -579,6 +618,8 @@ sub output_query
output_query_xen_domU_kernel ();
output_query_xen_pv_drivers ();
output_query_virtio_drivers ();
+ output_query_kernel_arch ();
+ output_query_userspace_arch ();
}
=item windows=(yes|no)
@@ -621,7 +662,8 @@ 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";
+ $rhel="yes" if ($oses->{$os}->{os} eq "linux" &&
+ $oses->{$os}->{distro} eq "rhel");
}
print "rhel=$rhel\n";
}
@@ -750,6 +792,50 @@ sub output_query_virtio_drivers
print "virtio_drivers=no\n";
}
+=item userspace_arch=(x86_64|...)
+
+Print the architecture of userspace.
+
+NB. For multi-boot VMs this can print several lines.
+
+=cut
+
+sub output_query_userspace_arch
+{
+ my %arches;
+
+ foreach my $os (keys %$oses) {
+ $arches{$oses->{$os}->{arch}} = 1 if exists $oses->{$os}->{arch};
+ }
+
+ foreach (sort keys %arches) {
+ print "userspace_arch=$_\n";
+ }
+}
+
+=item kernel_arch=(x86_64|...)
+
+Print the architecture of the kernel.
+
+NB. For multi-boot VMs this can print several lines.
+
+=cut
+
+sub output_query_kernel_arch
+{
+ my %arches;
+
+ foreach my $os (keys %$oses) {
+ foreach my $kernel (@{$oses->{$os}->{kernels}}) {
+ $arches{$kernel->{arch}} = 1 if exists $kernel->{arch};
+ }
+ }
+
+ foreach (sort keys %arches) {
+ print "kernel_arch=$_\n";
+ }
+}
+
=back
=head1 SEE ALSO
@@ -768,6 +854,8 @@ from L.
Richard W.M. Jones L
+Matthew Booth L
+
=head1 COPYRIGHT
Copyright (C) 2009 Red Hat Inc.