diff --git a/src/mad/ruby/CommandManager.rb b/src/mad/ruby/CommandManager.rb index d135217c50..5339533ffb 100644 --- a/src/mad/ruby/CommandManager.rb +++ b/src/mad/ruby/CommandManager.rb @@ -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 diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index df04bf4259..5427e4682c 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -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