3333 list of MACPCI objects in form ethXXX|side-XXX-ethXX->(mac, pci)
3434[in] last_state - Last boot state (post rename) of network cards on the machine
3535 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
3737 list of MACPCI objects in form (mac, pci)->ethXX
3838
3939[out] transactions
4040 list of string tuples as source and destination names for "ip link set
4141 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.
4246"""
4347
4448from __future__ import unicode_literals
@@ -70,11 +74,11 @@ class LogicError(RuntimeError):
7074
7175def __rename_nic (nic , name , transactions , cur_state ):
7276 """
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
7882 """
7983
8084 # Assert that name is valid
@@ -89,7 +93,7 @@ def __rename_nic(nic, name, transactions, cur_state):
8993
9094 if aliased is None :
9195 # 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 ))
9397 nic .tname = name
9498 transactions .append ((nic .kname , name ))
9599
@@ -122,24 +126,40 @@ def __rename_nic(nic, name, transactions, cur_state):
122126 transactions .append ((nic .kname , name ))
123127
124128
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]]
129135 """
130136 Core logic of renaming the current state based on the rules and past state.
137+
131138 This function assumes all inputs have been suitably sanitised.
132- @param static_rules
139+
140+ Parameters
141+ ----------
142+ static_rules : list[MACPCI]
133143 List of MACPCI objects representing rules
134- @param cur_state
144+ cur_state : list[MACPCI]
135145 List of MACPCI objects representing the current state
136- @param last_state
146+ last_state : list[MACPCI]
137147 List of MACPCI objects representing the last boot state
138- @param old_state
148+ old_state : list[MACPCI]
139149 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.
143163 """
144164
145165 transactions = []
@@ -365,26 +385,56 @@ def rename_logic( static_rules,
365385 util .niceformat (cur_state )))
366386 return transactions
367387
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]]
372394 """
373395 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]
377404 List of MACPCI objects representing rules
378- @param cur_state
405+ cur_state : list[MACPCI]
379406 List of MACPCI objects representing the current state
380- @param last_state
407+ last_state : list[MACPCI]
381408 List of MACPCI objects representing the last boot state
382- @param old_state
409+ old_state : list[MACPCI]
383410 List of MACPCI objects representing the old state
384411
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.
388438 """
389439
390440 if len (static_rules ):
0 commit comments