mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
Merge branch 'master' of https://github.com/Pardus-Kurumsal/ahenk
This commit is contained in:
commit
7eb8907b94
4 changed files with 67 additions and 45 deletions
|
@ -10,6 +10,7 @@ import stat
|
|||
import subprocess
|
||||
import uuid
|
||||
import urllib.request
|
||||
import errno
|
||||
|
||||
from base.Scope import Scope
|
||||
from base.messaging.ssh_file_transfer import FileTransfer
|
||||
|
@ -57,16 +58,21 @@ class ExecutionManager(object):
|
|||
temp_file = self.config_manager.get('CONNECTION', 'receivefileparam') + str(uuid.uuid4()) + '.deb'
|
||||
|
||||
if str(plugin['protocol']).lower() == 'ssh':
|
||||
self.logger.debug('[ExecutionManager] Distribution protocol is {}'.format(str(plugin['protocol']).lower()))
|
||||
host = parameter_map['host']
|
||||
username = parameter_map['username']
|
||||
password = parameter_map['password']
|
||||
port = parameter_map['port']
|
||||
path = parameter_map['path']
|
||||
try:
|
||||
self.logger.debug('[ExecutionManager] Distribution protocol is {}'.format(str(plugin['protocol']).lower()))
|
||||
host = parameter_map['host']
|
||||
username = parameter_map['username']
|
||||
password = parameter_map['password']
|
||||
port = parameter_map['port']
|
||||
path = parameter_map['path']
|
||||
|
||||
transfer = FileTransfer(host, port, username, password)
|
||||
transfer.connect()
|
||||
transfer.get_file(temp_file, path)
|
||||
transfer = FileTransfer(host, port, username, password)
|
||||
transfer.connect()
|
||||
transfer.get_file(temp_file, path)
|
||||
except Exception as e:
|
||||
self.logger.error('[ExecutionManager] Plugin package could not fetch. Error Message: {}.'.format(str(e)))
|
||||
self.logger.error('[ExecutionManager] Plugin Installation is cancelling')
|
||||
return
|
||||
|
||||
elif plugin['protocol'].lower() == 'http':
|
||||
self.logger.debug('[ExecutionManager] Distribution protocol is {}.'.format(str(plugin['protocol']).lower()))
|
||||
|
@ -75,10 +81,19 @@ class ExecutionManager(object):
|
|||
self.logger.debug('[ExecutionManager] Unsupported protocol is {}.'.format(str(plugin['protocol']).lower()))
|
||||
|
||||
self.logger.debug('[ExecutionManager] Plugin package downloaded via {}.'.format(str(plugin['protocol']).lower()))
|
||||
self.install_deb(temp_file)
|
||||
self.logger.debug('[ExecutionManager] Plugin installed.')
|
||||
self.remove_file(temp_file)
|
||||
self.logger.debug('[ExecutionManager] Temp files were removed.')
|
||||
try:
|
||||
self.install_deb(temp_file)
|
||||
self.logger.debug('[ExecutionManager] Plugin installed.')
|
||||
except Exception as e:
|
||||
self.logger.error('[ExecutionManager] Could not install plugin. Error Message: {}'.format(str(e)))
|
||||
return
|
||||
|
||||
try:
|
||||
self.remove_file(temp_file)
|
||||
self.logger.debug('[ExecutionManager] Temp files were removed.')
|
||||
except Exception as e:
|
||||
self.logger.error('[ExecutionManager] Could not remove temp file. Error Message: {}'.format(str(e)))
|
||||
|
||||
self.plugin_manager.loadSinglePlugin(plugin_name)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
@ -43,9 +43,10 @@ class FileTransfer(object):
|
|||
self.logger.debug('[FileTransfer] File was downloaded to {} from {}'.format(local_path, remote_path))
|
||||
except Exception as e:
|
||||
self.logger.error('[FileTransfer] A problem occurred while downloading file. Exception message: {}'.format(str(e)))
|
||||
raise
|
||||
finally:
|
||||
self.connection.close()
|
||||
self.logger.debug('[FileTransfer] Connection is closed successfully')
|
||||
self.logger.debug('[FileTransfer] Connection is closed successfully')
|
||||
|
||||
def connect(self):
|
||||
self.logger.debug('[FileTransfer] Connecting to {} via {}'.format(self.target_hostname, self.port))
|
||||
|
|
|
@ -38,18 +38,22 @@ class PluginManager(object):
|
|||
self.logger.info('[PluginManager] Loading plugins...')
|
||||
self.plugins = []
|
||||
self.logger.debug('[PluginManager] Lookup for possible plugins...')
|
||||
possibleplugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
||||
self.logger.debug('[PluginManager] Possible plugins.. ' + str(possibleplugins))
|
||||
for pname in possibleplugins:
|
||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pname)
|
||||
if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(location):
|
||||
self.logger.debug('It is not a plugin location ! There is no main module - ' + str(location))
|
||||
continue
|
||||
try:
|
||||
self.loadSinglePlugin(pname)
|
||||
except Exception as e:
|
||||
self.logger.error('[PluginManager] Exception occured when loading plugin ! Plugin name : ' + str(pname) + ' Exception : ' + str(e))
|
||||
self.logger.info('[PluginManager] Loaded plugins successfully.')
|
||||
|
||||
try:
|
||||
possible_plugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
||||
self.logger.debug('[PluginManager] Possible plugins: {} '.format(str(possible_plugins)))
|
||||
for plugin_name in possible_plugins:
|
||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
|
||||
if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(location):
|
||||
self.logger.debug('It is not a plugin location ! There is no main module - {}'.format(str(location)))
|
||||
continue
|
||||
try:
|
||||
self.loadSinglePlugin(plugin_name)
|
||||
except Exception as e:
|
||||
self.logger.error('[PluginManager] Exception occurred when loading plugin ! Plugin name : {} .Error Message: {}'.format(str(plugin_name), str(e)))
|
||||
self.logger.info('[PluginManager] Loaded plugins successfully.')
|
||||
except Exception as e:
|
||||
self.logger.warning('[PluginManager] Plugin folder path not found. Error Message: {}'.format(str(e)))
|
||||
|
||||
def loadSinglePlugin(self, plugin_name):
|
||||
# TODO check already loaded plugin
|
||||
|
|
|
@ -98,31 +98,32 @@ class Registration():
|
|||
|
||||
def get_registration_params(self):
|
||||
|
||||
print(System.Hardware.Network.ip_addresses())
|
||||
params = {
|
||||
'ipAddresses': self.get_ip_address(),
|
||||
'ipAddresses': str(System.Hardware.Network.ip_addresses()).replace('\'localhost\'', '').replace('\'127.0.0.1\'', ''),
|
||||
'macAddresses': System.Hardware.mac_address(),
|
||||
'hostname': str(socket.gethostname()),
|
||||
'system': str(platform.system()),
|
||||
'node': str(platform.node()),
|
||||
'release': str(platform.release()),
|
||||
'version': str(platform.version()),
|
||||
'machine': str(platform.machine()),
|
||||
'processor': str(platform.processor()),
|
||||
'architecture': str(platform.architecture()),
|
||||
'cpuCount': str(psutil.cpu_count()),
|
||||
'diskInfo': self.get_disks()
|
||||
'hostname': System.Os.hostname(),
|
||||
'os.name': System.Os.name(),
|
||||
'os.version': System.Os.version(),
|
||||
'os.kernel': System.Os.kernel_release(),
|
||||
'os.distributionName': System.Os.distribution_name(),
|
||||
'os.distributionId': System.Os.distribution_id(),
|
||||
'os.distributionVersion': System.Os.distribution_version(),
|
||||
'os.architecture': System.Os.architecture(),
|
||||
'hardware.cpu.architecture': System.Hardware.Cpu.architecture(),
|
||||
'hardware..cpu.logicalCoreCount': System.Hardware.Cpu.logical_core_count(),
|
||||
'hardware..cpu.physicalCoreCount': System.Hardware.Cpu.physical_core_count(),
|
||||
'hardware.disk.total': System.Hardware.Disk.total(),
|
||||
'hardware.disk.used': System.Hardware.Disk.used(),
|
||||
'hardware.disk.free': System.Hardware.Disk.free(),
|
||||
'hardware.disk.partitions': System.Hardware.Disk.partitions(),
|
||||
'hardware.memory.total': System.Hardware.Memory.total(),
|
||||
'hardware.network.ipAddresses': System.Hardware.Network.ip_addresses(),
|
||||
'sessions.userNames': System.Sessions.user_name(),
|
||||
}
|
||||
|
||||
return json.dumps(params)
|
||||
|
||||
def get_ip_address(self):
|
||||
arr = []
|
||||
for ip in System.Hardware.Network.ip_addresses():
|
||||
if ip is not 'localhost' and ip is not '127.0.0.1':
|
||||
arr.append(ip)
|
||||
return str(arr).replace('[','').replace(']','')
|
||||
|
||||
"""
|
||||
def get_disks(self):
|
||||
disk_info = []
|
||||
for _disk in psutil.disk_partitions():
|
||||
|
@ -134,6 +135,7 @@ class Registration():
|
|||
json_data = json.dumps(disk)
|
||||
disk_info.append(json_data)
|
||||
return disk_info
|
||||
"""
|
||||
|
||||
def unregister(self):
|
||||
self.logger.debug('[Registration] Ahenk is unregistering...')
|
||||
|
|
Loading…
Reference in a new issue