summaryrefslogtreecommitdiffstats
path: root/Monitoring/MonitoringService/Resource/interface.py
blob: db7b2d3f419a95d7636251576188daf389bc3fc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'''
Created on Jul 11, 2012

@author: steger
'''
from Resource.resource import resource

class interface(resource):
    '''
    classdocs
    '''
    UNDEFINED = 0
    INGRESS = 1
    EGRESS = 2

    def __init__(self, name = None, resourceid = None):
        resource.__init__(self, name, resourceid)
        self._public = False
        self._direction = self.UNDEFINED
        self._iface = None
        self._address = None
        self._hostname = None

    def setvalues(self, ifacename, address, ispublic = False, direction = 0, hostname = None):
        self.interface = ifacename
        self.address = address
        self.ispublic = ispublic
        self.direction = direction
        self.hostname = hostname
    
    @property
    def ispublic(self):
        if not self._iface:
            raise Exception("No interface name defined yet for %s" % self.resourceid)
        if not self._address:
            raise Exception("No address defined yet for %s" % self.resourceid)
        return self._public
    @ispublic.setter
    def ispublic(self, ispublic):
        if isinstance(ispublic, bool):
            self._public = ispublic
        else:
            self._public = False  
    
    @property
    def hostname(self):
        return self._hostname
    @hostname.setter
    def hostname(self, hostname):
        self._hostname = self.ipret(hostname)
            
    @property
    def address(self):
        return self._address
    @address.setter
    def address(self, address):
        if isinstance(address, tuple):
            self._address = address
        else:
            self._address = self.ipret(address)

    @property
    def interface(self):
        return self._iface
    @interface.setter
    def interface(self, iface):
        self._iface = self.ipret(iface)

    @property
    def direction(self):
        return self._direction
    @direction.setter
    def direction(self, direction):
        self._direction = direction & (self.INGRESS | self.EGRESS)
    
    @property
    def isvalid(self):
        return self.address and self.interface