Skip to content

Commit

Permalink
v2v: Add s_mapping_explanation field to source NIC.
Browse files Browse the repository at this point in the history
Instead of storing the original network name (s_vnet_orig) in the
source NIC struct and then trying to guess what happened much later
when we're writing target metadata, get our newly created Networks
abstract data type to store the precise mapping explanation.
  • Loading branch information
rwmjones committed Jul 9, 2018
1 parent c3bec46 commit 9a25ac6
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 28 deletions.
10 changes: 4 additions & 6 deletions v2v/create_libvirt_xml.ml
Expand Up @@ -243,7 +243,7 @@ let create_libvirt_xml ?pool source target_buses guestcaps
| Virtio_net -> "virtio" | E1000 -> "e1000" | RTL8139 -> "rtl8139" in
List.map (
fun { s_mac = mac; s_vnet_type = vnet_type;
s_vnet = vnet; s_vnet_orig = vnet_orig } ->
s_vnet = vnet; s_mapping_explanation = explanation } ->
let vnet_type_str =
match vnet_type with
| Bridge -> "bridge" | Network -> "network" in
Expand All @@ -254,11 +254,9 @@ let create_libvirt_xml ?pool source target_buses guestcaps
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
match explanation with
| Some explanation -> Comment explanation :: children
| None -> children in
e "interface" [ "type", vnet_type_str ] children in

(match mac with
Expand Down
10 changes: 5 additions & 5 deletions v2v/create_ovf.ml
Expand Up @@ -916,7 +916,7 @@ and add_networks nics guestcaps ovf_flavour ovf =
(* Iterate over the NICs, adding them to the OVF document. *)
List.iteri (
fun i { s_mac = mac; s_vnet_type = vnet_type;
s_vnet = vnet; s_vnet_orig = vnet_orig } ->
s_vnet = vnet; s_mapping_explanation = explanation } ->
let dev = sprintf "eth%d" i in

let model =
Expand All @@ -929,10 +929,10 @@ and add_networks nics guestcaps ovf_flavour ovf =
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
(match explanation with
| None -> ()
| Some explanation ->
append_child (Comment explanation) network_section
);

let network = e "Network" ["ovf:name", vnet] [] in
Expand Down
5 changes: 3 additions & 2 deletions v2v/input_disk.ml
Expand Up @@ -72,8 +72,9 @@ class input_disk input_format disk = object
let network = {
s_mac = None;
s_nic_model = None;
s_vnet = "default"; s_vnet_orig = "default";
s_vnet_type = Network
s_vnet = "default";
s_vnet_type = Network;
s_mapping_explanation = None
} in

let source = {
Expand Down
5 changes: 3 additions & 2 deletions v2v/input_vmx.ml
Expand Up @@ -372,8 +372,9 @@ and find_nics vmx =
| Some _ | None -> Network in
Some (port,
{ s_mac = mac; s_nic_model = model;
s_vnet = vnet; s_vnet_orig = vnet;
s_vnet_type = vnet_type })
s_vnet = vnet;
s_vnet_type = vnet_type;
s_mapping_explanation = None })
| _ -> None
) nics in
let nics = List.filter_map identity nics in
Expand Down
32 changes: 28 additions & 4 deletions v2v/networks.ml
Expand Up @@ -18,6 +18,8 @@

(* Network, bridge mapping. *)

open Printf

open Tools_utils
open Common_gettext.Gettext

Expand All @@ -40,20 +42,42 @@ let map t nic =
| Network ->
(try
let vnet = StringMap.find nic.s_vnet t.network_map in
{ nic with s_vnet = vnet }
{ nic with
s_vnet = vnet;
s_mapping_explanation =
Some (sprintf "network mapped from %S to %S"
nic.s_vnet vnet)
}
with Not_found ->
match t.default_network with
| None -> nic (* no mapping done *)
| Some default_network -> { nic with s_vnet = default_network }
| Some default_network ->
{ nic with
s_vnet = default_network;
s_mapping_explanation =
Some (sprintf "network mapped from %S to default %S"
nic.s_vnet default_network)
}
)
| Bridge ->
(try
let vnet = StringMap.find nic.s_vnet t.bridge_map in
{ nic with s_vnet = vnet }
{ nic with
s_vnet = vnet;
s_mapping_explanation =
Some (sprintf "bridge mapped from %S to %S"
nic.s_vnet vnet)
}
with Not_found ->
match t.default_bridge with
| None -> nic (* no mapping done *)
| Some default_bridge -> { nic with s_vnet = default_bridge }
| Some default_bridge ->
{ nic with
s_vnet = default_bridge;
s_mapping_explanation =
Some (sprintf "bridge mapped from %S to default %S"
nic.s_vnet default_bridge)
}
)

