Added framework for 'virt-df' command.
authorRichard Jones <rjones@trick.home.annexia.org>
Fri, 10 Jul 2009 09:44:20 +0000 (10:44 +0100)
committerRichard Jones <rjones@trick.home.annexia.org>
Fri, 10 Jul 2009 09:44:20 +0000 (10:44 +0100)
.gitignore
HACKING
Makefile.am
configure.ac
df/Makefile.am [new file with mode: 0644]
df/run-df-locally [new file with mode: 0755]
df/virt-df.pl [new file with mode: 0755]

index f660572..92b29b6 100644 (file)
@@ -46,6 +46,7 @@ daemon/names.c
 daemon/stubs.c
 depcomp
 .deps
 daemon/stubs.c
 depcomp
 .deps
+df/virt-df.1
 emptydisk
 examples/hello
 examples/to-xml
 emptydisk
 examples/hello
 examples/to-xml
@@ -67,6 +68,7 @@ haskell/Guestfs.hs
 html/guestfish.1.html
 html/guestfs.3.html
 html/recipes.html
 html/guestfish.1.html
 html/guestfs.3.html
 html/recipes.html
+html/virt-df.1.html
 html/virt-inspector.1.html
 html/virt-v2v.1.html
 images/100kallnewlines
 html/virt-inspector.1.html
 html/virt-v2v.1.html
 images/100kallnewlines
diff --git a/HACKING b/HACKING
index 747c3c5..7a4735c 100644 (file)
--- a/HACKING
+++ b/HACKING
@@ -39,6 +39,9 @@ contrib/
 daemon/
        The daemon that runs inside the guest and carries out actions.
 
 daemon/
        The daemon that runs inside the guest and carries out actions.
 
+df/
+       The virt-df tool.
+
 examples/
        The examples.
 
 examples/
        The examples.
 
index e2f7d1d..fe960b7 100644 (file)
@@ -44,6 +44,9 @@ endif
 if HAVE_V2V
 SUBDIRS += v2v
 endif
 if HAVE_V2V
 SUBDIRS += v2v
 endif
+if HAVE_DF
+SUBDIRS += df
+endif
 
 EXTRA_DIST = \
        config.rpath \
 
 EXTRA_DIST = \
        config.rpath \
