[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 2/4] MetadataReader: Allow different libvirt connections for input and output



Command line option changes:
--config -> -c
-c -> -ic

New option -oc specifies output connection.
---
 lib/Sys/VirtV2V/MetadataReader.pm            |   20 ++++----
 lib/Sys/VirtV2V/MetadataReader/LibVirt.pm    |    9 +++-
 lib/Sys/VirtV2V/MetadataReader/LibVirtXML.pm |    5 +-
 v2v/virt-v2v.pl                              |   66 +++++++++++++++-----------
 4 files changed, 59 insertions(+), 41 deletions(-)

diff --git a/lib/Sys/VirtV2V/MetadataReader.pm b/lib/Sys/VirtV2V/MetadataReader.pm
index 6a1bec3..7b5e7d5 100644
--- a/lib/Sys/VirtV2V/MetadataReader.pm
+++ b/lib/Sys/VirtV2V/MetadataReader.pm
@@ -36,7 +36,9 @@ Sys::VirtV2V::MetadataReader - Read a variety of guest metadata formats
 
  use Sys::VirtV2V::MetadataReader;
 
- $reader = Sys::VirtV2V::MetadataReader->instantiate("libvirtxml", $vmm, @args);
+ $reader = Sys::VirtV2V::MetadataReader->instantiate("libvirtxml", $uri,
+                                                     $config, @args);
+ exit 1 unless($mdr->is_configured());
  $dom = $reader->get_dom();
 
 =head1 DESCRIPTION
@@ -53,7 +55,7 @@ implements methods to access backends.
 
 =over
 
-=item instantiate(name, vmm, @args)
+=item instantiate(name, $uri, $config, @args)
 
 =over
 
@@ -61,13 +63,13 @@ implements methods to access backends.
 
 The name of the module to instantiate.
 
-=item config
+=item uri
 
-A parsed virt-v2v configuration file.
+A URI describing the target connection.
 
-=item vmm
+=item config
 
-A Sys::Virt connection.
+A parsed virt-v2v configuration file.
 
 =item args
 
