@@ -36,11 +36,7 @@ let write_config () =
36
36
with Network_config. Write_error -> ()
37
37
38
38
let get_index_from_ethx name =
39
- if String. starts_with ~prefix: " eth" name then
40
- let index = String. sub name 3 (String. length name - 3 ) in
41
- int_of_string_opt index
42
- else
43
- None
39
+ try Scanf. sscanf name " eth%d%!" Option. some with _ -> None
44
40
45
41
let sort_based_on_ethx () =
46
42
Sysfs. list ()
@@ -53,20 +49,32 @@ let sort_based_on_ethx () =
53
49
54
50
let read_previous_inventory () =
55
51
let previous_inventory = " /var/tmp/.previousInventory" in
56
- Xapi_stdext_unix.Unixext. file_lines_fold
57
- (fun acc line ->
58
- match Inventory. parse_inventory_entry line with
59
- | Some ("MANAGEMENT_INTERFACE" , iface ) ->
60
- info " get management interface from previous inventory: %s" iface ;
61
- (iface, snd acc)
62
- | Some ("MANAGEMENT_ADDRESS_TYPE" , addr_type ) ->
63
- info " get management address type from previous inventory: %s"
64
- addr_type ;
65
- (fst acc, addr_type)
66
- | _ ->
67
- acc
68
- )
69
- (" " , " " ) previous_inventory
52
+ try
53
+ Xapi_stdext_unix.Unixext. file_lines_fold
54
+ (fun acc line ->
55
+ match Inventory. parse_inventory_entry line with
56
+ | Some ("MANAGEMENT_INTERFACE" , iface ) ->
57
+ info " get management interface from previous inventory: %s" iface ;
58
+ (iface, snd acc)
59
+ | Some ("MANAGEMENT_ADDRESS_TYPE" , addr_type ) ->
60
+ info " get management address type from previous inventory: %s"
61
+ addr_type ;
62
+ (fst acc, addr_type)
63
+ | _ ->
64
+ acc
65
+ )
66
+ (" " , " " ) previous_inventory
67
+ with e ->
68
+ error " Failed to read previous inventory %s: %s" previous_inventory
69
+ (Printexc. to_string e) ;
70
+ raise
71
+ (Network_error
72
+ (Internal_error
73
+ (Printf. sprintf " Failed to read previous inventory: %s"
74
+ previous_inventory
75
+ )
76
+ )
77
+ )
70
78
71
79
let update_inventory () =
72
80
let iface, addr_type = read_previous_inventory () in
@@ -118,7 +126,7 @@ let sort last_order =
118
126
(None , [] )
119
127
| true , Some _ ->
120
128
(* Impossible *)
121
- error " device renamed but order is not None" ;
129
+ error " %s: device renamed but order is not None" __FUNCTION__ ;
122
130
raise
123
131
(Network_error (Internal_error " device renamed but order is not None" ))
124
132
| false , None ->
0 commit comments