Skip to content

Commit 0395592

Browse files
docs: Fix xcp/net/ifrename/* for Sphinx-autodoc generation
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
1 parent 98ef790 commit 0395592

File tree

2 files changed

+92
-43
lines changed

2 files changed

+92
-43
lines changed

xcp/net/ifrename/logic.py

Lines changed: 81 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@
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

4448
from __future__ import unicode_literals
@@ -70,11 +74,11 @@ class LogicError(RuntimeError):
7074

7175
def __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):

xcp/net/ifrename/static.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@
2525
Object for manipulating static rules.
2626
2727
Rules are of the form:
28-
<target name>: <id method> = "value"
28+
<target name>: <id method> = "value"
2929
30-
target name must be in the form eth*
31-
id methods are:
32-
mac: value should be the mac address of a device (e.g. DE:AD:C0:DE:00:00)
33-
pci: value should be the pci bus location of the device, optionally with an index (e.g. 0000:01:01.1[0])
34-
ppn: value should be the result of the biosdevname physical naming policy of a device (e.g. p1p1)
35-
label: value should be the SMBios label of a device (for SMBios 2.6 or above)
36-
37-
Any line starting with '#' is considered to be a comment
30+
target name must be in the form eth*
31+
id methods are:
32+
- `mac`: value should be the MAC address of a device (e.g. DE:AD:C0:DE:00:00)
33+
- `pci`: value should be the PCI bus location of the device, optionally with an index (e.g. 0000:01:01.1[0])
34+
- `ppn`: value should be the result of the biosdevname physical naming policy of a device (e.g. p1p1)
35+
- `label`: value should be the SMBIOS label of a device (for SMBIOS 2.6 or above)
3836
37+
Any line starting with '#' is considered to be a comment
3938
"""
4039

4140
from __future__ import unicode_literals
@@ -71,10 +70,10 @@
7170
7271
# target name must be in the form eth*
7372
# id methods are:
74-
# mac: value should be the mac address of a device (e.g. DE:AD:C0:DE:00:00)
75-
# pci: value should be the pci bus location of the device (e.g. 0000:01:01.1[0])
73+
# mac: value should be the MAC address of a device (e.g. DE:AD:C0:DE:00:00)
74+
# pci: value should be the PCI bus location of the device (e.g. 0000:01:01.1[0])
7675
# ppn: value should be the result of the biosdevname physical naming policy of a device (e.g. p1p1)
77-
# label: value should be the SMBios label of a device (for SMBios 2.6 or above)
76+
# label: value should be the SMBIOS label of a device (for SMBIOS 2.6 or above)
7877
7978
"""
8079

0 commit comments

Comments
 (0)