@@ -22,18 +22,36 @@ exception Read_error
22
22
23
23
exception Write_error
24
24
25
- let empty_config = default_config
25
+ (* If the interface-rename script dir exists, the devices are already renamed
26
+ to eth<N>, the <N> indicates device order *)
27
+ let device_already_renamed =
28
+ let dir = " /etc/sysconfig/network-scripts/interface-rename-data" in
29
+ Sys. file_exists dir && Sys. is_directory dir
30
+
31
+ (* If devices have already been renamed, then interface_order is None,
32
+ since the order is now reflected in their names. *)
33
+ let initial_interface_order = if device_already_renamed then None else Some []
34
+
35
+ let empty_config =
36
+ {default_config with interface_order= initial_interface_order}
26
37
27
38
let config_file_path = " /var/lib/xcp/networkd.db"
28
39
29
40
let temp_vlan = " xentemp"
30
41
31
- let bridge_naming_convention (device : string ) =
32
- if Astring. String.is_prefix ~affix :" eth" device then
42
+ let bridge_name_of_device (device : string ) =
43
+ if String. starts_with ~prefix :" eth" device then
33
44
" xenbr" ^ String. sub device 3 (String. length device - 3 )
34
45
else
35
46
" br" ^ device
36
47
48
+ let bridge_naming_convention (device : string ) pos_opt =
49
+ match pos_opt with
50
+ | Some index ->
51
+ " xenbr" ^ string_of_int index
52
+ | None ->
53
+ bridge_name_of_device device
54
+
37
55
let get_list_from ~sep ~key args =
38
56
List. assoc_opt key args
39
57
|> Option. map (fun v -> Astring.String. cuts ~empty: false ~sep v)
@@ -79,7 +97,11 @@ let parse_dns_config args =
79
97
let domains = get_list_from ~sep: " " ~key: " DOMAIN" args in
80
98
(nameservers, domains)
81
99
82
- let read_management_conf () =
100
+ let write_manage_iface_to_inventory bridge_name =
101
+ info " Writing management interface to inventory: %s" bridge_name ;
102
+ Inventory. update Inventory. _management_interface bridge_name
103
+
104
+ let read_management_conf interface_order =
83
105
try
84
106
let management_conf =
85
107
Xapi_stdext_unix.Unixext. string_of_file
@@ -114,7 +136,12 @@ let read_management_conf () =
114
136
| _ , hd :: _ ->
115
137
hd
116
138
in
117
- Inventory. reread_inventory () ;
139
+ let pos_opt =
140
+ Option. bind interface_order @@ fun order ->
141
+ List. find_map
142
+ (fun x -> if x.name = device then Some x.position else None )
143
+ order
144
+ in
118
145
let bridge_name =
119
146
let inventory_bridge =
120
147
try Some (Inventory. lookup Inventory. _management_interface)
@@ -124,14 +151,16 @@ let read_management_conf () =
124
151
| Some "" | None ->
125
152
let bridge =
126
153
if vlan = None then
127
- bridge_naming_convention device
154
+ bridge_naming_convention device pos_opt
128
155
else
129
156
(* At this point, we don't know what the VLAN bridge name will be,
130
157
* so use a temporary name. Xapi will replace the bridge once the name
131
158
* has been decided on. *)
132
159
temp_vlan
133
160
in
134
161
debug " No management bridge in inventory file... using %s" bridge ;
162
+ if not device_already_renamed then
163
+ write_manage_iface_to_inventory bridge ;
135
164
bridge
136
165
| Some bridge ->
137
166
debug " Management bridge in inventory file: %s" bridge ;
@@ -176,7 +205,7 @@ let read_management_conf () =
176
205
, [(bridge_name, primary_bridge_conf)]
177
206
)
178
207
| Some vlan ->
179
- let parent = bridge_naming_convention device in
208
+ let parent = bridge_naming_convention device pos_opt in
180
209
let secondary_bridge_conf =
181
210
{
182
211
default_bridge with
@@ -203,7 +232,7 @@ let read_management_conf () =
203
232
; bridge_config
204
233
; gateway_interface= Some bridge_name
205
234
; dns_interface= Some bridge_name
206
- ; interface_order= None
235
+ ; interface_order
207
236
}
208
237
with e ->
209
238
error " Error while trying to read firstboot data: %s\n %s"
0 commit comments