1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-22 17:57:46 +03:00

feature #575: added scripts_common for ruby

This commit is contained in:
Javi Fontan 2011-05-10 16:08:05 +02:00
parent 79ca4ce570
commit 3f0b0b75e8
2 changed files with 75 additions and 1 deletions

View File

@ -258,6 +258,9 @@ INSTALL_FILES=(
LIB_FILES:$LIB_LOCATION
RUBY_LIB_FILES:$LIB_LOCATION/ruby
RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula
MAD_RUBY_LIB_FILES:$LIB_LOCATION/ruby
MAD_RUBY_LIB_FILES:$LIB_LOCATION/remotes
MAD_RUBY_LIB_FILES:$VAR_LOCATION/remotes
MAD_SH_LIB_FILES:$LIB_LOCATION/sh
MAD_SH_LIB_FILES:$LIB_LOCATION/remotes
MAD_SH_LIB_FILES:$VAR_LOCATION/remotes
@ -415,11 +418,12 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \
#-----------------------------------------------------------------------------
# MAD ShellScript library files, to be installed under $LIB_LOCATION/sh
# MAD Script library files, to be installed under $LIB_LOCATION/<script lang>
# and remotes directory
#-----------------------------------------------------------------------------
MAD_SH_LIB_FILES="src/mad/sh/scripts_common.sh"
MAD_RUBY_LIB_FILES="src/mad/ruby/scripts_common.rb"
#-------------------------------------------------------------------------------
# Driver executable files, to be installed under $LIB_LOCATION/mads

View File

@ -0,0 +1,70 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
module OpenNebula
# Generic log function
def self.log_function(severity, message)
STDERR.puts "#{severity}: #{File.basename $0}: #{message}"
end
# Logs an info message
def self.log_info(message)
log_function("INFO", message)
end
# Logs an error message
def self.log_error(message)
log_function("ERROR", message)
end
# Logs a debug message
def self.log_debug(message)
log_function("DEBUG", message)
end
# Alias log to log_info in the singleton class
class << self
alias :log :log_info
end
# This function is used to pass error message to the mad
def self.error_message(message)
STDERR.puts "ERROR MESSAGE --8<------"
STDERR.puts message
STDERR.puts "ERROR MESSAGE ------>8--"
end
# Executes a command, if it fails returns error message and exits
# If a second parameter is present it is used as the error message when
# the command fails
def self.exec_and_log(command, message=nil)
output=`#{command} 2>&1 1>/dev/null`
code=$?
if code!=0
log_error "Command \"#{command}\" failed."
log_error output
if !message
error_message output
else
error_message message
end
exit code
end
log "Executed \"#{command}\"."
end
end