[Libguestfs] [PATCH 2/2] Config: Add --bridge and --network command line options

Matthew Booth mbooth at redhat.com
Tue May 4 19:07:17 UTC 2010


This change allows a default network mapping to be specified on the command line
which will be used if no mapping was found in the configuration file, or if no
configuration file was specified.

This change makes it possible to convert all guests except Xen PV guests without
a config file. Xen PV guests will require a config file to specify replacement
kernels. Guests with an old kernel that don't support VirtIO still need the
config file to enable VirtIO support.
---
 lib/Sys/VirtV2V/Config.pm |   20 +++++++++++++++
 v2v/virt-v2v.pl           |   57 +++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/lib/Sys/VirtV2V/Config.pm b/lib/Sys/VirtV2V/Config.pm
index 50c613c..5aa9917 100644
--- a/lib/Sys/VirtV2V/Config.pm
+++ b/lib/Sys/VirtV2V/Config.pm
@@ -312,6 +312,10 @@ sub map_network
     }
 
     unless (defined($mapping)) {
+        # Return the default if it was specified
+        return @{$self->{default_net_mapping}}
+            if (defined($self->{default_net_mapping}));
+
         print STDERR user_message(__x("WARNING: No mapping found for ".
                                       "{type} interface {name} in config ".
                                       "file. The converted guest may not ".
@@ -346,6 +350,22 @@ sub map_network
     return ($newname, $newtype);
 }
 
+=item set_default_net_mapping(name, type)
+
+Set the default network name and type which will be used if no specific mapping
+can be found in a config file.
+
+=cut
+
+sub set_default_net_mapping
+{
+    my $self = shift;
+
+    my ($name, $type) = @_;
+
+    $self->{default_net_mapping} = [ $name, $type ];
+}
+
 =back
 
 =head1 COPYRIGHT
diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl
index d9f6bb3..8395d93 100755
--- a/v2v/virt-v2v.pl
+++ b/v2v/virt-v2v.pl
@@ -178,6 +178,28 @@ my $config_file;
 
 Load the virt-v2v configuration from I<file>. There is no default.
 
+=cut
+
+my $network;
+
+=item B<-n network> | B<--network network>
+
+Map all guest bridges or networks which don't have a mapping in the
+configuration file to I<network>.
+
+This option cannot be used in conjunction with I<--bridge>.
+
+=cut
+
+my $bridge;
+
+=item B<-b bridge> | B<--bridge bridge>
+
+Map all guest bridges or networks which don't have a mapping in the
+configuration file to I<bridge>.
+
+This option cannot be used in conjunction with I<--network>.
+
 =item B<--help>
 
 Display brief help.
@@ -213,12 +235,34 @@ GetOptions ("help|?"      => sub {
             "oc=s"        => \$output_uri,
             "op=s"        => \$output_pool,
             "osd=s"       => \$output_storage_domain,
-            "f|config=s"  => \$config_file
+            "f|config=s"  => \$config_file,
+            "n|network=s" => sub {
+                my (undef, $value) = @_;
+
+                pod2usage({ -message => __("--network may only be specified ".
+                                           "once"),
+                            -exitval => 1 }) if (defined($network));
+                $network = $value;
+            },
+            "b|bridge=s"  => sub {
+                my (undef, $value) = @_;
+
+                pod2usage({ -message => __("--bridge may only be specified ".
+                                           "once"),
+                            -exitval => 1 }) if (defined($bridge));
+                $bridge = $value;
+            },
 ) or pod2usage(2);
 
 # Read the config file if one was given
 my $config = Sys::VirtV2V::Config->new($config_file);
 
+if (defined($network)) {
+    $config->set_default_net_mapping($network, 'network');
+} elsif (defined($bridge)) {
+    $config->set_default_net_mapping($bridge, 'bridge');
+}
+
 my $target;
 if ($output_method eq "libvirt") {
     pod2usage({ -message => __("You must specify an output storage pool ".
@@ -509,7 +553,8 @@ be created. virt-v2v.conf should specify:
 
 =item *
 
-a mapping for the guest's network configuration.
+a mapping for the guest's network configuration, unless a default was specified
+on the command line with I<--bridge> or I<--network>.
 
 =item *
 
@@ -566,8 +611,9 @@ converted.
 
 =back
 
-virt-v2v.conf should specify a mapping for the guest's network configuration.
-See L<virt-v2v.conf(5)> for details.
+virt-v2v.conf should specify a mapping for the guest's network configuration,
+unless a default was specified on the command line with I<--bridge> or
+I<--network>. See L<virt-v2v.conf(5)> for details.
 
 =head3 Authenticating to the ESX server
 
@@ -632,7 +678,8 @@ virt-v2v -f virt-v2v.conf -o rhev -osd <export_sd> <domain>
 =back
 
 Ensure that I<virt-v2v.conf> contains a correct network mapping for your target
-RHEV configuration.
+RHEV configuration, or that you have specified a default mapping on the command
+line with either I<--bridge> or I<--network>.
 
 =head1 RUNNING THE CONVERTED GUEST
 
-- 
1.6.6.1




More information about the Libguestfs mailing list