retrive file ahenk to lider via selected protocol was implemented

This commit is contained in:
Volkan Şahin 2016-05-12 17:35:47 +03:00
parent 518acdc784
commit d0b2e62b8d
3 changed files with 35 additions and 5 deletions

View file

@ -226,7 +226,7 @@ class AhenkDeamon(BaseDaemon):
while True:
if messager.ping_lider() is False:
Scope.getInstance().getLogger().warning('[AhenkDeamon] Connection is lost. Ahenk is trying for reconnection')
messager=self.init_messager()
messager = self.init_messager()
time.sleep(1)
def signal_handler(self, num, stack):
@ -251,7 +251,7 @@ class AhenkDeamon(BaseDaemon):
if 'login' == str(params[0]):
logger.debug('[AhenkDeamon] Signal is :{}'.format(str(params[0])))
login_message = message_manager.login_msg(params[1])
#messenger.send_direct_message(login_message)
# messenger.send_direct_message(login_message)
get_policy_message = message_manager.policy_request_msg(params[1])
messenger.send_direct_message(get_policy_message)
logger.debug('[AhenkDeamon] login event is handled for user:' + params[1])

View file

@ -11,7 +11,6 @@ import subprocess
import uuid
import urllib.request
from base.Scope import Scope
from base.messaging.ssh_file_transfer import FileTransfer
from base.model.PluginBean import PluginBean
@ -38,7 +37,10 @@ class ExecutionManager(object):
self.plugin_manager = scope.getPluginManager()
self.event_manager.register_event(MessageType.EXECUTE_SCRIPT.value, self.execute_script)
# send file ahenk to lider
self.event_manager.register_event(MessageType.REQUEST_FILE.value, self.request_file)
# send file lider to ahenk
self.event_manager.register_event(MessageType.RETRIVE_FILE.value, self.retrive_file)
self.event_manager.register_event(MessageType.MOVE_FILE.value, self.move_file)
self.event_manager.register_event(MessageType.EXECUTE_TASK.value, self.execute_task)
self.event_manager.register_event(MessageType.EXECUTE_POLICY.value, self.execute_policy)
@ -69,6 +71,8 @@ class ExecutionManager(object):
elif plugin['protocol'].lower() == 'http':
self.logger.debug('[ExecutionManager] Distribution protocol is {}.'.format(str(plugin['protocol']).lower()))
urllib.request.urlretrieve(parameter_map['url'], temp_file)
else:
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)
@ -226,7 +230,32 @@ class ExecutionManager(object):
os.chmod(file_path, st.st_mode | stat.S_IEXEC)
subprocess.call("/bin/sh " + file_path, shell=True)
# need to move somewhere else
def retrive_file(self, arg):
j = json.loads(arg)
parameter_map = json.loads(json.dumps(j['parameterMap']))
temp_file_path = self.config_manager.get('CONNECTION', 'receivefileparam')
temp_file_name = str(uuid.uuid4())
if str(j['protocol']).lower() == 'ssh':
self.logger.debug('[ExecutionManager] Retrive file protocol is {}'.format(str(j['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 + temp_file_name, path)
elif str(j['protocol']).lower() == 'http':
self.logger.debug('[ExecutionManager] Retrive file protocol is {}.'.format(str(j['protocol']).lower()))
urllib.request.urlretrieve(parameter_map['url'], temp_file_path + temp_file_name)
else:
self.logger.debug('[ExecutionManager] Unsupported protocol is {}.'.format(str(j['protocol']).lower()))
md5_hash = self.get_md5_file(temp_file_path + temp_file_name)
os.rename(temp_file_path + temp_file_name, temp_file_path + md5_hash)
def request_file(self, arg):
j = json.loads(arg)
# msg_id =str(j['id']).lower()

View file

@ -18,5 +18,6 @@ class MessageType(Enum):
REGISTER = 'REGISTER'
REGISTER_LDAP = 'REGISTER_LDAP'
REQUEST_FILE = 'REQUEST_FILE'
RETRIVE_FILE = 'SEND_FILE'
UNREGISTER = 'UNREGISTER'
TASK_STATUS = 'TASK_STATUS'