mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-14 06:12:19 +03:00
rename agent is developed
This commit is contained in:
parent
772e6430a8
commit
e8a128d91e
1 changed files with 44 additions and 20 deletions
|
@ -1,50 +1,74 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: Edip YILDIZ
|
# Author: Edip YILDIZ
|
||||||
# Author: Tuncay ÇOLAK <tuncay.colak@tubitak.gov.tr>
|
# Author: Hasan Kara <hasan.kara@pardus.org.tr>
|
||||||
|
|
||||||
|
|
||||||
from base.model.enum.content_type import ContentType
|
from base.model.enum.content_type import ContentType
|
||||||
import json, threading
|
import json, threading
|
||||||
|
|
||||||
|
|
||||||
from base.plugin.abstract_plugin import AbstractPlugin
|
from base.plugin.abstract_plugin import AbstractPlugin
|
||||||
|
from base.scope import Scope
|
||||||
import threading
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateEntry(AbstractPlugin):
|
class RenameEntry(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()
|
||||||
|
self.conf_manager = scope.get_configuration_manager()
|
||||||
|
self.hostname_file = '/etc/hostname'
|
||||||
|
|
||||||
|
def update_dn(self, old_cn, new_cn, new_dn):
|
||||||
|
return self.db_service.update('registration', ['jid', 'dn'], [new_cn, new_dn], ' jid = ' + '\'' + old_cn + '\'')
|
||||||
def update_dn(self, jid, newDn):
|
|
||||||
cols = ['dn'];
|
|
||||||
values = [newDn]
|
|
||||||
return self.db_service.update('registration', cols, values, 'jid=\''+jid+'\'')
|
|
||||||
|
|
||||||
|
|
||||||
def handle_task(self):
|
def handle_task(self):
|
||||||
try:
|
try:
|
||||||
dn = self.data['dn']
|
old_dn = self.data['dn']
|
||||||
jid= self.db_service.select_one_result('registration','jid','registered = 1')
|
old_cn = self.data['old_cn']
|
||||||
|
new_cn = self.data['new_cn']
|
||||||
|
directory_server = self.data['directory_server']
|
||||||
|
new_dn = str(old_dn).replace(old_cn, new_cn)
|
||||||
|
|
||||||
cn = self.data['oldCn']
|
self.logger.debug('Renaming hostname from: ' + old_cn + " to: " + new_cn)
|
||||||
newCn = self.data['newCn']
|
self.write_file(self.hostname_file, new_cn)
|
||||||
|
|
||||||
newDn=str(dn).replace(cn,newCn)
|
## update agent db
|
||||||
|
jid = self.db_service.select_one_result('registration','jid','registered = 1')
|
||||||
|
new_dn = str(old_dn).replace(old_cn, new_cn)
|
||||||
|
|
||||||
self.update_dn(jid,newDn)
|
self.update_dn(old_cn, new_cn, new_dn)
|
||||||
|
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)
|
||||||
|
|
||||||
|
file_sssd.close()
|
||||||
|
file_sssd = open(sssd_config_file_path, 'w')
|
||||||
|
file_sssd.write(file_data)
|
||||||
|
file_sssd.close()
|
||||||
|
|
||||||
|
# update ahenk.conf
|
||||||
|
self.conf_manager.set('CONNECTION', 'uid', new_cn)
|
||||||
|
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
|
||||||
|
self.conf_manager.write(configfile)
|
||||||
|
|
||||||
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
||||||
message='Ahenk adı başarı ile değiştirildi.',
|
message='Ahenk adı başarı ile değiştirildi.',
|
||||||
data=json.dumps({'Dn': newDn}),
|
data=json.dumps({'Dn': new_dn}),
|
||||||
content_type=ContentType.APPLICATION_JSON.value)
|
content_type=ContentType.APPLICATION_JSON.value)
|
||||||
|
self.execute("systemctl restart ahenk.service")
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -55,5 +79,5 @@ class UpdateEntry(AbstractPlugin):
|
||||||
|
|
||||||
|
|
||||||
def handle_task(task, context):
|
def handle_task(task, context):
|
||||||
cls = UpdateEntry(task, context)
|
cls = RenameEntry(task, context)
|
||||||
cls.handle_task()
|
cls.handle_task()
|
||||||
|
|
Loading…
Reference in a new issue