From 011e66b64ea6d60faedff0f6ab98342a75081a4b Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Herrero Date: Mon, 27 Apr 2020 19:38:30 +0200 Subject: [PATCH] F #2152: add option to forward in vmm exec (#4609) Co-authored-by: Vlastimil Holer --- share/etc/oned.conf | 6 ++++++ src/mad/ruby/ssh_stream.rb | 19 ++++++++++++++++++- src/vmm_mad/exec/one_vmm_exec.rb | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 0444c6fb61..99f3810c13 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -429,6 +429,8 @@ IM_MAD = [ # overridden for each action. # Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll # An example: "-l migrate=migrate_local,save" +# -d comma separated list of actions which forward SSH agent +# from frontend to remote host (default migrate) # -p more than one action per host in parallel, needs support from hypervisor # -s to execute remote commands, bash by default # -w Timeout in seconds to execute external commands (default unlimited) @@ -459,6 +461,8 @@ VM_MAD = [ # overridden for each action. # Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll # An example: "-l migrate=migrate_local,save" +# -d comma separated list of actions which forward SSH agent +# from frontend to remote host (default migrate) # -p more than one action per host in parallel, needs support from hypervisor # -s to execute remote commands, bash by default # -w Timeout in seconds to execute external commands (default unlimited) @@ -485,6 +489,8 @@ VM_MAD = [ # overridden for each action. # Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll # An example: "-l migrate=migrate_local,save" +# -d comma separated list of actions which forward SSH agent +# from frontend to remote host (default migrate) # -p more than one action per host in parallel, needs support from hypervisor # -s to execute remote commands, bash by default # -w Timeout in seconds to execute external commands (default unlimited) diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index 4473eb7267..496e4793d6 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -22,6 +22,8 @@ class SshStream attr_reader :stream_out, :stream_err, :stdin attr_reader :out, :err + attr_accessor :forward + # # EOF_ERR = "EOF_ERR" @@ -38,6 +40,7 @@ class SshStream @host = host @shell = shell @timeout = timeout + @forward = false end def opened? @@ -50,7 +53,7 @@ class SshStream def open @stdin, @stdout, @stderr, @wait_thr = Open3::popen3( - "#{SSH_CMD} #{@host} #{@shell} -s ; echo #{SSH_RC_STR} $? 1>&2", + "#{ssh_cmd} #{@host} #{@shell} -s ; echo #{SSH_RC_STR} $? 1>&2", :pgroup => true ) @@ -181,6 +184,16 @@ class SshStream exec(command) wait_for_command end + + private + + def ssh_cmd + if @forward + SSH_CMD + ' -o ForwardAgent=yes' + else + SSH_CMD + end + end end @@ -227,6 +240,10 @@ class SshStreamCommand < RemotesCommand def close @stream.close end + + def set_forward(forward) + @stream.forward = forward + end end diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index aee5ff3e97..b3e450be0c 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -68,6 +68,9 @@ class VmmAction @data = {} + # Check if SSH Forward Agent should be activated + forward = @vmm.options[:delegate_actions].key?(action.to_s.upcase) + get_data(:host) get_data(:deploy_id) get_data(:checkpoint_file) @@ -91,6 +94,10 @@ class VmmAction # Initialize streams and vnm @ssh_src = @vmm.get_ssh_stream(action, @data[:host], @id) + + # Activate SSH Forward Agent + @ssh_src.set_forward(forward) + @vnm_src = VirtualNetworkDriver.new(src_drvs, :local_actions => @vmm.options[:local_actions], :message => src_xml.to_s, @@ -100,6 +107,10 @@ class VmmAction dst_drvs, dst_xml = get_vnm_drivers(vm_template) @ssh_dst = @vmm.get_ssh_stream(action, @data[:dest_host], @id) + + # Activate SSH Forward Agent + @ssh_dst.set_forward(forward) + @vnm_dst = VirtualNetworkDriver.new(dst_drvs, :local_actions => @vmm.options[:local_actions], :message => dst_xml.to_s, @@ -1284,6 +1295,7 @@ opts = GetoptLong.new( ['--retries', '-r', GetoptLong::OPTIONAL_ARGUMENT], ['--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT], ['--local', '-l', GetoptLong::REQUIRED_ARGUMENT], + ['--delegate', '-d', GetoptLong::REQUIRED_ARGUMENT], ['--shell', '-s', GetoptLong::REQUIRED_ARGUMENT], ['--parallel', '-p', GetoptLong::NO_ARGUMENT], ['--timeout', '-w', GetoptLong::OPTIONAL_ARGUMENT] @@ -1294,6 +1306,7 @@ retries = 0 threads = 15 shell = 'bash' local_actions = {} +delegate_actions = OpenNebulaDriver.parse_actions_list('migrate') single_host = true timeout = nil @@ -1306,6 +1319,8 @@ begin threads = arg.to_i when '--local' local_actions = OpenNebulaDriver.parse_actions_list(arg) + when '--delegate' + delegate_actions = OpenNebulaDriver.parse_actions_list(arg) when '--shell' shell = arg when '--parallel' @@ -1328,6 +1343,7 @@ exec_driver = ExecDriver.new(hypervisor, :concurrency => threads, :retries => retries, :local_actions => local_actions, + :delegate_actions => delegate_actions, :shell => shell, :single_host => single_host, :timeout => timeout)