1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-12 09:17:41 +03:00

feature #863: refactored do_action

This commit is contained in:
Javi Fontan 2011-11-21 16:43:08 +01:00
parent 80efad700b
commit d4508e54a7
3 changed files with 39 additions and 34 deletions

View File

@ -111,7 +111,8 @@ class AuthDriver < OpenNebulaDriver
command = File.join(authN_path,ACTION[:authN].downcase)
command << ' ' << user << ' ' << password << ' ' << secret
local_action(command, request_id, ACTION[:authN])
do_action(command, request_id, nil, ACTION[:authN],
:local => true)
end
# Authenticate a user based in a string of the form user:secret when using the
@ -141,7 +142,8 @@ class AuthDriver < OpenNebulaDriver
command = @authZ_cmd.clone
command << ' ' << user_id << ' ' << requests.join(' ')
local_action(command, request_id, ACTION[:authZ])
do_action(command, request_id, nil, ACTION[:authZ],
:local => true)
end
end
end

View File

@ -69,19 +69,23 @@ class ImageDriver < OpenNebulaDriver
# Image Manager Protocol Actions (generic implementation
def mv(id, src, dst)
local_action("#{@actions_path}/mv #{src} #{dst} #{id}",id,ACTION[:mv])
do_action("#{@actions_path}/mv #{src} #{dst} #{id}", id, nil,
ACTION[:mv], :local => true)
end
def cp(id, src)
local_action("#{@actions_path}/cp #{src} #{id}",id,ACTION[:cp])
do_action("#{@actions_path}/cp #{src} #{id}", id, nil, ACTION[:cp],
:local => true)
end
def rm(id, dst)
local_action("#{@actions_path}/rm #{dst} #{id}",id,ACTION[:rm])
do_action("#{@actions_path}/rm #{dst} #{id}", id, nil, ACTION[:rm],
:local => true)
end
def mkfs(id, fs, size)
local_action("#{@actions_path}/mkfs #{fs} #{size} #{id}",id,ACTION[:mkfs])
do_action("#{@actions_path}/mkfs #{fs} #{size} #{id}", id, nil,
ACTION[:mkfs], :local => true)
end
end

View File

@ -141,21 +141,43 @@ class OpenNebulaDriver < ActionManager
def do_action(parameters, id, host, aname, ops={})
options={
:stdin => nil,
:script_name => nil
:script_name => nil,
:respond => true
}.merge(ops)
params=parameters+" #{id} #{host}"
command=action_command_line(aname, params, options[:script_name])
if action_is_local? aname
local_action(command, id, aname)
if ops[:local] || action_is_local? aname
execution=local_action(command, id, aname)
else
remotes_action(command, id, host, aname, @remote_scripts_base_path,
options[:stdin])
execution=remotes_action(command, id, host, aname,
@remote_scripts_base_path, options[:stdin])
end
if ops[:respond]
send_message_from_execution(aname, id, execution)
else
execution
end
end
def send_message_from_execution(aname, id, command_exe)
if command_exe.code == 0
result = RESULT[:success]
info = command_exe.stdout
else
result = RESULT[:failure]
info = command_exe.get_error_message
end
info = "-" if info == nil || info.empty?
send_message(aname,result,id,info)
end
# Given the action name and the parameter returns full path of the script
# and appends its parameters. It uses @local_actions hash to know if the
# actions is remote or local. If the local actions has defined an special
@ -213,17 +235,6 @@ class OpenNebulaDriver < ActionManager
log_method(id),
std_in,
@retries)
if command_exe.code == 0
result = RESULT[:success]
info = command_exe.stdout
else
result = RESULT[:failure]
info = command_exe.get_error_message
end
info = "-" if info == nil || info.empty?
send_message(aname,result,id,info)
end
# Execute a command associated to an action and id on localhost
@ -233,18 +244,6 @@ class OpenNebulaDriver < ActionManager
# @param [String, Symbol] aname name of the action
def local_action(command, id, aname)
command_exe = LocalCommand.run(command, log_method(id))
if command_exe.code == 0
result = RESULT[:success]
info = command_exe.stdout
else
result = RESULT[:failure]
info = command_exe.get_error_message
end
info = "-" if info == nil || info.empty?
send_message(aname,result,id,info)
end
# Sends a log message to ONE. The +message+ can be multiline, it will