1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #863: Moved Log methods to base driver module

This commit is contained in:
Ruben S. Montero 2011-11-22 12:19:26 +01:00
parent 7d89b719a5
commit 0143a6d520
2 changed files with 58 additions and 49 deletions

View File

@ -42,7 +42,10 @@ module DriverExecHelper
@remote_scripts_path = File.join(@remote_scripts_base_path, directory)
@local_scripts_path = File.join(@local_scripts_base_path, directory)
end
#
# METHODS FOR COMMAND LINE & ACTION PATHS
#
# 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
@ -85,6 +88,55 @@ module DriverExecHelper
end
end
#
# METHODS FOR LOGS & COMMAND OUTPUT
#
# Sends a log message to ONE. The +message+ can be multiline, it will
# be automatically splitted by lines.
def log(number, message)
in_error_message=false
msg=message.strip
msg.each_line {|line|
severity='I'
l=line.strip
if l=='ERROR MESSAGE --8<------'
in_error_message=true
next
elsif l=='ERROR MESSAGE ------>8--'
in_error_message=false
next
else
if in_error_message
severity='E'
elsif line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
line=$2
case $1
when 'ERROR'
severity='E'
when 'DEBUG'
severity='D'
when 'INFO'
severity='I'
else
severity='I'
end
end
end
send_message("LOG", severity, number, line.strip)
}
end
# Generates a proc with that calls log with a hardcoded number. It will
# be used to add loging to command actions
def log_method(num)
lambda {|message|
log(num, message)
}
end
#This method returns the result in terms
def get_info_from_execution(command_exe)
if command_exe.code == 0
@ -100,6 +152,8 @@ module DriverExecHelper
[result, info]
end
#
#
# Simple parser for the config file generated by OpenNebula
def read_configuration
one_config=nil

View File

@ -88,6 +88,7 @@ class OpenNebulaDriver < ActionManager
# @option ops [String] :stdin text to be writen to stdin
# @option ops [String] :script_name default script name for the action,
# action name is used by defaults
# @option ops [String] :respond if defined will send result to ONE core
def do_action(parameters, id, host, aname, ops={})
options={
:stdin => nil,
@ -95,9 +96,9 @@ class OpenNebulaDriver < ActionManager
:respond => true
}.merge(ops)
params=parameters+" #{id} #{host}"
params = parameters+" #{id} #{host}"
command=action_command_line(aname, params, options[:script_name])
command = action_command_line(aname, params, options[:script_name])
if ops[:local] || action_is_local? aname
execution = LocalCommand.run(command, log_method(id))
@ -119,52 +120,6 @@ class OpenNebulaDriver < ActionManager
[result, info]
end
# Sends a log message to ONE. The +message+ can be multiline, it will
# be automatically splitted by lines.
def log(number, message)
in_error_message=false
msg=message.strip
msg.each_line {|line|
severity='I'
l=line.strip
if l=='ERROR MESSAGE --8<------'
in_error_message=true
next
elsif l=='ERROR MESSAGE ------>8--'
in_error_message=false
next
else
if in_error_message
severity='E'
elsif line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
line=$2
case $1
when 'ERROR'
severity='E'
when 'DEBUG'
severity='D'
when 'INFO'
severity='I'
else
severity='I'
end
end
end
send_message("LOG", severity, number, line.strip)
}
end
# Generates a proc with that calls log with a hardcoded number. It will
# be used to add loging to command actions
def log_method(num)
lambda {|message|
log(num, message)
}
end
# Start the driver. Reads from STDIN and executes methods associated with
# the messages
def start_driver