33
33
list of MACPCI objects in form ethXXX|side-XXX-ethXX->(mac, pci)
34
34
[in] last_state - Last boot state (post rename) of network cards on the machine
35
35
list of MACPCI objects in form (mac, pci)->ethXX
36
- [in] old_state - Any older nics which have disappeared in the meantime
36
+ [in] old_state - Any older NICs which have disappeared in the meantime
37
37
list of MACPCI objects in form (mac, pci)->ethXX
38
38
39
39
[out] transactions
40
40
list of string tuples as source and destination names for "ip link set
41
41
name"
42
+
43
+ Abbreviations used in this file:
44
+ kname: The kernel name of the network interface (the original name assigned by the kernel).
45
+ tname: The temporary name of the interface, used while renaming interfaces to avoid name conflicts.
42
46
"""
43
47
44
48
from __future__ import unicode_literals
@@ -70,11 +74,11 @@ class LogicError(RuntimeError):
70
74
71
75
def __rename_nic (nic , name , transactions , cur_state ):
72
76
"""
73
- Rename a specified nic to name.
74
- It checkes in possibly_aliased for nics which currently have name, and
75
- renames them sideways.
76
- The caller should ensure that no nics in cur_state have already been renamed
77
- to name, and that name is a valid nic name
77
+ Rename a specified NIC to the given name.
78
+ It looks at possibly aliased NICs which currently have name, and
79
+ renames them sideways if necessary .
80
+ The caller should ensure that no NICs in cur_state have already been renamed
81
+ to name, and that name is a valid NIC name
78
82
"""
79
83
80
84
# Assert that name is valid
@@ -89,7 +93,7 @@ def __rename_nic(nic, name, transactions, cur_state):
89
93
90
94
if aliased is None :
91
95
# Using this rule will not alias another currently present NIC
92
- LOG .debug ("Renaming unaliased nic '%s' to '%s'" % (nic , name ))
96
+ LOG .debug ("Renaming unaliased NIC '%s' to '%s'" % (nic , name ))
93
97
nic .tname = name
94
98
transactions .append ((nic .kname , name ))
95
99
@@ -122,24 +126,40 @@ def __rename_nic(nic, name, transactions, cur_state):
122
126
transactions .append ((nic .kname , name ))
123
127
124
128
125
- def rename_logic ( static_rules ,
126
- cur_state ,
127
- last_state ,
128
- old_state ):
129
+ def rename_logic (
130
+ static_rules ,
131
+ cur_state ,
132
+ last_state ,
133
+ old_state ,
134
+ ): # type: (list[MACPCI], list[MACPCI], list[MACPCI], list[MACPCI]) -> list[tuple[str, str]]
129
135
"""
130
136
Core logic of renaming the current state based on the rules and past state.
137
+
131
138
This function assumes all inputs have been suitably sanitised.
132
- @param static_rules
139
+
140
+ Parameters
141
+ ----------
142
+ static_rules : list[MACPCI]
133
143
List of MACPCI objects representing rules
134
- @param cur_state
144
+ cur_state : list[MACPCI]
135
145
List of MACPCI objects representing the current state
136
- @param last_state
146
+ last_state : list[MACPCI]
137
147
List of MACPCI objects representing the last boot state
138
- @param old_state
148
+ old_state : list[MACPCI]
139
149
List of MACPCI objects representing the old state
140
- @returns List of tuples...
141
- @throws AssertionError (Should not be thrown, but better to know about logic
142
- errors if they occur)
150
+
151
+ Returns
152
+ -------
153
+ list[tuple[str, str]]
154
+ List of (source_name, destination_name) tuples, where each tuple
155
+ represents a name transaction for "ip link set name".
156
+ The first element is the current interface name (source),
157
+ and the second is the new interface name (destination).
158
+
159
+ Raises
160
+ ------
161
+ AssertionError
162
+ If the current state contains invalid entries.
143
163
"""
144
164
145
165
transactions = []
@@ -365,26 +385,56 @@ def rename_logic( static_rules,
365
385
util .niceformat (cur_state )))
366
386
return transactions
367
387
368
- def rename ( static_rules ,
369
- cur_state ,
370
- last_state ,
371
- old_state ):
388
+ def rename (
389
+ static_rules ,
390
+ cur_state ,
391
+ last_state ,
392
+ old_state ,
393
+ ): # type: (list[MACPCI], list[MACPCI], list[MACPCI], list[MACPCI]) -> list[tuple[str, str]]
372
394
"""
373
395
Rename current state based on the rules and past state.
374
- This function sanitises the input and delegates the renaming logic to
375
- __rename.
376
- @param static_rules
396
+
397
+ This function:
398
+ - Sanitises the input
399
+ - Delegates the renaming logic to rename_logic()
400
+
401
+ Parameters
402
+ ----------
403
+ static_rules : list[MACPCI]
377
404
List of MACPCI objects representing rules
378
- @param cur_state
405
+ cur_state : list[MACPCI]
379
406
List of MACPCI objects representing the current state
380
- @param last_state
407
+ last_state : list[MACPCI]
381
408
List of MACPCI objects representing the last boot state
382
- @param old_state
409
+ old_state : list[MACPCI]
383
410
List of MACPCI objects representing the old state
384
411
385
- @throws StaticRuleError, CurrentStateError, LastStateError, TypeError
386
-
387
- @returns list of tuples of name changes required
412
+ Returns
413
+ -------
414
+ list[tuple[str, str]]
415
+ List of (source_name, destination_name) tuples, where each tuple
416
+ represents a name transaction for "ip link set name".
417
+ The first element is the current interface name (source),
418
+ and the second is the new interface name (destination).
419
+
420
+ Raises
421
+ ------
422
+ OldStateError
423
+ Raised if any of the following conditions are met:
424
+ - An old state has a kernel name.
425
+ - An old state has a tname not starting with 'eth'.
426
+ StaticRuleError
427
+ Raised if any of the following conditions are met:
428
+ - A static rule has a kernel name.
429
+ - A static rule has a tname not starting with 'eth'.
430
+ - Duplicate eth names are present in static rules.
431
+ - Duplicate MAC addresses are present in static rules.
432
+ CurrentStateError
433
+ If the current state contains invalid entries.
434
+ LastStateError
435
+ If the last state contains invalid entries.
436
+ TypeError
437
+ If any of the input lists contain objects that are not MACPCI instances.
388
438
"""
389
439
390
440
if len (static_rules ):
0 commit comments