@@ -83,15 +85,15 @@ sub instantiate
 {
     my $class = shift;
 
-    my ($name, $config, $vmm, @args) = @_;
+    my ($name, $uri, $config, @args) = @_;
 
     defined($name) or carp("instantiate called without name argument");
+    defined($uri)  or carp("instantiate called without uri argument");
     defined($config) or carp("instantiate called without config argument");
-    defined($vmm) or carp("instantiate called without vmm argument");
 
     foreach my $module ($class->modules()) {
         if($module->get_name() eq $name) {
-            return $module->_new($config->{$name}, $vmm, @args);
+            return $module->_new($uri, $config->{$name}, @args);
         }
     }
 
diff --git a/lib/Sys/VirtV2V/MetadataReader/LibVirt.pm b/lib/Sys/VirtV2V/MetadataReader/LibVirt.pm
index d18f432..e6fcfff 100644
--- a/lib/Sys/VirtV2V/MetadataReader/LibVirt.pm
+++ b/lib/Sys/VirtV2V/MetadataReader/LibVirt.pm
@@ -38,7 +38,8 @@ Sys::VirtV2V::MetadataReader::LibVirt - Read libvirt metadata from libvirtd
 
  use Sys::VirtV2V::MetadataReader;
 
- $reader = Sys::VirtV2V::MetadataReader->instantiate("libvirt", $vmm, @args);
+ $reader = Sys::VirtV2V::MetadataReader->instantiate
+    ("libvirt", "xen+ssh://xenserver.example.com/", $config, @args);
  $dom = $reader->get_dom();
 
 =head1 DESCRIPTION
@@ -62,12 +63,16 @@ sub _new
 {
     my $class = shift;
 
-    my ($config, $vmm, @args) = @_;
+    my ($uri, $config, @args) = @_;
 
     my $self = {};
 
     bless($self, $class);
 
+    my @vmm_params = (auth => 1);
+    push(@vmm_params, url => $uri) if defined($uri);
+    my $vmm = Sys::Virt->new(@vmm_params);
+
     $self->{vmm} = $vmm;
     $self->_handle_args(@args);
 
diff --git a/lib/Sys/VirtV2V/MetadataReader/LibVirtXML.pm b/lib/Sys/VirtV2V/MetadataReader/LibVirtXML.pm
index 877b7e5..191210f 100644
--- a/lib/Sys/VirtV2V/MetadataReader/LibVirtXML.pm
+++ b/lib/Sys/VirtV2V/MetadataReader/LibVirtXML.pm
@@ -37,7 +37,8 @@ Sys::VirtV2V::MetadataReader::LibVirtXML - Read libvirt XML from a file
 
  use Sys::VirtV2V::MetadataReader;
 
- $reader = Sys::VirtV2V::MetadataReader->instantiate("libvirtxml", $vmm, @args);
+ $reader = Sys::VirtV2V::MetadataReader->instantiate("libvirtxml", undef,
+                                                     $config, @args);
  $dom = $reader->get_dom();
 
 =head1 DESCRIPTION
@@ -61,7 +62,7 @@ sub _new
 {
     my $class = shift;
 
-    my ($config, $vmm, @args) = @_;
+    my ($uri, $config, @args) = @_;
 
     my %obj = ();
     my $self = \%obj;
diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl
index 0ad3c6e..1784f2a 100755
--- a/v2v/virt-v2v.pl
+++ b/v2v/virt-v2v.pl
@@ -46,9 +46,9 @@ virt-v2v - Convert a guest to use KVM
 
  virt-v2v guest-domain.xml
 
- virt-v2v -s virt-v2v.conf guest-domain.xml
+ virt-v2v -c virt-v2v.conf guest-domain.xml
 
- virt-v2v --connect qemu:///system guest-domain.xml
+ virt-v2v -ic qemu:///system guest-domain
 
 =head1 DESCRIPTION
 
@@ -128,21 +128,12 @@ Display version number and exit.
 
 =cut
 
-my $uri;
+my $input_method = "libvirt";
 
-=item B<--connect URI> | B<-c URI>
+=item B<-i input>
 
-Connect to libvirt using the given I<URI>. If omitted, then we connect to the
-default libvirt hypervisor.
-
-=cut
-
-my $input = "libvirt";
-
-=item B<--input input> | B<-i input>
-
-The specified guest description uses the given I<input format>. The default is
-C<libvirt>. Supported options are:
+Specifies how the conversion source metadata can be obtained. The default is
+C<libvirt>.  Supported options are:
 
 =over
 
@@ -158,9 +149,27 @@ Guest argument is the path to an XML file describing a libvirt domain.
 
 =cut
 
+my $input_uri;
+
+=item B<-ic URI>
+
+Specifies the connection to use when using the libvirt input method. If omitted,
+then we connect to the default libvirt hypervisor.
+
+=cut
+
+my $output_uri = "qemu:///system";
+
+=item B<-oc URI>
+
+Specifies the libvirt connection to use to create the converted guest. If
+ommitted, this defaults to qemu:///system.
+
+=cut
+
 my $config_file;
 
-=item B<--config file> | B<-s file>
+=item B<-c file>
 
 Load the virt-v2v configuration from I<file>. There is no default.
 
@@ -173,9 +182,10 @@ Sys::VirtV2V::UserMessage->set_identifier('virt-v2v');
 
 GetOptions ("help|?"      => \$help,
             "version"     => \$version,
-            "connect|c=s" => \$uri,
-            "input|i=s"   => \$input,
-            "config|s=s"  => \$config_file
+            "i=s"         => \$input_method,
+            "ic=s"        => \$input_uri,
+            "oc=s"        => \$output_uri,
+            "c=s"         => \$config_file
     ) or pod2usage(2);
 pod2usage(0) if($help);
 
@@ -186,11 +196,6 @@ if ($version) {
 
 pod2usage(user_message(__"no guest argument given")) if @ARGV == 0;
 
-# Connect to libvirt
-my @vmm_params = (auth => 1);
-push(@vmm_params, uri => $uri) if(defined($uri));
-my $vmm = Sys::Virt->new(@vmm_params);
-
 # Read the config file if one was given
 my $config = {};
 if(defined($config_file)) {
@@ -206,11 +211,11 @@ if(defined($config_file)) {
 }
 
 # Get an appropriate MetadataReader
-my $mdr = Sys::VirtV2V::MetadataReader->instantiate($input, $config,
-                                                    $vmm, @ARGV);
+my $mdr = Sys::VirtV2V::MetadataReader->instantiate($input_method, $input_uri,
+                                                    $config, @ARGV);
 if(!defined($mdr)) {
-    print STDERR user_message __x("{input} is not a valid metadata format",
-                                  input => $input);
+    print STDERR user_message __x("{input} is not a valid input method",
+                                  input => $input_method);
     exit(1);
 }
 
@@ -239,6 +244,11 @@ my $os = inspect_guest($g);
 # Instantiate a GuestOS instance to manipulate the guest
 my $guestos = Sys::VirtV2V::GuestOS->instantiate($g, $os);
 
+# Connect to target libvirt
+my @vmm_params = (auth => 1);
+push(@vmm_params, uri => $output_uri) if(defined($output_uri));
+my $vmm = Sys::Virt->new(@vmm_params);
+
 # Modify the guest and its metadata for the target hypervisor
 Sys::VirtV2V::Converter->convert($vmm, $guestos, $dom, $os);
 
-- 
1.6.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]