Start virt-tools-get-key.
authorRichard Jones <rjones@trick.home.annexia.org>
Thu, 24 Sep 2009 16:13:10 +0000 (17:13 +0100)
committerRichard Jones <rjones@trick.home.annexia.org>
Thu, 24 Sep 2009 16:13:10 +0000 (17:13 +0100)
linux/50-virt-tools.in
linux/Makefile.am
tools/virt-ifconfig.pl
tools/virt-tools-get-key.pl
tools/virt-uname.pl
virt-tools.spec.in

index 5b7073f..b723262 100644 (file)
@@ -16,7 +16,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-/sbin/ip addr show dev "$1" > @localstatedir@/run/virt-tools/ip-"$1"
+/sbin/ip addr show dev "$1" > @localstatedir@/lib/virt-tools/ip-"$1"
 
 # Ensure the blocks get written to disk.
 sync
index b8339c7..4e21609 100644 (file)
@@ -20,7 +20,7 @@ nmconfdir = $(sysconfdir)/NetworkManager/dispatcher.d
 nmconf_SCRIPTS = 50-virt-tools
 
 # Directory for sharing data with the host.
-sharingdir = $(localstatedir)/run/virt-tools
+sharingdir = $(localstatedir)/lib/virt-tools
 
 install-data-hook:
        $(MKDIR_P) $(DESTDIR)$(sharingdir)
index 523c125..3455ed5 100755 (executable)
@@ -19,9 +19,7 @@
 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 Sys::Guestfs::Lib qw(open_guest get_partitions);
 use Pod::Usage;
 use Getopt::Long;
 use Locale::TextDomain 'virt-tools';
