diff --git a/src/im_mad/im_ssh/one_im_ssh.rb b/src/im_mad/im_ssh/one_im_ssh.rb index 8884e89cec..5a116528b9 100755 --- a/src/im_mad/im_ssh/one_im_ssh.rb +++ b/src/im_mad/im_ssh/one_im_ssh.rb @@ -71,7 +71,7 @@ class InformationManager < OpenNebulaDriver end cmd_string = "#{@remote_dir}/im/run_probes #{@hypervisor} #{host}" - cmd = SSHCommand.run(cmd_string, host, log_lambda) + cmd = RemotesCommand.run(cmd_string, host, @remote_dir, log_lambda) if cmd.code == 0 send_message("MONITOR", RESULT[:success], number, cmd.stdout) diff --git a/src/mad/ruby/CommandManager.rb b/src/mad/ruby/CommandManager.rb index 6588c14b52..e78ddef6de 100644 --- a/src/mad/ruby/CommandManager.rb +++ b/src/mad/ruby/CommandManager.rb @@ -138,6 +138,48 @@ private end end +class RemotesCommand < SSHCommand + ONE_LOCATION=ENV["ONE_LOCATION"] + + if !ONE_LOCATION + REMOTES_LOCATION="/usr/lib/one/remotes" + else + REMOTES_LOCATION=ONE_LOCATION+"/lib/remotes/" + end + + MAGIC_RC = 42 + + # Creates a command and runs it + def self.run(command, host, remote_dir, logger=nil, stdin=nil) + cmd_file = command.split(' ')[0] + + cmd_string = "'if [ -x \"#{cmd_file}\" ]; then; #{command}; else;\ + exit #{MAGIC_RC}; fi'" + + cmd = self.new(cmd_string, host, logger, stdin) + cmd.run + + if cmd.code == MAGIC_RC + cmd.update_remotes(host, remote_dir, logger) + cmd = super(command, host, logger, stdin) + end + + cmd + end + + def update_remotes(host, remote_dir, logger=nil) + log("Remote worker node files not found") + log("Updating remotes") + + # Use SCP to sync: + sync_cmd = "scp -r #{REMOTES_LOCATION}/. #{host}:#{remote_dir}" + + # Use rsync to sync: + # sync_cmd = "rsync -Laz #{REMOTES_LOCATION} #{host}:#{@remote_dir}" + LocalCommand.run(sync_cmd, logger) + end +end + if $0 == __FILE__ diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index 9c69c4c617..f75fb5eb90 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -107,16 +107,19 @@ class VirtualMachineDriver < OpenNebulaDriver # ------------------------------------------------------------------------- # Execute a command associated to an action and id in a remote host. # ------------------------------------------------------------------------- - def ssh_action(command, id, host, action) - command_exe = SSHCommand.run(command, host, log_method(id)) + def remotes_action(command, id, host, action, remote_dir, std_in=nil) + command_exe = RemotesCommand.run( + command, host, remote_dir, log_method(id), std_in) if command_exe.code == 0 result = :success + info = command_exe.stdout else result = :failure + info = command_exe.stderr end - send_message(ACTION[action],RESULT[result],id) + send_message(ACTION[action],RESULT[result],id,info) end # ------------------------------------------------------------------------- diff --git a/src/vmm_mad/ssh/one_vmm_ssh.rb b/src/vmm_mad/ssh/one_vmm_ssh.rb index 014eda5090..8226b79f89 100755 --- a/src/vmm_mad/ssh/one_vmm_ssh.rb +++ b/src/vmm_mad/ssh/one_vmm_ssh.rb @@ -66,56 +66,41 @@ class SshDriver < VirtualMachineDriver domain = tmp.read tmp.close() - cmd = "#{@remote_dir}/vmm/#{@hypervisor}/deploy #{remote_dfile}" - - deploy_exe = SSHCommand.run(cmd, host, log_method(id), domain) - - - if deploy_exe.code != 0 - send_message(ACTION[:deploy],RESULT[:failure],id) - else - send_message(ACTION[:deploy],RESULT[:success],id,deploy_exe.stdout) - end + remotes_action("#{@remote_dir}/vmm/#{@hypervisor}/deploy #{remote_dfile}", + id, host, :deploy, @remote_dir) end # ------------------------------------------------------------------------ # # Basic Domain Management Operations # # ------------------------------------------------------------------------ # def shutdown(id, host, deploy_id, not_used) - ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/shutdown #{deploy_id}", - id, host, :shutdown) + remotes_action("#{@remote_dir}/vmm/#{@hypervisor}/shutdown #{deploy_id}", + id, host, :shutdown, @remote_dir) end def cancel(id, host, deploy_id, not_used) - ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/cancel #{deploy_id}", - id, host, :cancel) + remotes_action("#{@remote_dir}/vmm/#{@hypervisor}/cancel #{deploy_id}", + id, host, :cancel, @remote_dir) end def save(id, host, deploy_id, file) - ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/save #{deploy_id} #{file}", - id, host, :save) + remotes_action("#{@remote_dir}/vmm/#{@hypervisor}/save #{deploy_id} #{file}", + id, host, :save, @remote_dir) end def restore(id, host, deploy_id, file) - ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/restore #{file}", - id, host, :restore) + remotes_action("#{@remote_dir}/vmm/#{@hypervisor}/restore #{file}", + id, host, :restore, @remote_dir) end def migrate(id, host, deploy_id, dest_host) - ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/migrate #{deploy_id} #{dest_host}", - id, host, :migrate) + remotes_action("#{@remote_dir}/vmm/#{@hypervisor}/migrate #{deploy_id} #{dest_host}", + id, host, :migrate, @remote_dir) end def poll(id, host, deploy_id, not_used) - cmd = "#{@remote_dir}/vmm/#{@hypervisor}/poll #{deploy_id}" - - poll_exe = SSHCommand.run(cmd, host, log_method(id)) - - if poll_exe.code != 0 - send_message(ACTION[:poll],RESULT[:failure],id) - else - send_message(ACTION[:poll],RESULT[:success],id,poll_exe.stdout) - end + remotes_action("#{@remote_dir}/vmm/#{@hypervisor}/poll #{deploy_id}", + id, host, :poll, @remote_dir) end end