File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,22 @@ let read_config () =
97
97
error " Could not interpret the configuration in management.conf"
98
98
)
99
99
100
+ let get_index_from_ethx name =
101
+ if String. starts_with ~prefix: " eth" name then
102
+ let index = String. sub name 3 (String. length name - 3 ) in
103
+ int_of_string_opt index
104
+ else
105
+ None
106
+
107
+ let sort_based_on_ethx () =
108
+ Sysfs. list ()
109
+ |> List. filter_map (fun name ->
110
+ if Sysfs. is_physical name then
111
+ get_index_from_ethx name |> Option. map (fun i -> (name, i))
112
+ else
113
+ None
114
+ )
115
+
100
116
let on_shutdown signal =
101
117
let dbg = " shutdown" in
102
118
Debug. with_thread_associated dbg
@@ -321,6 +337,24 @@ module Interface = struct
321
337
let get_all dbg () =
322
338
Debug. with_thread_associated dbg (fun () -> Sysfs. list () ) ()
323
339
340
+ let get_interface_positions dbg () =
341
+ Debug. with_thread_associated dbg
342
+ (fun () ->
343
+ match ! config.interface_order with
344
+ | Some order ->
345
+ List. filter_map
346
+ (fun dev ->
347
+ if dev.present then
348
+ Some (dev.name, dev.position)
349
+ else
350
+ None
351
+ )
352
+ order
353
+ | None ->
354
+ sort_based_on_ethx ()
355
+ )
356
+ ()
357
+
324
358
let exists dbg name =
325
359
Debug. with_thread_associated dbg
326
360
(fun () -> List. mem name (Sysfs. list () ))
Original file line number Diff line number Diff line change @@ -183,6 +183,7 @@ let bind () =
183
183
S. set_gateway_interface set_gateway_interface ;
184
184
S. set_dns_interface set_dns_interface ;
185
185
S.Interface. get_all Interface. get_all ;
186
+ S.Interface. get_interface_positions Interface. get_interface_positions ;
186
187
S.Interface. exists Interface. exists ;
187
188
S.Interface. get_mac Interface. get_mac ;
188
189
S.Interface. get_pci_bus_path Interface. get_pci_bus_path ;
Original file line number Diff line number Diff line change @@ -420,6 +420,18 @@ module Interface_API (R : RPC) = struct
420
420
[" Get list of all interface names" ]
421
421
(debug_info_p @-> unit_p @-> returning iface_list_p err)
422
422
423
+ let get_interface_positions =
424
+ let module T = struct
425
+ type _iface_position_list_t = (iface * int ) list [@@ deriving rpcty ]
426
+ end in
427
+ let iface_position_list_p =
428
+ Param. mk ~description: [" interface postion list" ]
429
+ T. _iface_position_list_t
430
+ in
431
+ declare " Interface.get_interface_positions"
432
+ [" Get list of interface names and their positions" ]
433
+ (debug_info_p @-> unit_p @-> returning iface_position_list_p err)
434
+
423
435
let exists =
424
436
let result = Param. mk ~description: [" existence" ] Types. bool in
425
437
declare " Interface.exists"
You can’t perform that action at this time.
0 commit comments