summaryrefslogtreecommitdiffstats
path: root/inspector
diff options
context:
space:
mode:
authorRichard Jones <rjones@trick.home.annexia.org>2009-07-09 14:01:58 +0100
committerRichard Jones <rjones@trick.home.annexia.org>2009-07-09 15:33:26 +0100
commit2f70ca487bee8babe5aef27f00a2131ea86ebd50 (patch)
treec1271a5ea3317b2e8851d2302b9d5b15fa770652 /inspector
parente3c2a599027f88a617b46b77be1673de0c94faee (diff)
downloadlibguestfs-2f70ca487bee8babe5aef27f00a2131ea86ebd50.tar.gz
libguestfs-2f70ca487bee8babe5aef27f00a2131ea86ebd50.tar.xz
libguestfs-2f70ca487bee8babe5aef27f00a2131ea86ebd50.zip
Add Sys::Guestfs::Lib - useful functions for using libguestfs from Perl.
This adds an extra Perl module called Sys::Guestfs::Lib which adds useful functions for using libguestfs from Perl. The intention is that common code shared between virt-inspector, virt-df and virt-v2v will move into this library. This patch also changes virt-inspector to use this library.
Diffstat (limited to 'inspector')
-rwxr-xr-xinspector/virt-inspector.pl65
1 files changed, 9 insertions, 56 deletions
diff --git a/inspector/virt-inspector.pl b/inspector/virt-inspector.pl
index 3557a38a..2922ecc4 100755
--- a/inspector/virt-inspector.pl
+++ b/inspector/virt-inspector.pl
@@ -20,6 +20,7 @@ use warnings;
use strict;
use Sys::Guestfs;
+use Sys::Guestfs::Lib qw(open_guest);
use Pod::Usage;
use Getopt::Long;
use Data::Dumper;
@@ -27,9 +28,6 @@ use File::Temp qw/tempdir/;
use XML::Writer;
# Optional:
-eval "use Sys::Virt;";
-eval "use XML::XPath;";
-eval "use XML::XPath::XMLParser;";
eval "use YAML::Any;";
=encoding utf8
@@ -202,61 +200,15 @@ GetOptions ("help|?" => \$help,
pod2usage (1) if $help;
pod2usage ("$0: no image or VM names given") if @ARGV == 0;
-# Domain name or guest image(s)?
-
-my @images;
-if (-e $ARGV[0]) {
- @images = @ARGV;
-
- foreach (@images) {
- if (! -r $_) {
- die "guest image $_ does not exist or is not readable\n"
- }
- }
+my $rw = 0;
+$rw = 1 if $output eq "fish";
+my $g;
+if ($uri) {
+ $g = open_guest (\@ARGV, rw => $rw, address => $uri);
} else {
- die "virt-inspector: no libvirt support (install Sys::Virt, XML::XPath and XML::XPath::XMLParser)\n"
- unless exists $INC{"Sys/Virt.pm"} &&
- exists $INC{"XML/XPath.pm"} &&
- exists $INC{"XML/XPath/XMLParser.pm"};
-
- pod2usage ("$0: too many domains listed on command line") if @ARGV > 1;
-
- my $vmm;
- if (defined $uri) {
- $vmm = Sys::Virt->new (uri => $uri, readonly => 1);
- } else {
- $vmm = Sys::Virt->new (readonly => 1);
- }
- die "cannot connect to libvirt $uri\n" unless $vmm;
-
- my @doms = $vmm->list_defined_domains ();
- my $isitinactive = "an inactive libvirt domain";
- if ($output ne "fish") {
- # In the special case where we want read-only access to
- # a domain, allow the user to specify an active domain too.
- push @doms, $vmm->list_domains ();
- $isitinactive = "a libvirt domain";
- }
- my $dom;
- foreach (@doms) {
- if ($_->get_name () eq $ARGV[0]) {
- $dom = $_;
- last;
- }
- }
- die "$ARGV[0] is not the name of $isitinactive\n" unless $dom;
-
- # Get the names of the image(s).
- my $xml = $dom->get_xml_description ();
-
- my $p = XML::XPath->new (xml => $xml);
- my @disks = $p->findnodes ('//devices/disk/source/@dev');
- @images = map { $_->getData } @disks;
+ $g = open_guest (\@ARGV, rw => $rw);
}
-# We've now got the list of @images, so feed them to libguestfs.
-my $g = Sys::Guestfs->new ();
-$g->add_drive_ro ($_) foreach @images;
$g->launch ();
$g->wait_ready ();
@@ -948,7 +900,7 @@ if ($output eq "fish" || $output eq "ro-fish") {
print "--ro ";
}
- print "-a $_ " foreach @images;
+ print "-a $_ " foreach @ARGV;
my $mounts = $oses{$root_dev}->{mounts};
# Have to mount / first. Luckily '/' is early in the ASCII
@@ -1405,6 +1357,7 @@ sub output_query_virtio_drivers
L<guestfs(3)>,
L<guestfish(1)>,
L<Sys::Guestfs(3)>,
+L<Sys::Guestfs::Lib(3)>,
L<Sys::Virt(3)>,
L<http://libguestfs.org/>.