|
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,32 @@ 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(static_rules, cur_state, last_state, old_state): |
129 | 130 | """ |
130 | 131 | Core logic of renaming the current state based on the rules and past state. |
| 132 | +
|
131 | 133 | This function assumes all inputs have been suitably sanitised. |
132 | | - @param static_rules |
| 134 | +
|
| 135 | + Parameters |
| 136 | + ---------- |
| 137 | + static_rules : list[MACPCI] |
133 | 138 | List of MACPCI objects representing rules |
134 | | - @param cur_state |
| 139 | + cur_state : list[MACPCI] |
135 | 140 | List of MACPCI objects representing the current state |
136 | | - @param last_state |
| 141 | + last_state : list[MACPCI] |
137 | 142 | List of MACPCI objects representing the last boot state |
138 | | - @param old_state |
| 143 | + old_state : list[MACPCI] |
139 | 144 | 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. |
143 | 155 | """ |
144 | 156 |
|
145 | 157 | transactions = [] |
@@ -365,26 +377,44 @@ def rename_logic( static_rules, |
365 | 377 | util.niceformat(cur_state))) |
366 | 378 | return transactions |
367 | 379 |
|
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): |
372 | 381 | """ |
373 | 382 | 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: |
| 385 | + - Sanitises the input |
| 386 | + - Delegates the renaming logic to rename_logic() |
| 387 | +
|
| 388 | + Parameters |
| 389 | + ---------- |
| 390 | + static_rules : list[MACPCI] |
377 | 391 | List of MACPCI objects representing rules |
378 | | - @param cur_state |
| 392 | + cur_state : list[MACPCI] |
379 | 393 | List of MACPCI objects representing the current state |
380 | | - @param last_state |
| 394 | + last_state : list[MACPCI] |
381 | 395 | List of MACPCI objects representing the last boot state |
382 | | - @param old_state |
| 396 | + old_state : list[MACPCI] |
383 | 397 | List of MACPCI objects representing the old state |
384 | 398 |
|
385 | | - @throws StaticRuleError, CurrentStateError, LastStateError, TypeError |
386 | | -
|
387 | | - @returns list of tuples of name changes required |
| 399 | + Returns |
| 400 | + ------- |
| 401 | + list |
| 402 | + List of tuples of name changes required |
| 403 | +
|
| 404 | + Raises |
| 405 | + ------ |
| 406 | + StaticRuleError |
| 407 | + Raised if any of the following conditions are met: |
| 408 | + - A static rule has a kernel name. |
| 409 | + - A static rule has a tname not starting with 'eth'. |
| 410 | + - Duplicate eth names are present in static rules. |
| 411 | + - Duplicate MAC addresses are present in static rules. |
| 412 | + CurrentStateError |
| 413 | + If the current state contains invalid entries. |
| 414 | + LastStateError |
| 415 | + If the last state contains invalid entries. |
| 416 | + TypeError |
| 417 | + If any of the input lists contain objects that are not MACPCI instances. |
388 | 418 | """ |
389 | 419 |
|
390 | 420 | if len(static_rules): |
|
0 commit comments