diff --git a/src/mad/ruby/one_mad.rb b/src/mad/ruby/one_mad.rb index 71022ce3ca..edf472462c 100755 --- a/src/mad/ruby/one_mad.rb +++ b/src/mad/ruby/one_mad.rb @@ -145,5 +145,29 @@ class ONEMad def action_finalize(args) exit(0) end + + # Functions for VM deployment + # TODO: Move elsewhere + def get_local_deployment_file(remote_deployment_file) + local_deployment_file=nil + + one_location=ENV["ONE_LOCATION"] + m=remote_deployment_file.match(/.*?\/(\d+)\/images\/(deployment.\d+)$/) + local_deployment_file="#{one_location}/var/#{m[1]}/#{m[2]}" if m + + return local_deployment_file + end + + def execute_local_command(cmd_string) + command=SSHCommand.new(cmd_string) + stdout, stderr=command.exec_local_command(cmd_string) + exit_code=command.get_exit_code(stderr) + if exit_code!=0 + return stderr + else + nil + end + end + end diff --git a/src/mad/ruby/one_ssh.rb b/src/mad/ruby/one_ssh.rb index dd29152a63..b7246b799b 100644 --- a/src/mad/ruby/one_ssh.rb +++ b/src/mad/ruby/one_ssh.rb @@ -37,7 +37,7 @@ class SSHCommand end end - private + #private # Gets exit code from STDERR def get_exit_code(str) diff --git a/src/vmm_mad/xen/one_vmm_xen.rb b/src/vmm_mad/xen/one_vmm_xen.rb index c17fffa9b4..aec09425e0 100755 --- a/src/vmm_mad/xen/one_vmm_xen.rb +++ b/src/vmm_mad/xen/one_vmm_xen.rb @@ -36,26 +36,32 @@ class DM < ONEMad def action_init(args) send_message("INIT", "SUCCESS") end - + def action_deploy(args) action_number=args[1] action_host=args[2] + remote_deployment_file=args[3] # Get local deployment file - one_location=ENV["ONE_LOCATION"] - m=args[3].match(/.*?\/(\d+)\/images\/(deployment.\d+)$/) + local_deployment_file=get_local_deployment_file(remote_deployment_file) # If matched the we can read the file and get more configuration values - if m - local_deployment_file="#{one_location}/var/#{m[1]}/#{m[2]}" - + if local_deployment_file # TODO: review this way of copying files # This command copies deployment file to remote machine # when shared directories are not used - copy_deploy="scp #{local_deployment_file} #{args[2]}:#{args[3]}" - copy_deploy_exit=system(copy_deploy) + copy_deploy="scp #{local_deployment_file} "+ + "#{action_host}:#{remote_deployment_file}" mad_log("DEPLOY", action_number, "Command: #{copy_deploy}") - mad_log("DEPLOY", action_number, "Command finalized: "+copy_deploy_exit.to_s) + copy_deploy_exit=execute_local_command(copy_deploy) + + if copy_deploy_exit + mad_log("DEPLOY", action_number, + "Error: "+copy_deploy_exit.to_s) + else + mad_log("DEPLOY", action_number, + "Copy success") + end # TODO: check for error