mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
Adding logging facilities to command execution
git-svn-id: http://svn.opennebula.org/one/trunk@345 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
6119f446b6
commit
62e25f09de
@ -11,20 +11,35 @@ class GenericCommand
|
||||
|
||||
# Creates the new command:
|
||||
# +command+: string with the command to be executed
|
||||
def initialize(command)
|
||||
def initialize(command, logger=nil)
|
||||
@command=command
|
||||
@logger=logger
|
||||
@callback=nil
|
||||
end
|
||||
|
||||
def log(message)
|
||||
@logger.call(message) if @logger
|
||||
end
|
||||
|
||||
# Runs the command and calls the callback if it is defined
|
||||
# +data+: variable to pass to the callaback to provide data
|
||||
# or to share with other callbacks
|
||||
def run(data=nil)
|
||||
|
||||
log("About to execute #{command}")
|
||||
|
||||
(@stdout, @stderr)=execute
|
||||
@code=get_exit_code(@stderr)
|
||||
|
||||
log("Command executed, exit code: #{@code}")
|
||||
|
||||
@callback.call(self, data) if @callback
|
||||
|
||||
if @code!=0
|
||||
log("Command execution fail. STDERR follows.")
|
||||
log(@stderr)
|
||||
end
|
||||
|
||||
return @code
|
||||
end
|
||||
|
||||
@ -75,9 +90,9 @@ class SSHCommand < GenericCommand
|
||||
|
||||
# This one takes another parameter. +host+ is the machine
|
||||
# where de command is going to be executed
|
||||
def initialize(command, host)
|
||||
def initialize(command, host, logger=nil)
|
||||
@host=host
|
||||
super(command)
|
||||
super(command, logger)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -57,7 +57,17 @@ class OpenNebulaDriver < ActionManager
|
||||
send_message("LOG", "-", 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
|
||||
loop_thread = Thread.new { loop }
|
||||
start_listener
|
||||
|
Loading…
x
Reference in New Issue
Block a user