@@ -114,11 +114,12 @@ let refresh_all ~__context ~host =
114
114
in
115
115
List. iter (fun self -> refresh_internal ~__context ~self ) pifs
116
116
117
- let bridge_naming_convention (device : string ) =
118
- if String. starts_with ~prefix: " eth" device then
119
- " xenbr" ^ String. sub device 3 (String. length device - 3 )
120
- else
121
- " br" ^ device
117
+ let bridge_naming_convention (device : string ) (pos_opt : int option ) =
118
+ match pos_opt with
119
+ | Some index ->
120
+ " xenbr" ^ string_of_int index
121
+ | None ->
122
+ " br" ^ device
122
123
123
124
let read_bridges_from_inventory () =
124
125
try String. split ' ' (Xapi_inventory. lookup Xapi_inventory. _current_interfaces)
@@ -337,8 +338,8 @@ let assert_fcoe_not_in_use ~__context ~self =
337
338
()
338
339
)
339
340
340
- let find_or_create_network (bridge : string ) (device : string ) ~ managed
341
- ~__context =
341
+ let find_or_create_network (bridge : string ) (device : string )
342
+ ( pos_opt : int option ) ~ managed ~__context =
342
343
let nets =
343
344
Db.Network. get_refs_where ~__context
344
345
~expr: (Eq (Field " bridge" , Literal bridge))
@@ -352,41 +353,52 @@ let find_or_create_network (bridge : string) (device : string) ~managed
352
353
let () =
353
354
Db.Network. create ~__context ~ref: net_ref ~uuid: net_uuid
354
355
~current_operations: [] ~allowed_operations: []
355
- ~name_label: (Helpers. choose_network_name_for_pif device)
356
+ ~name_label: (Helpers. choose_network_name_for_pif device pos_opt )
356
357
~name_description: " " ~m TU:1500L ~purpose: [] ~bridge ~managed
357
358
~other_config: [] ~blobs: [] ~tags: [] ~default_locking_mode: `unlocked
358
359
~assigned_ips: []
359
360
in
360
361
net_ref
361
362
362
363
type tables = {
363
- device_to_mac_table : (string * string ) list
364
+ device_to_position_table : (string * int ) list
365
+ ; device_to_mac_table : (string * string ) list
364
366
; pif_to_device_table : (API .ref_PIF * string ) list
365
367
}
366
368
367
369
let make_tables ~__context ~host =
368
370
let dbg = Context. string_of_task __context in
369
- let devices =
370
- List. filter
371
- (fun name -> Net.Interface. is_physical dbg name)
372
- (Net.Interface. get_all dbg () )
371
+ let device_to_position_table = Net.Interface. get_interface_positions dbg () in
372
+ let device_to_mac_table =
373
+ List. map
374
+ (fun (name , _ ) -> (name, Net.Interface. get_mac dbg name))
375
+ device_to_position_table
373
376
in
374
- let pifs =
377
+ (* Get all PIFs on this host *)
378
+ let pif_to_device_table =
375
379
Db.PIF. get_records_where ~__context
376
380
~expr:
377
381
(And
378
382
( Eq (Field " host" , Literal (Ref. string_of host))
379
383
, Eq (Field " physical" , Literal " true" )
380
384
)
381
385
)
386
+ |> List. map (fun (pref , prec ) -> (pref, prec.API. pIF_device))
382
387
in
383
- {
384
- device_to_mac_table=
385
- List. combine devices
386
- (List. map (fun name -> Net.Interface. get_mac dbg name) devices)
387
- ; pif_to_device_table=
388
- List. map (fun (pref , prec ) -> (pref, prec.API. pIF_device)) pifs
389
- }
388
+ debug " tables: device_to_position_table = %s"
389
+ (String. concat " ; "
390
+ (List. map
391
+ (fun (d , p ) -> d ^ " :" ^ string_of_int p)
392
+ device_to_position_table
393
+ )
394
+ ) ;
395
+ debug " tables: device_to_mac_table = %s"
396
+ (String. concat " ; "
397
+ (List. map (fun (d , m ) -> d ^ " :" ^ m) device_to_mac_table)
398
+ ) ;
399
+ debug " tables: pif_to_device_table = %s"
400
+ (String. concat " ; " (List. map snd pif_to_device_table)) ;
401
+ {device_to_position_table; device_to_mac_table; pif_to_device_table}
390
402
391
403
let is_my_management_pif ~__context ~self =
392
404
let net = Db.PIF. get_network ~__context ~self in
@@ -445,16 +457,19 @@ let db_introduce = pool_introduce
445
457
let db_forget ~__context ~self = Db.PIF. destroy ~__context ~self
446
458
447
459
(* Internal [introduce] is passed a pre-built table [t] *)
448
- let introduce_internal ?network ?(physical = true ) ~t :_ ~__context ~host ~mAC
449
- ~mTU ~device ~vLAN ~vLAN_master_of ?metrics ~managed
450
- ?(disallow_unplug = false ) () =
451
- let bridge = if managed then bridge_naming_convention device else " " in
460
+ let introduce_internal ?network ?(physical = true ) ~t ~__context ~host ~mAC ~mTU
461
+ ~device ~vLAN ~vLAN_master_of ?metrics ~managed ?(disallow_unplug = false )
462
+ () =
463
+ let pos_opt = List. assoc_opt device t.device_to_position_table in
464
+ let bridge =
465
+ if managed then bridge_naming_convention device pos_opt else " "
466
+ in
452
467
(* If we are not told which network to use,
453
468
* apply the default convention *)
454
469
let net_ref =
455
470
match network with
456
471
| None ->
457
- find_or_create_network bridge device ~managed ~__context
472
+ find_or_create_network bridge device pos_opt ~managed ~__context
458
473
| Some x ->
459
474
x
460
475
in
0 commit comments