mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2025-01-13 22:29:41 +03:00
move and delete agent has been coded
This commit is contained in:
parent
2bcc0fa441
commit
1ea4435920
2 changed files with 49 additions and 64 deletions
|
@ -1,66 +1,44 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: Edip YILDIZ
|
# Author: Hasan Kara <hasankara@pardus.org.tr>
|
||||||
# Author: Tuncay ÇOLAK <tuncay.colak@tubitak.gov.tr>
|
|
||||||
|
|
||||||
|
|
||||||
from base.model.enum.content_type import ContentType
|
from base.model.enum.content_type import ContentType
|
||||||
import json, threading
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from base.scope import Scope
|
||||||
from base.plugin.abstract_plugin import AbstractPlugin
|
from base.plugin.abstract_plugin import AbstractPlugin
|
||||||
|
from base.registration.registration import Registration
|
||||||
import threading
|
|
||||||
|
|
||||||
|
|
||||||
class MoveAgent(AbstractPlugin):
|
class DeleteAgent(AbstractPlugin):
|
||||||
def __init__(self, data, context):
|
def __init__(self, data, context):
|
||||||
super(AbstractPlugin, self).__init__()
|
super(AbstractPlugin, self).__init__()
|
||||||
|
scope = Scope.get_instance()
|
||||||
self.data = data
|
self.data = data
|
||||||
self.context = context
|
self.context = context
|
||||||
self.logger = self.get_logger()
|
self.logger = self.get_logger()
|
||||||
self.message_code = self.get_message_code()
|
self.message_code = self.get_message_code()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_dn(self, jid, newDn):
|
|
||||||
cols = ['dn'];
|
|
||||||
values = [newDn]
|
|
||||||
return self.db_service.update('registration', cols, values, 'jid=\''+jid+'\'')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getCnFromDn(self,dn):
|
|
||||||
if dn !=None and str(dn) !="":
|
|
||||||
dnStrArr = str(dn).split(",")
|
|
||||||
if len(dnStrArr)>0:
|
|
||||||
return dnStrArr[0]
|
|
||||||
|
|
||||||
|
|
||||||
def handle_task(self):
|
def handle_task(self):
|
||||||
try:
|
try:
|
||||||
dn = self.data['dn']
|
dn = self.data['dn']
|
||||||
newParentDn = self.data['newParentDn']
|
directory_server = self.data['directory_server']
|
||||||
|
registration = Scope.get_instance().get_registration()
|
||||||
jid= self.db_service.select_one_result('registration','jid','registered = 1')
|
registration.purge_and_unregister(directory_server)
|
||||||
|
|
||||||
newDn=str(dn).replace(dn, self.getCnFromDn(dn)+ str(newParentDn))
|
|
||||||
|
|
||||||
self.update_dn(jid,newDn)
|
|
||||||
|
|
||||||
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
||||||
message='Ahenk başarı ile taşındı.',
|
message='Ahenk başarı ile silindi.',
|
||||||
data=json.dumps({'Dn': newDn}),
|
data=json.dumps({'Dn': dn}),
|
||||||
content_type=ContentType.APPLICATION_JSON.value)
|
content_type=ContentType.APPLICATION_JSON.value)
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(" error on handle xmessage task. Error: " + str(e))
|
self.logger.error(" error on handle deleting agent. Error: " + str(e))
|
||||||
self.context.create_response(code=self.message_code.TASK_ERROR.value,
|
self.context.create_response(code=self.message_code.TASK_ERROR.value,
|
||||||
message='Ahenk taşınırken hata olustu' + str(e),
|
message='Ahenk silinirken hata olustu' + str(e),
|
||||||
content_type=ContentType.APPLICATION_JSON.value)
|
content_type=ContentType.APPLICATION_JSON.value)
|
||||||
|
|
||||||
|
|
||||||
def handle_task(task, context):
|
def handle_task(task, context):
|
||||||
cls = MoveAgent(task, context)
|
cls = DeleteAgent(task, context)
|
||||||
cls.handle_task()
|
cls.handle_task()
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: Edip YILDIZ
|
# Author: Hasan Kara <hasankara@pardus.org.tr>
|
||||||
# Author: Tuncay ÇOLAK <tuncay.colak@tubitak.gov.tr>
|
|
||||||
|
|
||||||
|
|
||||||
from base.model.enum.content_type import ContentType
|
from base.model.enum.content_type import ContentType
|
||||||
import json, threading
|
import json
|
||||||
|
|
||||||
|
|
||||||
from base.plugin.abstract_plugin import AbstractPlugin
|
from base.plugin.abstract_plugin import AbstractPlugin
|
||||||
|
|
||||||
import threading
|
|
||||||
|
|
||||||
|
|
||||||
class MoveAgent(AbstractPlugin):
|
class MoveAgent(AbstractPlugin):
|
||||||
def __init__(self, data, context):
|
def __init__(self, data, context):
|
||||||
|
@ -21,46 +17,57 @@ class MoveAgent(AbstractPlugin):
|
||||||
self.logger = self.get_logger()
|
self.logger = self.get_logger()
|
||||||
self.message_code = self.get_message_code()
|
self.message_code = self.get_message_code()
|
||||||
|
|
||||||
|
def update_dn(self, jid, new_dn):
|
||||||
|
cols = ['dn']
|
||||||
def update_dn(self, jid, newDn):
|
values = [new_dn]
|
||||||
cols = ['dn'];
|
|
||||||
values = [newDn]
|
|
||||||
return self.db_service.update('registration', cols, values, 'jid=\''+jid+'\'')
|
return self.db_service.update('registration', cols, values, 'jid=\''+jid+'\'')
|
||||||
|
|
||||||
|
def get_cn_from_dn(self, dn):
|
||||||
|
if dn != None and str(dn) != "":
|
||||||
def getCnFromDn(self,dn):
|
dn_str_arr = str(dn).split(",")
|
||||||
if dn !=None and str(dn) !="":
|
if len(dn_str_arr) > 0:
|
||||||
dnStrArr = str(dn).split(",")
|
return dn_str_arr[0]
|
||||||
if len(dnStrArr)>0:
|
|
||||||
return dnStrArr[0]
|
|
||||||
|
|
||||||
|
|
||||||
def handle_task(self):
|
def handle_task(self):
|
||||||
try:
|
try:
|
||||||
dn = self.data['dn']
|
dn = self.data['dn']
|
||||||
newParentDn = self.data['newParentDn']
|
new_parent_dn = self.data['new_parent_dn']
|
||||||
|
directory_server = self.data['directory_server']
|
||||||
|
|
||||||
jid= self.db_service.select_one_result('registration','jid','registered = 1')
|
jid = self.db_service.select_one_result('registration', 'jid', 'registered = 1')
|
||||||
|
new_dn = str(dn).replace(dn, self.get_cn_from_dn(dn) + ',' + str(new_parent_dn))
|
||||||
|
self.update_dn(jid, new_dn)
|
||||||
|
|
||||||
newDn=str(dn).replace(dn, self.getCnFromDn(dn)+ str(newParentDn))
|
if directory_server == "LDAP":
|
||||||
|
# update SSSD conf agent DN
|
||||||
|
sssd_config_file_path = "/etc/sssd/sssd.conf"
|
||||||
|
file_sssd = open(sssd_config_file_path, 'r')
|
||||||
|
file_data = file_sssd.read()
|
||||||
|
old_dn_in_sssd = ""
|
||||||
|
new_dn_in_sssd = "ldap_default_bind_dn = " + new_dn + "\n"
|
||||||
|
with open(sssd_config_file_path) as fp:
|
||||||
|
for line in fp:
|
||||||
|
if line.startswith('ldap_default_bind_dn'):
|
||||||
|
old_dn_in_sssd = line
|
||||||
|
file_data = file_data.replace(old_dn_in_sssd, new_dn_in_sssd)
|
||||||
|
|
||||||
self.update_dn(jid,newDn)
|
file_sssd.close()
|
||||||
|
file_sssd = open(sssd_config_file_path, 'w')
|
||||||
|
file_sssd.write(file_data)
|
||||||
|
file_sssd.close()
|
||||||
|
|
||||||
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
||||||
message='Ahenk başarı ile taşındı.',
|
message='Ahenk başarı ile taşındı.',
|
||||||
data=json.dumps({'Dn': newDn}),
|
data=json.dumps({'Dn': new_dn}),
|
||||||
content_type=ContentType.APPLICATION_JSON.value)
|
content_type=ContentType.APPLICATION_JSON.value)
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(" error on handle xmessage task. Error: " + str(e))
|
self.logger.error("Error occured while moving agent. Error: " + str(e))
|
||||||
self.context.create_response(code=self.message_code.TASK_ERROR.value,
|
self.context.create_response(code=self.message_code.TASK_ERROR.value,
|
||||||
message='Ahenk taşınırken hata olustu' + str(e),
|
message='Ahenk taşınırken hata olustu' + str(e),
|
||||||
content_type=ContentType.APPLICATION_JSON.value)
|
content_type=ContentType.APPLICATION_JSON.value)
|
||||||
|
|
||||||
|
|
||||||
def handle_task(task, context):
|
def handle_task(task, context):
|
||||||
cls = MoveAgent(task, context)
|
cls = MoveAgent(task, context)
|
||||||
cls.handle_task()
|
cls.handle_task()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue