Skip to content

Commit 3b21c30

Browse files
committed
Fixup: Adjust device_to_mac_table code and add table print
Signed-off-by: Changlei Li <[email protected]>
1 parent 402671f commit 3b21c30

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

ocaml/xapi/xapi_pif.ml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,40 @@ let make_tables ~__context ~host =
5858
let dbg = Context.string_of_task __context in
5959
let device_to_position_table = Net.Interface.get_interface_positions dbg () in
6060
let device_to_mac_table =
61-
let devices =
62-
List.filter
63-
(fun name -> Net.Interface.is_physical dbg name)
64-
(Net.Interface.get_all dbg ())
65-
in
66-
List.combine devices
67-
(List.map (fun name -> Net.Interface.get_mac dbg name) devices)
61+
List.filter_map
62+
(fun name ->
63+
if Net.Interface.is_physical dbg name then
64+
Some (name, Net.Interface.get_mac dbg name)
65+
else
66+
None
67+
)
68+
(Net.Interface.get_all dbg ())
6869
in
6970
(* Get all PIFs on this host *)
70-
let pifs =
71+
let pif_to_device_table =
7172
Db.PIF.get_records_where ~__context
7273
~expr:
7374
(And
7475
( Eq (Field "host", Literal (Ref.string_of host))
7576
, Eq (Field "physical", Literal "true")
7677
)
7778
)
79+
|> List.map (fun (pref, prec) -> (pref, prec.API.pIF_device))
7880
in
79-
{
80-
device_to_position_table
81-
; device_to_mac_table
82-
; pif_to_device_table=
83-
List.map (fun (pref, prec) -> (pref, prec.API.pIF_device)) pifs
84-
}
81+
debug "tables: device_to_position_table = %s"
82+
(String.concat "; "
83+
(List.map
84+
(fun (d, p) -> d ^ ":" ^ string_of_int p)
85+
device_to_position_table
86+
)
87+
) ;
88+
debug "tables: device_to_mac_table = %s"
89+
(String.concat "; "
90+
(List.map (fun (d, m) -> d ^ ":" ^ m) device_to_mac_table)
91+
) ;
92+
debug "tables: pif_to_device_table = %s"
93+
(String.concat "; " (List.map snd pif_to_device_table)) ;
94+
{device_to_position_table; device_to_mac_table; pif_to_device_table}
8595

8696
let refresh_internal ~__context ~interface_tables ~self =
8797
let dbg = Context.string_of_task __context in

0 commit comments

Comments
 (0)