@@ -126,6 +129,7 @@ html/recipes.html: $(wildcard recipes/*.sh) $(wildcard recipes/*.html) $(wildcar
        mv $@-t $@
 
 HTMLFILES = html/guestfs.3.html html/guestfish.1.html \
        mv $@-t $@
 
 HTMLFILES = html/guestfs.3.html html/guestfish.1.html \
+       html/virt-df.1.html \
        html/virt-inspector.1.html \
        html/virt-v2v.1.html \
        html/recipes.html \
        html/virt-inspector.1.html \
        html/virt-v2v.1.html \
        html/recipes.html \
index 2cb898a..30d7c1d 100644 (file)
@@ -506,7 +506,7 @@ AC_CHECK_PROG([GHC],[ghc],[ghc],[no])
 AM_CONDITIONAL([HAVE_HASKELL],
     [test "x$GHC" != "xno"])
 
 AM_CONDITIONAL([HAVE_HASKELL],
     [test "x$GHC" != "xno"])
 
-dnl Check for Perl modules needed by the inspector and V2V.
+dnl Check for Perl modules needed by virt-df, inspector and V2V.
 missing_perl_modules=no
 for pm in Pod::Usage Getopt::Long Sys::Virt Data::Dumper XML::Writer; do
     AC_MSG_CHECKING([for $pm])
 missing_perl_modules=no
 for pm in Pod::Usage Getopt::Long Sys::Virt Data::Dumper XML::Writer; do
     AC_MSG_CHECKING([for $pm])
@@ -518,9 +518,11 @@ for pm in Pod::Usage Getopt::Long Sys::Virt Data::Dumper XML::Writer; do
     fi
 done
 if test "x$missing_perl_modules" = "xyes"; then
     fi
 done
 if test "x$missing_perl_modules" = "xyes"; then
-    AC_MSG_WARN([some Perl modules required to compile virt-inspector and virt-v2v are missing])
+    AC_MSG_WARN([some Perl modules required to compile virt-df, virt-inspector and virt-v2v are missing])
 fi
 
 fi
 
+AM_CONDITIONAL([HAVE_DF],
+    [test "x$PERL" != "xno" -a "x$missing_perl_modules" != "xyes"])
 AM_CONDITIONAL([HAVE_INSPECTOR],
     [test "x$PERL" != "xno" -a "x$missing_perl_modules" != "xyes"])
 AM_CONDITIONAL([HAVE_V2V],
 AM_CONDITIONAL([HAVE_INSPECTOR],
     [test "x$PERL" != "xno" -a "x$missing_perl_modules" != "xyes"])
 AM_CONDITIONAL([HAVE_V2V],
@@ -559,6 +561,7 @@ AC_CONFIG_FILES([Makefile
                 ruby/Makefile ruby/Rakefile
                 java/Makefile
                 haskell/Makefile
                 ruby/Makefile ruby/Rakefile
                 java/Makefile
                 haskell/Makefile
+                df/Makefile
                 inspector/Makefile
                 v2v/Makefile
                 libguestfs.pc
                 inspector/Makefile
                 v2v/Makefile
                 libguestfs.pc
@@ -586,6 +589,8 @@ echo -n "Java bindings ....................... "
 if test "x$HAVE_JAVA_TRUE" = "x"; then echo "yes"; else echo "no"; fi
 echo -n "Haskell bindings .................... "
 if test "x$HAVE_HASKELL" = "x"; then echo "yes"; else echo "no"; fi
 if test "x$HAVE_JAVA_TRUE" = "x"; then echo "yes"; else echo "no"; fi
 echo -n "Haskell bindings .................... "
 if test "x$HAVE_HASKELL" = "x"; then echo "yes"; else echo "no"; fi
+echo -n "virt-df ............................. "
+if test "x$HAVE_DF" = "x"; then echo "yes"; else echo "no"; fi
 echo -n "virt-inspector ...................... "
 if test "x$HAVE_INSPECTOR" = "x"; then echo "yes"; else echo "no"; fi
 echo -n "virt-v2v ............................ "
 echo -n "virt-inspector ...................... "
 if test "x$HAVE_INSPECTOR" = "x"; then echo "yes"; else echo "no"; fi
 echo -n "virt-v2v ............................ "
diff --git a/df/Makefile.am b/df/Makefile.am
new file mode 100644 (file)
index 0000000..4ff2fb1
--- /dev/null
@@ -0,0 +1,48 @@
+# libguestfs virt-df
+# Copyright (C) 2009 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+EXTRA_DIST = \
+       run-df-locally \
+       virt-df.pl
+
+if HAVE_DF
+
+man_MANS = virt-df.1
+
+noinst_DATA = @top_builddir@/html/virt-df.1.html
+
+virt-df.1: virt-df.pl
+       $(POD2MAN) \
+         --section 1 \
+         -c "Virtualization Support" \
+         --release "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" \
+         $< > $@
+
+@top_builddir@/html/virt-df.1.html: virt-df.pl
+       mkdir -p @top_builddir@/html
+       cd @top_builddir@ && pod2html \
+         --css 'pod.css' \
+         --title 'virt-df, display free space on virtual filesystems' \
+         --htmldir html \
+         --outfile html/virt-df.1.html \
+         df/$<
+
+install-data-hook:
+       mkdir -p $(DESTDIR)$(bindir)
+       install -m 0755 virt-df.pl $(DESTDIR)$(bindir)/virt-df
+
+endif
diff --git a/df/run-df-locally b/df/run-df-locally
new file mode 100755 (executable)
index 0000000..3557443
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+# virt-df
+# Copyright (C) 2009 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# This script sets up the environment so you can run virt-df in place
+# without needing to do 'make install' first. You can also run virt-df
+# by creating a symlink to this script and putting it in your path.
+#
+# Use it like this:
+#   ./run-df-locally [usual virt-df args ...]
+
+use strict;
+use warnings;
+
+use File::Basename qw(dirname);
+use File::Spec;
+use Cwd qw(abs_path);
+
+my $path = $0;
+
+# Follow symlinks until we get to the real file
+while(-l $path) {
+    my $link = readlink($path);
+    if(File::Spec->file_name_is_absolute($link)) {
+        $path = $link;
+    } else {
+        $path = File::Spec->catfile(dirname($path), $link);
+    }
+}
+
+# Get the absolute path of the parent directory
+$path = abs_path(dirname($path).'/..');
+
+$ENV{LD_LIBRARY_PATH} = $path.'/src/.libs';
+$ENV{LIBGUESTFS_PATH} = $path.'/appliance';
+$ENV{PERL5LIB}        = $path.'/perl/blib/lib:'.$path.'/perl/blib/arch';
+
+exec('perl', $path.'/df/virt-df.pl', @ARGV);
diff --git a/df/virt-df.pl b/df/virt-df.pl
new file mode 100755 (executable)
index 0000000..a4664a8
--- /dev/null
@@ -0,0 +1,155 @@
+#!/usr/bin/perl -w
+# virt-df
+# Copyright (C) 2009 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+use warnings;
+use strict;
+
+use Sys::Guestfs;
+use Sys::Guestfs::Lib qw(open_guest get_partitions resolve_windows_path
+  inspect_all_partitions inspect_partition
+  inspect_operating_systems mount_operating_system inspect_in_detail);
+use Pod::Usage;
+use Getopt::Long;
+use Data::Dumper;
+use File::Temp qw/tempdir/;
+use XML::Writer;
+
+=encoding utf8
+
+=head1 NAME
+
+virt-df - Display free space on virtual filesystems
+
+=head1 SYNOPSIS
+
+ virt-df [--options]
+
+ virt-df [--options] guest [guest ...]
+
+ virt-df [--options] disk.img [disk.img ...]
+
+=head1 DESCRIPTION
+
+
+
+
+
+
+=head1 OPTIONS
+
+=over 4
+
+=cut
+
+my $help;
+
+=item B<--help>
+
+Display brief help.
+
+=cut
+
+my $uri;
+
+=item B<--connect URI> | B<-c URI>
+
+If using libvirt, connect to the given I<URI>.  If omitted,
+then we connect to the default libvirt hypervisor.
+
+Libvirt is only used if you specify a C<domname> on the
+command line.  If you specify guest block devices directly,
+then libvirt is not used at all.
+
+=cut
+
+GetOptions ("help|?" => \$help,
+           "connect|c=s" => \$uri,
+    ) or pod2usage (2);
+pod2usage (1) if $help;
+pod2usage ("$0: no image or VM names given") if @ARGV == 0;
+
+# my $g;
+# if ($uri) {
+#     $g = open_guest (\@ARGV, rw => $rw, address => $uri);
+# } else {
+#     $g = open_guest (\@ARGV, rw => $rw);
+# }
+
+# $g->launch ();
+# $g->wait_ready ();
+
+# # List of possible filesystems.
+# my @partitions = get_partitions ($g);
+
+# # Now query each one to build up a picture of what's in it.
+# my %fses =
+#     inspect_all_partitions ($g, \@partitions,
+#       use_windows_registry => $windows_registry);
+
+# #print "fses -----------\n";
+# #print Dumper(\%fses);
+
+# my $oses = inspect_operating_systems ($g, \%fses);
+
+# #print "oses -----------\n";
+# #print Dumper($oses);
+
+# # Mount up the disks and check for applications.
+
+# my $root_dev;
+# foreach $root_dev (sort keys %$oses) {
+#     my $os = $oses->{$root_dev};
+#     mount_operating_system ($g, $os);
+#     inspect_in_detail ($g, $os);
+#     $g->umount_all ();
+# }
+
+=head1 SEE ALSO
+
+L<virt-inspector(1)>,
+L<guestfs(3)>,
+L<guestfish(1)>,
+L<Sys::Guestfs(3)>,
+L<Sys::Guestfs::Lib(3)>,
+L<Sys::Virt(3)>,
+L<http://libguestfs.org/>.
+
+For Windows registry parsing we require the C<reged> program
+from L<http://home.eunet.no/~pnordahl/ntpasswd/>.
+
+=head1 AUTHOR
+
+Richard W.M. Jones L<http://et.redhat.com/~rjones/>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2009 Red Hat Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.