Passed
Push — master ( 7f62ad...2ec8a9 )
by Vinicius
02:07 queued 13s
created

build.proxy_port.ProxyPort.get_destination()   A

Complexity

Conditions 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 7
nop 2
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 12
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 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