From 2f2a3a129c91de540e66c3bfbe30b0df1942cd4b Mon Sep 17 00:00:00 2001 From: pikusa Date: Wed, 03 Apr 2013 13:18:17 +0000 Subject: project commit and dir tree change --- (limited to 'Monitoring/MonitoringService/Resource') diff --git a/Monitoring/MonitoringService/Resource/__init__.py b/Monitoring/MonitoringService/Resource/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Monitoring/MonitoringService/Resource/__init__.py diff --git a/Monitoring/MonitoringService/Resource/interface.py b/Monitoring/MonitoringService/Resource/interface.py new file mode 100644 index 0000000..db7b2d3 --- /dev/null +++ b/Monitoring/MonitoringService/Resource/interface.py @@ -0,0 +1,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 diff --git a/Monitoring/MonitoringService/Resource/link.py b/Monitoring/MonitoringService/Resource/link.py new file mode 100644 index 0000000..6e32dd9 --- /dev/null +++ b/Monitoring/MonitoringService/Resource/link.py @@ -0,0 +1,35 @@ +''' +Created on May 31, 2012 + +@author: steger +''' +from Resource.resource import resource +from Resource.node import node + +class link(resource): + def __init__(self, name = None, resourceid = None, source = None, destination = None): + resource.__init__(self, name, resourceid) + self._source = source + self._destination = destination + + @property + def source(self): + return self._source + @source.setter + def source(self, source): + if isinstance(source, node): + self._source = source + @source.deleter + def source(self): + self._source = None + + @property + def destination(self): + return self._destination + @destination.setter + def destination(self, destination): + if isinstance(destination, node): + self._destination = destination + @destination.deleter + def destination(self): + self._destination = None \ No newline at end of file diff --git a/Monitoring/MonitoringService/Resource/node.py b/Monitoring/MonitoringService/Resource/node.py new file mode 100644 index 0000000..5a65121 --- /dev/null +++ b/Monitoring/MonitoringService/Resource/node.py @@ -0,0 +1,48 @@ +''' +Created on May 31, 2012 + +@author: steger +''' +from Resource.resource import resource +from Resource.interface import interface + +class node(resource): + def __init__(self, name = None, resourceid = None): + resource.__init__(self, name, resourceid) + self._public = False + self._interfaces = {} + + @property + def ispublic(self): + if not len(self._interfaces): + raise Exception("No interfaces defined yet for %s" % self.resourceid) + return self._public + + def addinterface(self, iface): + if not isinstance(iface, interface): + raise Exception("Wrong resource type %s is not an interface" % iface) + self._interfaces[iface.interface] = iface + self._public |= iface.ispublic + + def interfaces(self): + for iface in self._interfaces.itervalues(): + if not iface.isvalid: + print "WW: invalid interface:", iface.resourceid + continue + yield iface.interface, iface.address, iface.ispublic, iface.hostname, iface.direction + + def get_ipaddress(self, interfacename): + for ifname, address, _, _, _ in self.interfaces(): + if ifname == interfacename: + return address + raise Exception("%s has no interface %s" % (self.resourceid, interfacename)) + + def get_hostname(self, interfacename): + for ifname, address, _, hostname, _ in self.interfaces(): + if ifname != interfacename: + continue + if hostname: + return hostname + else: + return address + raise Exception("%s has no interface %s" % (self.resourceid, interfacename)) diff --git a/Monitoring/MonitoringService/Resource/path.py b/Monitoring/MonitoringService/Resource/path.py new file mode 100644 index 0000000..6296bc4 --- /dev/null +++ b/Monitoring/MonitoringService/Resource/path.py @@ -0,0 +1,9 @@ +''' +Created on Jun 12, 2012 + +@author: steger +''' +from Resource.link import link + +class path(link): + pass \ No newline at end of file diff --git a/Monitoring/MonitoringService/Resource/resource.py b/Monitoring/MonitoringService/Resource/resource.py new file mode 100644 index 0000000..fb093bd --- /dev/null +++ b/Monitoring/MonitoringService/Resource/resource.py @@ -0,0 +1,44 @@ +''' +Created on May 31, 2012 + +@author: steger +''' + +class resource(object): + def __init__(self, name = None, resourceid = None): + self._name = name + self._resourceid = resourceid + + @staticmethod + def ipret(x): + if not x: + return None + x = str(x) + if len(x): + return x + else: + return None + + @property + def name(self): + if self._name is None: + raise Exception("resource name is not set") + return self._name + @name.setter + def name(self, name): + self._name = self.ipret(name) + @name.deleter + def name(self): + self._name = None + + @property + def resourceid(self): + if self._resourceid is None: + raise Exception("resource id is not set") + return self._resourceid + @resourceid.setter + def resourceid(self, resourceid): + self._resourceid = resourceid + @resourceid.deleter + def resourceid(self): + self._resourceid = None \ No newline at end of file diff --git a/Monitoring/MonitoringService/Resource/slice.py b/Monitoring/MonitoringService/Resource/slice.py new file mode 100644 index 0000000..002318f --- /dev/null +++ b/Monitoring/MonitoringService/Resource/slice.py @@ -0,0 +1,40 @@ +''' +Created on Oct 30, 2012 + +@author: steger +''' + +class slice_pointer(object): + ''' + classdocs + ''' + + def __init__(self, sliceid = None, slicename = ""): + ''' + Constructor + ''' + self._sliceid = sliceid + self._name = slicename + + @property + def sliceid(self): + if self._sliceid is None: + raise Exception("slice id is not set") + return self._sliceid + @sliceid.setter + def sliceid(self, sliceid): + self._sliceid = sliceid + @sliceid.deleter + def sliceid(self): + self._sliceid = None + + @property + def name(self): + return self._name + @name.setter + def name(self, name): + self._name = name + @name.deleter + def name(self): + self._name = "" + \ No newline at end of file -- cgit