diff --git a/include/Nebula.h b/include/Nebula.h index 15e5268775..8767aa9942 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -237,7 +237,7 @@ private: log_location = "/var/log/one/"; var_location = "/var/lib/one/"; hook_location = "/usr/share/one/hooks/"; - remotes_location = "/usr/lib/one/remotes/"; + remotes_location = "/var/lib/one/remotes/"; } else { @@ -253,7 +253,7 @@ private: log_location = nebula_location + "var/"; var_location = nebula_location + "var/"; hook_location = nebula_location + "share/hooks/"; - remotes_location = nebula_location + "lib/remotes/"; + remotes_location = nebula_location + "var/remotes/"; } }; diff --git a/install.sh b/install.sh index 4d6059e806..2834543290 100755 --- a/install.sh +++ b/install.sh @@ -168,13 +168,7 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \ $ETC_LOCATION/ec2query_templates \ $ETC_LOCATION/occi_templates" -LIB_DIRS="$LIB_LOCATION/remotes \ - $LIB_LOCATION/remotes/im \ - $LIB_LOCATION/remotes/im/kvm.d \ - $LIB_LOCATION/remotes/im/xen.d \ - $LIB_LOCATION/remotes/vmm/xen \ - $LIB_LOCATION/remotes/vmm/kvm \ - $LIB_LOCATION/ruby \ +LIB_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/OpenNebula \ $LIB_LOCATION/ruby/cloud/ \ $LIB_LOCATION/ruby/cloud/econe \ @@ -187,6 +181,13 @@ LIB_DIRS="$LIB_LOCATION/remotes \ $LIB_LOCATION/tm_commands/lvm \ $LIB_LOCATION/mads" +VAR_DIRS="$VAR_LOCATION/remotes \ + $VAR_LOCATION/remotes/im \ + $VAR_LOCATION/remotes/im/kvm.d \ + $VAR_LOCATION/remotes/im/xen.d \ + $VAR_LOCATION/remotes/vmm/xen \ + $VAR_LOCATION/remotes/vmm/kvm" + LIB_ECO_CLIENT_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/OpenNebula $LIB_LOCATION/ruby/cloud/ \ @@ -197,7 +198,7 @@ LIB_OCCI_CLIENT_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/cloud/occi" if [ "$CLIENT" = "no" ]; then - MAKE_DIRS="$MAKE_DIRS $SHARE_DIRS $ETC_DIRS $LIB_DIRS" + MAKE_DIRS="$MAKE_DIRS $SHARE_DIRS $ETC_DIRS $LIB_DIRS $VAR_DIRS" elif [ "$CLIENT" = "ec2" ]; then MAKE_DIRS="$MAKE_DIRS $LIB_ECO_CLIENT_DIRS" elif [ "$CLIENT" = "occi" ]; then @@ -216,11 +217,11 @@ INSTALL_FILES[2]="LIB_FILES:$LIB_LOCATION" INSTALL_FILES[3]="RUBY_LIB_FILES:$LIB_LOCATION/ruby" INSTALL_FILES[4]="RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula" INSTALL_FILES[5]="MADS_LIB_FILES:$LIB_LOCATION/mads" -INSTALL_FILES[6]="IM_PROBES_FILES:$LIB_LOCATION/remotes/im" -INSTALL_FILES[7]="IM_PROBES_KVM_FILES:$LIB_LOCATION/remotes/im/kvm.d" -INSTALL_FILES[8]="IM_PROBES_XEN_FILES:$LIB_LOCATION/remotes/im/xen.d" -INSTALL_FILES[9]="VMM_SSH_KVM_SCRIPTS:$LIB_LOCATION/remotes/vmm/kvm" -INSTALL_FILES[10]="VMM_SSH_XEN_SCRIPTS:$LIB_LOCATION/remotes/vmm/xen" +INSTALL_FILES[6]="IM_PROBES_FILES:$VAR_LOCATION/remotes/im" +INSTALL_FILES[7]="IM_PROBES_KVM_FILES:$VAR_LOCATION/remotes/im/kvm.d" +INSTALL_FILES[8]="IM_PROBES_XEN_FILES:$VAR_LOCATION/remotes/im/xen.d" +INSTALL_FILES[9]="VMM_SSH_KVM_SCRIPTS:$VAR_LOCATION/remotes/vmm/kvm" +INSTALL_FILES[10]="VMM_SSH_XEN_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen" INSTALL_FILES[11]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs" INSTALL_FILES[12]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh" INSTALL_FILES[13]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy" diff --git a/src/cli/onehost b/src/cli/onehost index 2bf1ec1eb3..8af1a3524a 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -387,7 +387,7 @@ when "disable" when "sync" check_parameters("sync", 0) if ONE_LOCATION - FileUtils.touch "#{ONE_LOCATION}/lib/remotes" + FileUtils.touch "#{ONE_LOCATION}/var/remotes" else FileUtils.touch "/var/lib/one/remotes" end diff --git a/src/im_mad/im_sh/one_im_sh.rb b/src/im_mad/im_sh/one_im_sh.rb index 79714d2934..71cf5e0a3e 100755 --- a/src/im_mad/im_sh/one_im_sh.rb +++ b/src/im_mad/im_sh/one_im_sh.rb @@ -21,13 +21,11 @@ ONE_LOCATION=ENV["ONE_LOCATION"] if !ONE_LOCATION RUBY_LIB_LOCATION="/usr/lib/one/ruby" ETC_LOCATION="/etc/one/" - PROBE_LOCATION="/usr/lib/one/im_probes/" - REMOTES_LOCATION="/usr/lib/one/remotes" + REMOTES_LOCATION="/var/lib/one/remotes" else RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" ETC_LOCATION=ONE_LOCATION+"/etc/" - PROBE_LOCATION=ONE_LOCATION+"/lib/im_probes/" - REMOTES_LOCATION=ONE_LOCATION+"/lib/remotes/" + REMOTES_LOCATION=ONE_LOCATION+"/var/remotes/" end $: << RUBY_LIB_LOCATION @@ -49,7 +47,7 @@ class InformationManager < OpenNebulaDriver @config = read_configuration @hypervisor = hypervisor - @cmd_path = "#{ENV['ONE_LOCATION']}/lib/remotes/im" + @cmd_path = "#{REMOTES_LOCATION}/im" # register actions register_action(:MONITOR, method("action_monitor")) diff --git a/src/im_mad/im_ssh/one_im_ssh.rb b/src/im_mad/im_ssh/one_im_ssh.rb index 57dd1514c8..5a116528b9 100755 --- a/src/im_mad/im_ssh/one_im_ssh.rb +++ b/src/im_mad/im_ssh/one_im_ssh.rb @@ -21,13 +21,11 @@ ONE_LOCATION=ENV["ONE_LOCATION"] if !ONE_LOCATION RUBY_LIB_LOCATION="/usr/lib/one/ruby" ETC_LOCATION="/etc/one/" - PROBE_LOCATION="/usr/lib/one/im_probes/" - REMOTES_LOCATION="/usr/lib/one/remotes" + REMOTES_LOCATION="/var/lib/one/remotes" else RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" ETC_LOCATION=ONE_LOCATION+"/etc/" - PROBE_LOCATION=ONE_LOCATION+"/lib/im_probes/" - REMOTES_LOCATION=ONE_LOCATION+"/lib/remotes/" + REMOTES_LOCATION=ONE_LOCATION+"/var/remotes/" end $: << RUBY_LIB_LOCATION @@ -73,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..0f3082d8fd 100644 --- a/src/mad/ruby/CommandManager.rb +++ b/src/mad/ruby/CommandManager.rb @@ -138,6 +138,50 @@ private end end +class RemotesCommand < SSHCommand + ONE_LOCATION=ENV["ONE_LOCATION"] + + if !ONE_LOCATION + REMOTES_LOCATION="/var/lib/one/remotes" + else + REMOTES_LOCATION=ONE_LOCATION+"/var/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 + self.update_remotes(host, remote_dir, logger) + + @command = command + cmd.run + end + + cmd + end + + def self.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..f696875926 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -59,7 +59,7 @@ class VirtualMachineDriver < OpenNebulaDriver :deleted => 'd', :unknown => '-' } - + HOST_ARG = 1 # ------------------------------------------------------------------------- @@ -67,7 +67,7 @@ class VirtualMachineDriver < OpenNebulaDriver # ------------------------------------------------------------------------- def initialize(concurrency=10, threaded=true) super(concurrency,threaded) - + @hosts = Array.new register_action(ACTION[:deploy].to_sym, method("deploy")) @@ -107,18 +107,23 @@ 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) + info = "-" if info == nil || info.empty? + + send_message(ACTION[action],RESULT[result],id,info) end - + # ------------------------------------------------------------------------- # Execute a command associated to an action and id on localhost # ------------------------------------------------------------------------- @@ -127,10 +132,14 @@ class VirtualMachineDriver < OpenNebulaDriver if command_exe.code == 0 result = :success + info = command_exe.stdout else result = :failure + info = command_exe.stderr end + info = "-" if info == nil || info.empty? + send_message(ACTION[action],RESULT[result],id) end @@ -171,7 +180,7 @@ class VirtualMachineDriver < OpenNebulaDriver error = "Action not implemented by driver #{self.class}" send_message(ACTION[:poll],RESULT[:failure],id,error) end - + private def delete_running_action(action_id) @@ -181,7 +190,7 @@ private @action_running.delete(action_id) end end - + def get_first_runable action_index=nil @action_queue.each_with_index do |action, index| @@ -195,32 +204,32 @@ private break end end - + return action_index end - + def get_runable_action action_index=get_first_runable - + if action_index action=@action_queue[action_index] else action=nil end - + if action @hosts << action[:args][HOST_ARG] if action[:args][HOST_ARG] @action_queue.delete_at(action_index) end - + STDERR.puts "action: #{action.inspect}" STDERR.puts "queue: #{@action_queue.inspect}" STDERR.puts "hosts: #{@hosts.inspect}" STDERR.flush - + return action end - + def empty_queue get_first_runable==nil end diff --git a/src/vmm_mad/ssh/one_vmm_ssh.rb b/src/vmm_mad/ssh/one_vmm_ssh.rb index 014eda5090..d7745063fe 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, domain) 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