diff options
author | pikusa <pikusa@man.poznan.pl> | 2013-04-03 13:18:17 (GMT) |
---|---|---|
committer | pikusa <pikusa@man.poznan.pl> | 2013-04-03 13:18:17 (GMT) |
commit | 2f2a3a129c91de540e66c3bfbe30b0df1942cd4b (patch) | |
tree | 2d313cdf0068af368d4de6067d676be16f6a6464 /Monitoring/MonitoringService/Resource/node.py | |
parent | ff8aa232b071a9b54dff833714a870fd0aec0b30 (diff) | |
download | novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.zip novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.gz novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.bz2 |
project commit and dir tree change
Diffstat (limited to 'Monitoring/MonitoringService/Resource/node.py')
-rw-r--r-- | Monitoring/MonitoringService/Resource/node.py | 48 |
1 files changed, 48 insertions, 0 deletions
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)) |