[Pkg-libvirt-commits] [libguestfs] 164/266: v2v: Store original vnet, and add comment to output metadata when mapping it.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:41:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit 78f725ffd5d06557c401b3618dc4b73722655e00
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu Aug 21 23:25:44 2014 +0100

    v2v: Store original vnet, and add comment to output metadata when mapping it.
    
    When we map the network or bridge names (using --network or --bridge
    command line options), this commit keeps the original name and adds it
    as a comment to the output metadata.
    
    The comment will look something like this:
    
        <interface type='bridge'>
          <!-- bridge mapped from "VM Network" to "bridge1" -->
          <source bridge='bridge1'/>
          <model type='rtl8139'/>
        </interface>
---
 v2v/input_disk.ml                              |  2 +-
 v2v/input_libvirt.ml                           |  7 ++++++-
 v2v/output_RHEV.ml                             |  9 ++++++++-
 v2v/output_libvirt.ml                          | 12 ++++++++++--
 v2v/test-v2v-networks-and-bridges-expected.xml |  7 +++++++
 v2v/types.ml                                   |  1 +
 v2v/types.mli                                  |  1 +
 7 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
index cc76e9c..00a7614 100644
--- a/v2v/input_disk.ml
+++ b/v2v/input_disk.ml
@@ -69,7 +69,7 @@ class input_disk verbose input_format disk = object
     (* Give the guest a simple generic network interface. *)
     let network = {
       s_mac = None;
-      s_vnet = "default";
+      s_vnet = "default"; s_vnet_orig = "default";
       s_vnet_type = Network
     } in
 
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
index f709a0d..fed6438 100644
--- a/v2v/input_libvirt.ml
+++ b/v2v/input_libvirt.ml
@@ -225,7 +225,12 @@ object
         | Some vnet_type ->
           let vnet = xpath_to_string "source/@network | source/@bridge" "" in
           if vnet <> "" then (
-            let nic = { s_mac = mac; s_vnet = vnet; s_vnet_type = vnet_type } in
+            let nic = {
+              s_mac = mac;
+              s_vnet = vnet;
+              s_vnet_orig = vnet;
+              s_vnet_type = vnet_type
+            } in
             nics := nic :: !nics
           )
       done;
diff --git a/v2v/output_RHEV.ml b/v2v/output_RHEV.ml
index 647574a..735eab2 100644
--- a/v2v/output_RHEV.ml
+++ b/v2v/output_RHEV.ml
@@ -563,7 +563,8 @@ object
 
       (* Iterate over the NICs, adding them to the OVF document. *)
       iteri (
-        fun i { s_mac = mac; s_vnet_type = vnet_type; s_vnet = vnet } ->
+        fun i { s_mac = mac; s_vnet_type = vnet_type;
+                s_vnet = vnet; s_vnet_orig = vnet_orig } ->
           let dev = sprintf "eth%d" i in
 
           let model =
@@ -576,6 +577,12 @@ object
                 bus dev;
               "1" *) in
 
+          if vnet_orig <> vnet then (
+            let c = Comment (sprintf "mapped from \"%s\" to \"%s\""
+                               vnet_orig vnet) in
+            append_child c network_section
+          );
+
           let network = e "Network" ["ovf:name", vnet] [] in
           append_child network network_section;
 
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index 099e8c9..fbbd8d6 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -118,16 +118,24 @@ let create_libvirt_xml ?pool source overlays guestcaps =
       match guestcaps.gcaps_net_bus with
       | Virtio_net -> "virtio" | E1000 -> "e1000" | RTL8139 -> "rtl8139" in
     List.map (
-      fun { s_mac = mac; s_vnet_type = vnet_type; s_vnet = vnet } ->
+      fun { s_mac = mac; s_vnet_type = vnet_type;
+            s_vnet = vnet; s_vnet_orig = vnet_orig } ->
         let vnet_type_str =
           match vnet_type with
           | Bridge -> "bridge" | Network -> "network" in
 
         let nic =
-          e "interface" [ "type", vnet_type_str ] [
+          let children = [
             e "source" [ vnet_type_str, vnet ] [];
             e "model" [ "type", net_model ] [];
           ] in
+          let children =
+            if vnet_orig <> vnet then
+              Comment (sprintf "%s mapped from \"%s\" to \"%s\""
+                         vnet_type_str vnet_orig vnet) :: children
+            else
+              children in
+          e "interface" [ "type", vnet_type_str ] children in
 
         (match mac with
         | None -> ()
diff --git a/v2v/test-v2v-networks-and-bridges-expected.xml b/v2v/test-v2v-networks-and-bridges-expected.xml
index 37f66a7..80ac21e 100644
--- a/v2v/test-v2v-networks-and-bridges-expected.xml
+++ b/v2v/test-v2v-networks-and-bridges-expected.xml
@@ -1,33 +1,40 @@
     <interface type='bridge'>
+      <!-- bridge mapped from "VM Network" to "bridge1" -->
       <source bridge='bridge1'/>
       <model type='rtl8139'/>
     </interface>
     <interface type='bridge'>
+      <!-- bridge mapped from "bob" to "bridge2" -->
       <source bridge='bridge2'/>
       <model type='rtl8139'/>
       <mac address='52:54:00:01:02:03'/>
     </interface>
     <interface type='network'>
+      <!-- network mapped from "default" to "network1" -->
       <source network='network1'/>
       <model type='rtl8139'/>
       <mac address='52:54:00:01:02:04'/>
     </interface>
     <interface type='network'>
+      <!-- network mapped from "john" to "network2" -->
       <source network='network2'/>
       <model type='rtl8139'/>
       <mac address='52:54:00:01:02:05'/>
     </interface>
     <interface type='network'>
+      <!-- network mapped from "paul" to "network3" -->
       <source network='network3'/>
       <model type='rtl8139'/>
       <mac address='52:54:00:01:02:06'/>
     </interface>
     <interface type='network'>
+      <!-- network mapped from "george" to "network4" -->
       <source network='network4'/>
       <model type='rtl8139'/>
       <mac address='52:54:00:01:02:07'/>
     </interface>
     <interface type='network'>
+      <!-- network mapped from "ringo" to "network4" -->
       <source network='network4'/>
       <model type='rtl8139'/>
       <mac address='52:54:00:01:02:08'/>
diff --git a/v2v/types.ml b/v2v/types.ml
index 0d7238c..688f009 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -45,6 +45,7 @@ and source_removable = {
 and source_nic = {
   s_mac : string option;
   s_vnet : string;
+  s_vnet_orig : string;
   s_vnet_type : vnet_type;
 }
 and vnet_type = Bridge | Network
diff --git a/v2v/types.mli b/v2v/types.mli
index 5778a11..16babca 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -51,6 +51,7 @@ and source_removable = {
 and source_nic = {
   s_mac : string option;                (** MAC address. *)
   s_vnet : string;                      (** Source network name. *)
+  s_vnet_orig : string;                 (** Original network (if we map it). *)
   s_vnet_type : vnet_type;              (** Source network type. *)
 }
 (** Network interfaces. *)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list