let create () = {
Expand Down
5 changes: 4 additions & 1 deletion v2v/networks.mli
Expand Up @@ -45,4 +45,7 @@ val add_default_bridge : t -> string -> unit

val map : t -> Types.source_nic -> Types.source_nic
(** Apply the mapping to the source NIC, returning the updated
NIC with possibly modified [s_vnet] field. *)
NIC with possibly modified [s_vnet] field.
[s_mapping_explanation] is set in the output with an
informational message about what was done. *)
4 changes: 2 additions & 2 deletions v2v/parse_libvirt_xml.ml
Expand Up @@ -445,8 +445,8 @@ let parse_libvirt_xml ?conn xml =
s_mac = mac;
s_nic_model = model;
s_vnet = vnet;
s_vnet_orig = vnet;
s_vnet_type = vnet_type
s_vnet_type = vnet_type;
s_mapping_explanation = None
} in
List.push_front nic nics
in
Expand Down
2 changes: 1 addition & 1 deletion v2v/parse_ovf_from_ova.ml
Expand Up @@ -238,8 +238,8 @@ and parse_nics xpathctx =
s_mac = mac;
s_nic_model = nic_model;
s_vnet = vnet;
s_vnet_orig = vnet;
s_vnet_type = vnet_type;
s_mapping_explanation = None
} in
List.push_front nic nics
done;
Expand Down
6 changes: 3 additions & 3 deletions v2v/test-v2v-networks-and-bridges-expected.xml
Expand Up @@ -3,7 +3,7 @@
<source bridge='bridge1'/>
</interface>
<interface type='bridge'>
<!-- bridge mapped from "bob" to "bridge2" -->
<!-- bridge mapped from "bob" to default "bridge2" -->
<source bridge='bridge2'/>
<mac address='52:54:00:01:02:03'/>
</interface>
Expand All @@ -23,12 +23,12 @@
<mac address='52:54:00:01:02:06'/>
</interface>
<interface type='network'>
<!-- network mapped from "george" to "network4" -->
<!-- network mapped from "george" to default "network4" -->
<source network='network4'/>
<mac address='52:54:00:01:02:07'/>
</interface>
<interface type='network'>
<!-- network mapped from "ringo" to "network4" -->
<!-- network mapped from "ringo" to default "network4" -->
<source network='network4'/>
<mac address='52:54:00:01:02:08'/>
</interface>
2 changes: 1 addition & 1 deletion v2v/types.ml
Expand Up @@ -71,8 +71,8 @@ and source_nic = {
s_mac : string option;
s_nic_model : s_nic_model option;
s_vnet : string;
s_vnet_orig : string;
s_vnet_type : vnet_type;
s_mapping_explanation : string option;
}
and s_nic_model = Source_other_nic of string |
Source_rtl8139 | Source_e1000 | Source_virtio_net
Expand Down
5 changes: 4 additions & 1 deletion v2v/types.mli
Expand Up @@ -130,8 +130,11 @@ and source_nic = {
s_mac : string option; (** MAC address. *)
s_nic_model : s_nic_model option; (** Network adapter model. *)
s_vnet : string; (** Source network name. *)
s_vnet_orig : string; (** Original network (if we map it). *)
s_vnet_type : vnet_type; (** Source network type. *)
s_mapping_explanation : string option;
(** If the NIC or network was mapped, this contains an English
explanation of the change which can be written to the target
hypervisor metadata for informational purposes. *)
}
(** Network adapter models. *)
and s_nic_model = Source_other_nic of string |
Expand Down

0 comments on commit 9a25ac6

Please sign in to comment.