mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-09 18:52:16 +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
|
||||
# -*- coding: utf-8 -*-
|
||||
# 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
|
||||
import json, threading
|
||||
|
||||
|
||||
from base.plugin.abstract_plugin import AbstractPlugin
|
||||
|
||||
import threading
|
||||
from base.scope import Scope
|
||||
|
||||
|
||||
class UpdateEntry(AbstractPlugin):
|
||||
class RenameEntry(AbstractPlugin):
|
||||
def __init__(self, data, context):
|
||||
super(AbstractPlugin, self).__init__()
|
||||
scope = Scope().get_instance()
|
||||
self.data = data
|
||||
self.context = context
|
||||
self.logger = self.get_logger()
|
||||
self.message_code = self.get_message_code()
|
||||
self.conf_manager = scope.get_configuration_manager()
|
||||
self.hostname_file = '/etc/hostname'
|
||||
|
||||
|
||||
|
||||
def update_dn(self, jid, newDn):
|
||||
cols = ['dn'];
|
||||
values = [newDn]
|
||||
return self.db_service.update('registration', cols, values, 'jid=\''+jid+'\'')
|
||||
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 handle_task(self):
|
||||
try:
|
||||
dn = self.data['dn']
|
||||
jid= self.db_service.select_one_result('registration','jid','registered = 1')
|
||||
old_dn = self.data['dn']
|
||||
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)
|
||||
|
||||
self.logger.debug('Renaming hostname from: ' + old_cn + " to: " + new_cn)
|
||||
self.write_file(self.hostname_file, new_cn)
|
||||
|
||||
cn = self.data['oldCn']
|
||||
newCn = self.data['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)
|
||||
|
||||
newDn=str(dn).replace(cn,newCn)
|
||||
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)
|
||||
|
||||
self.update_dn(jid,newDn)
|
||||
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,
|
||||
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)
|
||||
self.execute("systemctl restart ahenk.service")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
|
@ -55,5 +79,5 @@ class UpdateEntry(AbstractPlugin):
|
|||
|
||||
|
||||
def handle_task(task, context):
|
||||
cls = UpdateEntry(task, context)
|
||||
cls = RenameEntry(task, context)
|
||||
cls.handle_task()
|
||||
|
|
Loading…
Reference in a new issue