|
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 |
@@ -122,24 +126,37 @@ 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: list[MACPCI], |
| 131 | + cur_state: list[MACPCI], |
| 132 | + last_state: list[MACPCI], |
| 133 | + old_state: list[MACPCI] |
| 134 | +) -> list: |
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 |
| 154 | + List of tuples representing name transactions. |
| 155 | +
|
| 156 | + Raises |
| 157 | + ------ |
| 158 | + AssertionError |
| 159 | + If the current state contains invalid entries. |
143 | 160 | """ |
144 | 161 |
|
145 | 162 | transactions = [] |
@@ -365,26 +382,53 @@ def rename_logic( static_rules, |
365 | 382 | util.niceformat(cur_state))) |
366 | 383 | return transactions |
367 | 384 |
|
368 | | -def rename( static_rules, |
369 | | - cur_state, |
370 | | - last_state, |
371 | | - old_state ): |
| 385 | +def rename( |
| 386 | + static_rules: list[MACPCI], |
| 387 | + cur_state: list[MACPCI], |
| 388 | + last_state: list[MACPCI], |
| 389 | + old_state: list[MACPCI] |
| 390 | +) -> list: |
372 | 391 | """ |
373 | 392 | 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 |
| 393 | +
|
| 394 | + This function: |
| 395 | + - Sanitises the input |
| 396 | + - Delegates the renaming logic to rename_logic() |
| 397 | +
|
| 398 | + Parameters |
| 399 | + ---------- |
| 400 | + static_rules : list[MACPCI] |
377 | 401 | List of MACPCI objects representing rules |
378 | | - @param cur_state |
| 402 | + cur_state : list[MACPCI] |
379 | 403 | List of MACPCI objects representing the current state |
380 | | - @param last_state |
| 404 | + last_state : list[MACPCI] |
381 | 405 | List of MACPCI objects representing the last boot state |
382 | | - @param old_state |
| 406 | + old_state : list[MACPCI] |
383 | 407 | List of MACPCI objects representing the old state |
384 | 408 |
|
385 | | - @throws StaticRuleError, CurrentStateError, LastStateError, TypeError |
386 | | -
|
387 | | - @returns list of tuples of name changes required |
| 409 | + Returns |
| 410 | + ------- |
| 411 | + list |
| 412 | + List of tuples of name changes required |
| 413 | +
|
| 414 | + Raises |
| 415 | + ------ |
| 416 | + OldStateError |
| 417 | + Raised if any of the following conditions are met: |
| 418 | + - An old state has a kernel name. |
| 419 | + - An old state has a tname not starting with 'eth'. |
| 420 | + StaticRuleError |
| 421 | + Raised if any of the following conditions are met: |
| 422 | + - A static rule has a kernel name. |
| 423 | + - A static rule has a tname not starting with 'eth'. |
| 424 | + - Duplicate eth names are present in static rules. |
| 425 | + - Duplicate MAC addresses are present in static rules. |
| 426 | + CurrentStateError |
| 427 | + If the current state contains invalid entries. |
| 428 | + LastStateError |
| 429 | + If the last state contains invalid entries. |
| 430 | + TypeError |
| 431 | + If any of the input lists contain objects that are not MACPCI instances. |
388 | 432 | """ |
389 | 433 |
|
390 | 434 | if len(static_rules): |
|
0 commit comments