Skip to content

Commit c455eb0

Browse files
committed
Fixup: avoid read inventory when device already renamed
Signed-off-by: Changlei Li <[email protected]>
1 parent ae7dc42 commit c455eb0

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

ocaml/networkd/lib/network_config.ml

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,35 @@ let read_management_conf interface_order =
132132
order
133133
in
134134
let bridge_name =
135-
let inventory_bridge =
136-
try Some (Inventory.lookup Inventory._management_interface)
137-
with Inventory.Missing_inventory_key _ -> None
135+
let get_bridge_name () =
136+
if vlan = None then
137+
bridge_naming_convention device pos_opt
138+
else
139+
(* At this point, we don't know what the VLAN bridge name will be,
140+
* so use a temporary name. Xapi will replace the bridge once the name
141+
* has been decided on. *)
142+
temp_vlan
138143
in
139-
match inventory_bridge with
140-
| Some "" | None ->
141-
let bridge =
142-
if vlan = None then
143-
bridge_naming_convention device pos_opt
144-
else
145-
(* At this point, we don't know what the VLAN bridge name will be,
146-
* so use a temporary name. Xapi will replace the bridge once the name
147-
* has been decided on. *)
148-
temp_vlan
149-
in
150-
debug "No management bridge in inventory file... using %s" bridge ;
151-
if not Network_utils.device_already_renamed then
152-
write_manage_iface_to_inventory bridge ;
153-
bridge
154-
| Some bridge ->
155-
debug "Management bridge in inventory file: %s" bridge ;
156-
bridge
144+
if Network_utils.device_already_renamed then (
145+
let inventory_bridge =
146+
try Some (Inventory.lookup Inventory._management_interface)
147+
with Inventory.Missing_inventory_key _ -> None
148+
in
149+
match inventory_bridge with
150+
| Some "" | None ->
151+
let bridge = get_bridge_name () in
152+
debug "No management bridge in inventory file... using %s" bridge ;
153+
bridge
154+
| Some bridge ->
155+
debug "Management bridge in inventory file: %s" bridge ;
156+
bridge
157+
) else
158+
(* As design: If interfaces are sorted by networkd, the management
159+
interface need be written to inventory by networkd, too *)
160+
let bridge = get_bridge_name () in
161+
debug "management bridge name %s" bridge ;
162+
write_manage_iface_to_inventory bridge ;
163+
bridge
157164
in
158165
let mac = Network_utils.Ip.get_mac device in
159166
let dns = parse_dns_config args in

0 commit comments

Comments
 (0)