| Total Complexity | 10 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Coverage | 50% |
| Changes | 0 | ||
| 1 | """ This class helps to handle multi-home physical loops (two ports). """ |
||
| 2 | |||
| 3 | 1 | from typing import Optional |
|
| 4 | |||
| 5 | 1 | from kytos.core.common import EntityStatus |
|
| 6 | 1 | from kytos.core.controller import Controller |
|
| 7 | 1 | from kytos.core.interface import Interface |
|
| 8 | |||
| 9 | |||
| 10 | 1 | class ProxyPort: |
|
| 11 | """This class helps to handle multi-home physical loops (two ports).""" |
||
| 12 | |||
| 13 | 1 | def __init__(self, controller: Controller, source: Interface): |
|
| 14 | self.controller = controller |
||
| 15 | self.source = source |
||
| 16 | |||
| 17 | 1 | @property |
|
| 18 | 1 | def destination(self) -> Optional[Interface]: |
|
| 19 | """Destination interface of the loop.""" |
||
| 20 | if ( |
||
| 21 | self.source.status != EntityStatus.UP |
||
| 22 | or "looped" not in self.source.metadata |
||
| 23 | or "port_numbers" not in self.source.metadata["looped"] |
||
| 24 | or not self.source.metadata["looped"]["port_numbers"] |
||
| 25 | or len(self.source.metadata["looped"]["port_numbers"]) < 2 |
||
| 26 | ): |
||
| 27 | return None |
||
| 28 | |||
| 29 | destination = self.source.switch.get_interface_by_port_no( |
||
| 30 | self.source.metadata["looped"]["port_numbers"][1] |
||
| 31 | ) |
||
| 32 | if not destination or destination.status != EntityStatus.UP: |
||
| 33 | return None |
||
| 34 | return destination |
||
| 35 | |||
| 36 | 1 | def is_ready(self) -> Optional[bool]: |
|
| 37 | """Make sure this class has all it needs""" |
||
| 38 | return self.source and self.destination |
||
| 39 |