mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Add RemotesCommand to check remote files existence in worker nodes
This commit is contained in:
parent
c2d7ca16cd
commit
ffce3651c0
@ -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)
|
||||
|
@ -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__
|
||||
|
||||
|
@ -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
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user