summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/MultiHome.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/hooks/MultiHome.py')
-rw-r--r--module/plugins/hooks/MultiHome.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/module/plugins/hooks/MultiHome.py b/module/plugins/hooks/MultiHome.py
index ddf8db69f..473e6dcb1 100644
--- a/module/plugins/hooks/MultiHome.py
+++ b/module/plugins/hooks/MultiHome.py
@@ -17,18 +17,20 @@
@author: mkaay
"""
-from module.plugins.Hook import Hook
from time import time
+from module.plugins.Hook import Hook
+
+
class MultiHome(Hook):
__name__ = "MultiHome"
__version__ = "0.11"
__description__ = """ip address changer"""
- __config__ = [ ("activated", "bool", "Activated" , "False"),
- ("interfaces", "str", "Interfaces" , "None") ]
+ __config__ = [("activated", "bool", "Activated", "False"),
+ ("interfaces", "str", "Interfaces", "None")]
__author_name__ = ("mkaay")
__author_mail__ = ("mkaay@mkaay.de")
-
+
def setup(self):
self.register = {}
self.interfaces = []
@@ -36,28 +38,30 @@ class MultiHome(Hook):
if not self.interfaces:
self.parseInterfaces([self.config["download"]["interface"]])
self.setConfig("interfaces", self.toConfig())
-
+
def toConfig(self):
return ";".join([i.adress for i in self.interfaces])
-
+
def parseInterfaces(self, interfaces):
for interface in interfaces:
if not interface or str(interface).lower() == "none":
continue
self.interfaces.append(Interface(interface))
-
+
def coreReady(self):
requestFactory = self.core.requestFactory
oldGetRequest = requestFactory.getRequest
+
def getRequest(pluginName, account=None):
iface = self.bestInterface(pluginName, account)
if iface:
iface.useFor(pluginName, account)
requestFactory.iface = lambda: iface.adress
- self.logDebug("Multihome: using address: "+iface.adress)
+ self.logDebug("Multihome: using address: " + iface.adress)
return oldGetRequest(pluginName, account)
+
requestFactory.getRequest = getRequest
-
+
def bestInterface(self, pluginName, account):
best = None
for interface in self.interfaces:
@@ -65,18 +69,19 @@ class MultiHome(Hook):
best = interface
return best
+
class Interface(object):
def __init__(self, adress):
self.adress = adress
self.history = {}
-
+
def lastPluginAccess(self, pluginName, account):
if (pluginName, account) in self.history:
return self.history[(pluginName, account)]
return 0
-
+
def useFor(self, pluginName, account):
self.history[(pluginName, account)] = time()
-
+
def __repr__(self):
return "<Interface - %s>" % self.adress