Skip to content

Commit 4b5d14e

Browse files
docs: Fix xcp/net/ifrename/* for Sphinx-autodoc generation
Signed-off-by: Bernhard Kaindl <[email protected]>
1 parent 0c35e95 commit 4b5d14e

File tree

2 files changed

+61
-36
lines changed

2 files changed

+61
-36
lines changed

xcp/net/ifrename/logic.py

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
[out] transactions
4040
list of string tuples as source and destination names for "ip link set
4141
name"
42+
43+
Terms and 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
@@ -122,24 +126,32 @@ 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(static_rules, cur_state, last_state, old_state):
129130
"""
130131
Core logic of renaming the current state based on the rules and past state.
132+
131133
This function assumes all inputs have been suitably sanitised.
132-
@param static_rules
134+
135+
Parameters
136+
----------
137+
static_rules : List[MACPCI]
133138
List of MACPCI objects representing rules
134-
@param cur_state
139+
cur_state : List[MACPCI]
135140
List of MACPCI objects representing the current state
136-
@param last_state
141+
last_state : List[MACPCI]
137142
List of MACPCI objects representing the last boot state
138-
@param old_state
143+
old_state : List[MACPCI]
139144
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)
145+
146+
Returns
147+
-------
148+
list
149+
List of tuples representing name transactions.
150+
151+
Raises
152+
------
153+
AssertionError
154+
If the current state contains invalid entries.
143155
"""
144156

145157
transactions = []
@@ -365,26 +377,42 @@ def rename_logic( static_rules,
365377
util.niceformat(cur_state)))
366378
return transactions
367379

368-
def rename( static_rules,
369-
cur_state,
370-
last_state,
371-
old_state ):
380+
def rename(static_rules, cur_state, last_state, old_state):
372381
"""
373382
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
383+
384+
This function sanitises the input and delegates the renaming logic to rename_logic.
385+
386+
Parameters
387+
----------
388+
static_rules : List[MACPCI]
377389
List of MACPCI objects representing rules
378-
@param cur_state
390+
cur_state : List[MACPCI]
379391
List of MACPCI objects representing the current state
380-
@param last_state
392+
last_state : List[MACPCI]
381393
List of MACPCI objects representing the last boot state
382-
@param old_state
394+
old_state : List[MACPCI]
383395
List of MACPCI objects representing the old state
384396
385-
@throws StaticRuleError, CurrentStateError, LastStateError, TypeError
386-
387-
@returns list of tuples of name changes required
397+
Returns
398+
-------
399+
list
400+
List of tuples of name changes required
401+
402+
Raises
403+
------
404+
StaticRuleError
405+
Raised if any of the following conditions are met:
406+
- A static rule has a kernel name.
407+
- A static rule has a tname not starting with 'eth'.
408+
- Duplicate eth names are present in static rules.
409+
- Duplicate MAC addresses are present in static rules.
410+
CurrentStateError
411+
If the current state contains invalid entries.
412+
LastStateError
413+
If the last state contains invalid entries.
414+
TypeError
415+
If any of the input lists contain objects that are not MACPCI instances.
388416
"""
389417

390418
if len(static_rules):

xcp/net/ifrename/static.py

Lines changed: 9 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
@@ -82,9 +81,7 @@ class StaticRules(object):
8281
"""
8382
Object for parsing the static rules configuration.
8483
85-
There are two distinct usecases; the installer needs to write the
86-
static rules from scratch, whereas interface-rename.py in dom0 needs
87-
to read them.
84+
- interface-rename.py in Dom0 needs to read them.
8885
"""
8986

9087
methods = ["mac", "pci", "ppn", "label", "guess"]

0 commit comments

Comments
 (0)