File support_macvtap_networks.patch of Package virt-v2v

Support network configurations such as:

 <interface type='direct'>
   <mac address='f0:de:f1:9b:42:af'/>
   <source dev='eth0' mode='bridge'/>
   <model type='rtl8139'/>
   <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
 </interface>

which should be converted to:

 <interface type='direct'>
   <mac address='f0:de:f1:9b:42:af'/>
   <source dev='eth0' mode='bridge'/>
   <model type='virtio'/>
   <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
 </interface>

It is not possible to map this to another network through the virt-v2v
configuration file, or to validate that the interface works on the target.
Remapping during conversion can be done through the --network or --bridge
parameters.


Index: virt-v2v-0.9.1/lib/Sys/VirtConvert/Connection/LibVirt.pm
===================================================================
--- virt-v2v-0.9.1.orig/lib/Sys/VirtConvert/Connection/LibVirt.pm
+++ virt-v2v-0.9.1/lib/Sys/VirtConvert/Connection/LibVirt.pm
@@ -225,6 +225,13 @@ sub _parse_dom
         $info{mac} = _node_val($nic, 'mac/@address');
         $info{vnet} = _node_val($nic, 'source/@network | source/@bridge');
         $info{vnet_type} = _node_val($nic, '@type');
+        if (($info{vnet_type} eq 'direct') && (!defined($info{vnet}))) {
+            my ($source) = $root->findnodes('devices/interface/source');
+            if (defined($source)) {
+                $info{vnet_source}->{dev} = _node_val($source, '@dev');
+                $info{vnet_source}->{mode} = _node_val($source, '@mode');
+            }
+        }
 
         push(@{$meta{nics}}, \%info);
     }
Index: virt-v2v-0.9.1/lib/Sys/VirtConvert/Connection/LibVirtTarget.pm
===================================================================
--- virt-v2v-0.9.1.orig/lib/Sys/VirtConvert/Connection/LibVirtTarget.pm
+++ virt-v2v-0.9.1/lib/Sys/VirtConvert/Connection/LibVirtTarget.pm
@@ -490,7 +490,12 @@ DOM
         $mac->setAttribute('address', $nic->{mac});
 
         my $source = _append_elem($interface, 'source');
-        $source->setAttribute($vnet_type, $vnet);
+        if (!defined($vnet)) {
+            $source->setAttribute('dev', $nic->{vnet_source}->{dev});
+            $source->setAttribute('mode', $nic->{vnet_source}->{mode});
+        } else {
+            $source->setAttribute($vnet_type, $vnet);
+        }
 
         my $model = _append_elem($interface, 'model');
         $model->setAttribute('type', $guestcaps->{net});
Index: virt-v2v-0.9.1/lib/Sys/VirtConvert/Config.pm
===================================================================
--- virt-v2v-0.9.1.orig/lib/Sys/VirtConvert/Config.pm
+++ virt-v2v-0.9.1/lib/Sys/VirtConvert/Config.pm
@@ -499,10 +499,20 @@ sub map_network
         return @{$self->{default_net_mapping}}
             if (defined($self->{default_net_mapping}));
 
-        logmsg WARN, __x('No mapping found for "network type=\'{type}\' '.
+        if (($oldtype eq 'direct') && (!defined($oldname))) {
+
+            logmsg WARN, __x('No mapping possible for network type=\'{type}\''.
+                         ' Verify network interface configuration or use '.
+                         '\'--network\' or \'--bridge\' parameter to remap '.
+                         'network during conversion.', type => $oldtype);
+        } else {
+
+            logmsg WARN, __x('No mapping found for "network type=\'{type}\' '.
                          'name=\'{name}\'" in config file. The converted '.
                          'guest may not start until its network interface '.
                          'is updated.', type => $oldtype, name => $oldname);
+        }
+
         return;
     }