mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-12-26 03:02:16 +03:00
implemented policy process
This commit is contained in:
parent
eba656d8ae
commit
5d905432ad
7 changed files with 70 additions and 8 deletions
|
@ -35,12 +35,19 @@ class Policy(object):
|
|||
@property
|
||||
def user_profiles(self):
|
||||
profiles = []
|
||||
for p in self.policy['userProfiles']:
|
||||
profiles.append(Profile(p))
|
||||
return profiles
|
||||
try:
|
||||
for p in self.policy['userPolicyProfiles']:
|
||||
profiles.append(Profile(p))
|
||||
return profiles
|
||||
except Exception as e:
|
||||
return None
|
||||
|
||||
|
||||
def to_string(self):
|
||||
return str(self.policy)
|
||||
|
||||
def to_json(self):
|
||||
return json.load(self.policy)
|
||||
|
||||
def obj_type(self):
|
||||
return "POLICY"
|
||||
|
|
|
@ -57,3 +57,7 @@ class Profile(object):
|
|||
|
||||
def to_json(self):
|
||||
return json.load(self.profile)
|
||||
|
||||
@property
|
||||
def obj_name(self):
|
||||
return "PROFILE"
|
||||
|
|
|
@ -46,3 +46,7 @@ class Task(object):
|
|||
|
||||
def to_json(self):
|
||||
return json.load(self.task)
|
||||
|
||||
@property
|
||||
def obj_name(self):
|
||||
return "TASK"
|
||||
|
|
|
@ -20,11 +20,21 @@ class Plugin(threading.Thread):
|
|||
def run(self):
|
||||
while True:
|
||||
try:
|
||||
task = self.InQueue.get(block=True)
|
||||
command = Scope.getInstance().getPluginManager().findCommand(self.getName(), task.command_cls_id)
|
||||
command.handle_task(task)
|
||||
# TODO add result to response queue
|
||||
|
||||
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)
|
||||
except Exception as e:
|
||||
# TODO error log here
|
||||
self.logger.error("Plugin running exception " + str(e))
|
||||
|
|
|
@ -66,6 +66,28 @@ class PluginManager(object):
|
|||
# Not implemented yet
|
||||
pass
|
||||
|
||||
def findPolicyModule(self,plugin_name):
|
||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
|
||||
if os.path.isdir(location) and "policy.py" in os.listdir(location):
|
||||
info = imp.find_module("policy", [location])
|
||||
return imp.load_module("policy", *info)
|
||||
else:
|
||||
self.logger.warning('[PluginManager] policy.py not found Plugin Name : ' + str(plugin_name))
|
||||
return None
|
||||
|
||||
def processPolicy(self, policy):
|
||||
user_profiles = policy.user_profiles
|
||||
for profile in user_profiles:
|
||||
try:
|
||||
plugin = profile.plugin
|
||||
plugin_name = plugin.name
|
||||
if plugin_name in self.pluginQueueDict:
|
||||
self.pluginQueueDict[plugin_name].put(profile, 1)
|
||||
except Exception as e:
|
||||
print("Exception occured..")
|
||||
self.logger.error("Policy profile not processed " + str(profile.plugin.name))
|
||||
|
||||
|
||||
def checkPluginExists(self, plugin_name, version=None):
|
||||
|
||||
criteria = ' name=\''+plugin_name+'\''
|
||||
|
|
|
@ -28,6 +28,14 @@ class TaskManager(object):
|
|||
self.logger.debug('Exception occured when adding task ' + str(e))
|
||||
pass
|
||||
|
||||
def addPolicy(self,policy):
|
||||
try:
|
||||
print("adding policy")
|
||||
self.pluginManager.processPolicy(policy)
|
||||
except Exception as e:
|
||||
self.logger.error("Exception occured when adding policy ")
|
||||
pass
|
||||
|
||||
def saveTask(self, task):
|
||||
cols = ['id', 'create_date', 'modify_date', 'command_cls_id', 'parameter_map', 'deleted', 'plugin']
|
||||
values = [str(task.id), str(task.create_date), str(task.modify_date), str(task.command_cls_id), str(task.parameter_map), str(task.deleted), task.plugin.to_string()]
|
||||
|
|
7
opt/ahenk/plugins/plugin1/policy.py
Normal file
7
opt/ahenk/plugins/plugin1/policy.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
|
||||
|
||||
def handle_policy(profile_data):
|
||||
print("This is policy file - plugin 1")
|
Loading…
Reference in a new issue