diff options
author | Richard Jones <rjones@trick.home.annexia.org> | 2009-07-10 10:44:20 +0100 |
---|---|---|
committer | Richard Jones <rjones@trick.home.annexia.org> | 2009-07-10 10:44:20 +0100 |
commit | 67a3d3e3915a18a58702b7e68f514d9dc9a82a2e (patch) | |
tree | c645bbd3cc98adcad68cd8fecc89406f3da819fb /df | |
parent | 9b56a72636ba7511f7bef19572c161327b9a01df (diff) | |
download | libguestfs-67a3d3e3915a18a58702b7e68f514d9dc9a82a2e.tar.gz libguestfs-67a3d3e3915a18a58702b7e68f514d9dc9a82a2e.tar.xz libguestfs-67a3d3e3915a18a58702b7e68f514d9dc9a82a2e.zip |
Added framework for 'virt-df' command.
Diffstat (limited to 'df')
-rw-r--r-- | df/Makefile.am | 48 | ||||
-rwxr-xr-x | df/run-df-locally | 52 | ||||
-rwxr-xr-x | df/virt-df.pl | 155 |
3 files changed, 255 insertions, 0 deletions
diff --git a/df/Makefile.am b/df/Makefile.am new file mode 100644 index 00000000..4ff2fb11 --- /dev/null +++ b/df/Makefile.am @@ -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 index 00000000..35574438 --- /dev/null +++ b/df/run-df-locally @@ -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 index 00000000..a4664a82 --- /dev/null +++ b/df/virt-df.pl @@ -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. |