Passed
Pull Request — master (#35)
by Vinicius
02:31
created

build.proxy_port.ProxyPort.status()   A

Complexity

Conditions 4

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 7.456

Importance

Changes 0
Metric Value
cc 4
eloc 8
nop 1
dl 0
loc 10
ccs 2
cts 5
cp 0.4
crap 7.456
rs 10
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.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
    source interface is where the loop starts
14
    destination interface is where the loop ends
15
16
    """
17
18 1
    def __init__(self, controller: Controller, source: Interface):
19 1
        self.controller = controller
20 1
        self.source = source
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
            return None
38
39 1
        return destination
40
41 1
    @property
42 1
    def status(self) -> EntityStatus:
43
        """ProxyPort status."""
44
        if (
45
            self.source.status == EntityStatus.UP
46
            and self.destination
47
            and self.destination.status == EntityStatus.UP
48
        ):
49
            return EntityStatus.UP
50
        return EntityStatus.DOWN
51