@@ -171,7 +169,7 @@ sub do_ifconfig
         eval {
             $g->mount_ro ($partition, "/");
            my $dir;
-           my @dirs = ("/var/run/virt-tools", "/run/virt-tools");
+           my @dirs = ("/var/lib/virt-tools", "/lib/virt-tools");
            foreach $dir (@dirs) {
                if ($g->is_dir ($dir)) {
                    my @names = $g->ls ($dir);
index 0b478b8..3dce2db 100755 (executable)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-use Net::SNMP;
+use Sys::Virt;
+use Sys::Guestfs;
+use Sys::Guestfs::Lib qw(open_guest get_partitions);
+use Pod::Usage;
+use Getopt::Long;
+use Locale::TextDomain 'virt-tools';
 
+=encoding utf8
+
+=head1 NAME
+
+virt-tools-get-key - virt-tools helper to get the guest's key
+
+=head1 SYNOPSIS
+
+ virt-tools-get-key [--options] domname
+
+=head1 DESCRIPTION
+
+This helper program is used by L<virt-tools(8)> to get the guest's
+secret key.  If you don't know anything about this, you probably want
+to start by reading L<virt-tools(8)>.  Otherwise read on.
+
+The single command line argument should be a libvirt domain name (see
+C<virsh list --all>).
+
+=head2 KEY CACHE
+
+The cache is described in detail in L<virt-tools(8)>.  In brief, if
+C<@LOCALSTATEDIR@/lib/virt-tools/keys/E<lt>UUIDE<gt>> exists (where
+E<lt>UUIDE<gt> is the guest's UUID), then the contents of that file
+are returned directly.  Otherwise we will try to create this file
+after reading the key so that we don't have to read the key out of the
+guest's filesystem each time.
+
+=head1 OPTIONS
+
+=over 4
+
+=cut
+
+my $help;
+
+=item B<--help>
+
+Display brief help.
+
+=cut
+
+my $version;
+
+=item B<--version>
+
+Display version number and exit.
+
+=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.
+
+=cut
+
+my $verbose;
+
+=item B<--verbose> | B<-v>
+
+Enable verbose messages, useful for debugging.
+
+=back
+
+=cut
+
+GetOptions ("help|?" => \$help,
+            "version" => \$version,
+            "connect|c=s" => \$uri,
+            "verbose|v" => \$verbose,
+    ) or pod2usage (2);
+pod2usage (1) if $help;
+if ($version) {
+    print "@PACKAGE_STRING@\n";
+    exit
+}
+
+die __"no domain name or UUID listed on the command line\n" unless @ARGV == 1;
+
+my $g;
+
+if ($uri) {
+    $g = open_guest (\@ARGV, address => $uri);
+} else {
+    $g = open_guest (\@ARGV);
+}
+
+$g->launch ();
+
+# Don't care about mountpoints.  Instead, just look for a
+# directory with one of a selection of names on one of the
+# partitions that we found.
+my @partitions = get_partitions ($g);
+
+my $key;
+
+SEARCH:
+foreach my $partition (@partitions) {
+    eval {
+       $g->mount_ro ($partition, "/");
+       my $dir;
+       my @dirs = ("/var/lib/virt-tools", "/lib/virt-tools");
+       foreach $dir (@dirs) {
+           if ($g->is_dir ($dir) && $g->is_file ("$dir/key")) {
+               $key = $g->cat ("$dir/key");
+               last SEARCH;
+           }
+       }
+    };
+    $g->umount_all ();
+}
+
+undef $g;
+
+die __x("{n}: no key found in guest.\nDoes it have the virt-tool-guest package installed?\n",
+       n => $ARGV[0])
+    unless $key;
+
+print $key;
+
+exit 0;
+
+=head1 SEE ALSO
+
+L<virt-ifconfig(8)>,
+L<guestfs(3)>,
+L<guestfish(1)>,
+L<Sys::Guestfs(3)>,
+L<Sys::Guestfs::Lib(3)>,
+L<Sys::Virt(3)>,
+L<http://libguestfs.org/>.
+
+=head1 AUTHORS
+
+=over 4
+
+=item *
+
+Richard W.M. Jones (C<rjones at redhat dot com>)
+
+=item *
+
+Matthew Booth (C<mbooth at redhat dot com>)
+
+=back
+
+=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.
index 4c7e253..ee1ced3 100755 (executable)
@@ -325,10 +325,10 @@ guest side.
 =head2 COMMUNICATIONS DIRECTORY
 
 The guest writes various static, mostly unchanging, information into
-its own directory.  On Linux the directory is C</var/lib/virt-tools/>
-and under Windows it is C<%systemroot%\virttool\>.  In the discussion
-below, this communications directory is referred to as
-C<$GUESTCOMMSDIR>.
+its own directory.  On Linux the directory is
+C<@LOCALSTATEDIR@/lib/virt-tools/> and under Windows it is
+C<%systemroot%\virttool\>.  In the discussion below, this
+communications directory is referred to as C<$GUESTCOMMSDIR>.
 
 The host is able to read files out of this directory using
 L<libguestfs(3)> (without any cooperation needed by the guest).
@@ -426,13 +426,14 @@ verify its operation:
 
 C<virt-tools-get-key> caches the keys of guests that it has seen
 before so it doesn't have to read them each time.  The cache is in
-C</var/lib/virt-tools/keys/> (in the host).
+C<@LOCALSTATEDIR@/lib/virt-tools/keys/> (in the host).
 
 You can just delete the files in this directory at any time, I<or> you
 can drop a file in here which contains the key of a guest.
 
-To do this, create a file C</var/lib/virt-tools/keys/E<lt>UUIDE<gt>>
-where E<lt>UUIDE<gt> is the guest's UUID as displayed by this command:
+To do this, create a file
+C<@LOCALSTATEDIR@/lib/virt-tools/keys/E<lt>UUIDE<gt>> where
+E<lt>UUIDE<gt> is the guest's UUID as displayed by this command:
 
  virsh domuuid <name>
 
@@ -486,7 +487,8 @@ command by hand.
 
 C<virt-tools-get-transport> caches the transports of guests that it
 has seen before so it doesn't have to determine them each time.  The
-cache is in C</var/lib/virt-tools/transports/> (in the host).
+cache is in C<@LOCALSTATEDIR@/lib/virt-tools/transports/> (in the
+host).
 
 As for the L</KEY CACHE>, this directory is just some files that are
 named after the UUID of the guest, containing the transport.
index 343b406..8443d90 100644 (file)
@@ -84,7 +84,7 @@ rm -rf $RPM_BUILD_ROOT
 %defattr(-,root,root,-)
 %doc COPYING
 %{_sysconfdir}/NetworkManager/dispatcher.d/50-virt-tools
-%dir %{_localstatedir}/run/virt-tools/
+%dir %{_localstatedir}/lib/virt-tools/
 
 
 %changelog