Passed
Push — master ( d721c9...4c266c )
by Vinicius
07:20 queued 04:30
created

build.proxy_port.ProxyPort.destination()   B

Complexity

Conditions 6

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 13
nop 1
dl 0
loc 18
ccs 8
cts 8
cp 1
crap 6
rs 8.6666
c 0
b 0
f 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.interface import Interface
7
8
9 1
class ProxyPort:
10
    """This class helps to handle multi-home physical loops (two ports).
11
12
    source interface is where the loop starts
13
    destination interface is where the loop ends
14
    evc_ids are which evc ids this proxy port is being used by
15
16
    """
17
18 1
    def __init__(self, source: Interface):
19 1
        self.source = source
20 1
        self.evc_ids: set[str] = set()
21
22 1
    @property
23 1
    def destination(self) -> Optional[Interface]:
24
        """Destination interface of the loop."""
25 1
        if (
26
            "looped" not in self.source.metadata
27
            or "port_numbers" not in self.source.metadata["looped"]
28
            or not self.source.metadata["looped"]["port_numbers"]
29
            or len(self.source.metadata["looped"]["port_numbers"]) < 2
30
        ):
31 1
            return None
32
33 1
        destination = self.source.switch.get_interface_by_port_no(
34
            self.source.metadata["looped"]["port_numbers"][1]
35
        )
36 1
        if not destination:
37 1
            return None
38
39 1
        return destination
40
41 1
    @property
42 1
    def status(self) -> EntityStatus:
43
        """ProxyPort status."""
44 1
        if (
45
            self.source.status == EntityStatus.UP
46
            and self.destination
47
            and self.destination.status == EntityStatus.UP
48
        ):
49 1
            return EntityStatus.UP
50 1
        return EntityStatus.DOWN
51
52 1
    def __repr__(self) -> str:
53
        """Repr method."""
54
        return f"ProxyPort({self.source}, {self.destination}, {self.status})"
55