Passed
Pull Request — master (#27)
by Vinicius
05:49
created

build.proxy_port   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 39
ccs 9
cts 18
cp 0.5
rs 10
c 0
b 0
f 0
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B ProxyPort.destination() 0 18 8
A ProxyPort.is_ready() 0 3 1
A ProxyPort.__init__() 0 3 1
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