2016-02-29 10:48:00 +02:00
|
|
|
#!/usr/bin/python3
|
2016-02-18 16:38:30 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
2016-03-01 18:43:26 +02:00
|
|
|
import threading
|
2016-03-23 17:15:27 +02:00
|
|
|
|
2016-03-01 18:43:26 +02:00
|
|
|
from base.Scope import Scope
|
2016-02-18 16:38:30 +02:00
|
|
|
|
2016-03-23 17:15:27 +02:00
|
|
|
|
2016-03-01 18:43:26 +02:00
|
|
|
class Plugin(threading.Thread):
|
2016-02-18 16:38:30 +02:00
|
|
|
"""docstring for Plugin"""
|
2016-03-23 17:15:27 +02:00
|
|
|
|
|
|
|
def __init__(self, name, InQueue):
|
2016-03-23 10:04:31 +02:00
|
|
|
threading.Thread.__init__(self)
|
2016-02-18 16:38:30 +02:00
|
|
|
self.name = name
|
2016-03-01 18:43:26 +02:00
|
|
|
self.InQueue = InQueue
|
2016-03-23 10:04:31 +02:00
|
|
|
scope = Scope.getInstance()
|
|
|
|
self.pluginManager = scope.getPluginManager()
|
|
|
|
self.logger = scope.getLogger()
|
2016-03-01 18:43:26 +02:00
|
|
|
|
2016-03-23 10:04:31 +02:00
|
|
|
def run(self):
|
2016-03-23 17:15:27 +02:00
|
|
|
while True:
|
2016-03-23 10:04:31 +02:00
|
|
|
try:
|
2016-03-29 11:52:18 +03:00
|
|
|
item_obj = self.InQueue.get(block=True)
|
|
|
|
obj_name = item_obj.obj_name
|
|
|
|
print(obj_name)
|
|
|
|
if obj_name == "TASK":
|
|
|
|
command = Scope.getInstance().getPluginManager().findCommand(self.getName(), item_obj.command_cls_id)
|
|
|
|
command.handle_task(item_obj)
|
|
|
|
# TODO add result to response queue
|
|
|
|
elif obj_name == "PROFILE":
|
|
|
|
plugin = item_obj.plugin
|
|
|
|
plugin_name = plugin.name
|
|
|
|
profile_data = item_obj.profile_data
|
|
|
|
policy_module = Scope.getInstance().getPluginManager().findPolicyModule(plugin_name)
|
|
|
|
policy_module.handle_policy(profile_data)
|
|
|
|
else:
|
|
|
|
self.logger.warning("Not supported object type " + obj_name)
|
2016-03-23 10:04:31 +02:00
|
|
|
except Exception as e:
|
2016-03-23 17:15:27 +02:00
|
|
|
# TODO error log here
|
2016-03-23 10:04:31 +02:00
|
|
|
self.logger.error("Plugin running exception " + str(e))
|
2016-02-18 16:38:30 +02:00
|
|
|
|
|
|
|
def getName(self):
|
|
|
|
return self.name
|