xcp.net.ifrename.logic¶
Interface Rename logic
Provides the ‘rename’ function which takes 4 lists of state and returns a list of name transactions to rename network interfaces.
- [in] static_rules - Static rules provided by the user, taking absolute priority
list of MACPCI objects in form (mac, pci)->ethXX
- [in] cur_state - Current state of network cards on the machine (pre rename)
list of MACPCI objects in form ethXXX|side-XXX-ethXX->(mac, pci)
- [in] last_state - Last boot state (post rename) of network cards on the machine
list of MACPCI objects in form (mac, pci)->ethXX
- [in] old_state - Any older NICs which have disappeared in the meantime
list of MACPCI objects in form (mac, pci)->ethXX
- [out] transactions
list of string tuples as source and destination names for “ip link set name”
- Abbreviations used in this file:
kname: The kernel name of the network interface (the original name assigned by the kernel). tname: The temporary name of the interface, used while renaming interfaces to avoid name conflicts.
- exception xcp.net.ifrename.logic.CurrentStateError[source]¶
Bases:
RuntimeErrorError with current state information
- exception xcp.net.ifrename.logic.LastStateError[source]¶
Bases:
RuntimeErrorError with last state information
- exception xcp.net.ifrename.logic.LogicError[source]¶
Bases:
RuntimeErrorLogical Error. Needs fixing
- exception xcp.net.ifrename.logic.OldStateError[source]¶
Bases:
RuntimeErrorError with old state information
- exception xcp.net.ifrename.logic.StaticRuleError[source]¶
Bases:
RuntimeErrorError with static rules
- xcp.net.ifrename.logic.rename(static_rules: list[MACPCI], cur_state: list[MACPCI], last_state: list[MACPCI], old_state: list[MACPCI]) list[tuple[str, str]][source]¶
Rename current state based on the rules and past state.
This function: - Sanitises the input - Delegates the renaming logic to rename_logic()
Parameters¶
- static_ruleslist[MACPCI]
List of MACPCI objects representing rules
- cur_statelist[MACPCI]
List of MACPCI objects representing the current state
- last_statelist[MACPCI]
List of MACPCI objects representing the last boot state
- old_statelist[MACPCI]
List of MACPCI objects representing the old state
Returns¶
- list[tuple[str, str]]
List of (source_name, destination_name) tuples, where each tuple represents a name transaction for “ip link set name”. The first element is the current interface name (source), and the second is the new interface name (destination).
Raises¶
- OldStateError
Raised if any of the following conditions are met: - An old state has a kernel name. - An old state has a tname not starting with ‘eth’.
- StaticRuleError
Raised if any of the following conditions are met: - A static rule has a kernel name. - A static rule has a tname not starting with ‘eth’. - Duplicate eth names are present in static rules. - Duplicate MAC addresses are present in static rules.
- CurrentStateError
If the current state contains invalid entries.
- LastStateError
If the last state contains invalid entries.
- TypeError
If any of the input lists contain objects that are not MACPCI instances.
- xcp.net.ifrename.logic.rename_logic(static_rules: list[MACPCI], cur_state: list[MACPCI], last_state: list[MACPCI], old_state: list[MACPCI]) list[tuple[str, str]][source]¶
Core logic of renaming the current state based on the rules and past state.
This function assumes all inputs have been suitably sanitised.
Parameters¶
- static_ruleslist[MACPCI]
List of MACPCI objects representing rules
- cur_statelist[MACPCI]
List of MACPCI objects representing the current state
- last_statelist[MACPCI]
List of MACPCI objects representing the last boot state
- old_statelist[MACPCI]
List of MACPCI objects representing the old state
Returns¶
- list[tuple[str, str]]
List of (source_name, destination_name) tuples, where each tuple represents a name transaction for “ip link set name”. The first element is the current interface name (source), and the second is the new interface name (destination).
Raises¶
- AssertionError
If the current state contains invalid entries.