diff --git a/src/cli/one_helper/oneprovision_helper.rb b/src/cli/one_helper/oneprovision_helper.rb index 9c528c1722..162bc510c6 100644 --- a/src/cli/one_helper/oneprovision_helper.rb +++ b/src/cli/one_helper/oneprovision_helper.rb @@ -489,6 +489,9 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper def resources_operation(args, operation, options, type) parse_options(options) + OneProvision::Utils.print_cmd("#{type} #{operation[:operation]}", + options) + objects = names_to_ids(args[0], type) return [-1, objects.message] if OpenNebula.is_error?(objects) @@ -498,7 +501,7 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper operation[:message]) do |obj| rc = obj.info - return rc if OpenNebula.is_error?(rc) + return [-1, rc.message] if OpenNebula.is_error?(rc) case type when 'HOSTS' @@ -515,14 +518,14 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper end unless p_id - return OpenNebula::Error.new('No provision ID found') + return [-1, 'No provision ID found'] end provision = OneProvision::Provision.new_with_id(p_id, @client) rc = provision.info - return rc if OpenNebula.is_error?(rc) + return [-1, rc.message] if OpenNebula.is_error?(rc) provision.update_objects(type.downcase, :remove, obj['ID']) end diff --git a/src/cli/oneprovision b/src/cli/oneprovision index e9047a74fa..38df95cbef 100755 --- a/src/cli/oneprovision +++ b/src/cli/oneprovision @@ -99,6 +99,8 @@ CommandParser::CmdParser.new(ARGV) do :options => OneProvisionHelper::CREATE_OPTIONS do helper.parse_options(options) + OneProvision::Utils.print_cmd('create', options) + if options[:cleanup_timeout].nil? timeout = 20 else @@ -191,6 +193,8 @@ CommandParser::CmdParser.new(ARGV) do [OpenNebulaHelper::FORMAT] do helper.parse_options(options) + OneProvision::Utils.print_cmd('configure', options) + rc = helper.configure(args[0], options.key?(:force)) if OpenNebula.is_error?(rc) @@ -217,6 +221,8 @@ CommandParser::CmdParser.new(ARGV) do [OpenNebulaHelper::FORMAT] do helper.parse_options(options) + OneProvision::Utils.print_cmd('delete', options) + if options[:cleanup_timeout].nil? timeout = 20 else @@ -354,14 +360,18 @@ CommandParser::CmdParser.new(ARGV) do :options => [OneProvisionHelper::MODES, OneProvisionHelper::FORCE] do rc = helper.resources_operation(args, - {}, + { :operation => 'delete' }, options, resource.upcase) - return 0 if rc[0] == 0 - - STDERR.puts rc[1] - exit(-1) + if rc.is_a?(Array) && rc[0] == 0 + 0 + elsif rc.is_a?(Array) + STDERR.puts rc[1] + exit(-1) + else + 0 + end end end end diff --git a/src/oneprovision/lib/provision/provision.rb b/src/oneprovision/lib/provision/provision.rb index 1e9b4eefa5..1a1de7a0f8 100644 --- a/src/oneprovision/lib/provision/provision.rb +++ b/src/oneprovision/lib/provision/provision.rb @@ -424,7 +424,7 @@ module OneProvision def update_objects(object, operation, id, name = nil) rc = info - return rc if OpenNebula.is_error?(rc) + return [-1, rc.message] if OpenNebula.is_error?(rc) if FULL_CLUSTER.include?(object) path = 'infrastructure' @@ -438,11 +438,11 @@ module OneProvision o = Resource.object(object, provider) rc = o.info(id) - return rc if OpenNebula.is_error?(rc) + return [-1, rc.message] if OpenNebula.is_error?(rc) rc = o.delete(FULL_CLUSTER.include?(object) ? tf : nil) - return rc if OpenNebula.is_error?(rc) + return [-1, rc.message] if OpenNebula.is_error?(rc) # If it is an array, a host has been deleted if rc.is_a? Array @@ -455,7 +455,11 @@ module OneProvision end end - update + rc = update + + [-1, rc.message] if OpenNebula.is_error?(rc) + + 0 end # Reads provider name from template diff --git a/src/oneprovision/lib/provision/utils.rb b/src/oneprovision/lib/provision/utils.rb index 2098aac971..0d55c58bf6 100644 --- a/src/oneprovision/lib/provision/utils.rb +++ b/src/oneprovision/lib/provision/utils.rb @@ -49,6 +49,27 @@ module OneProvision ERROR_OPEN = 'ERROR MESSAGE --8<------' ERROR_CLOSE = 'ERROR MESSAGE ------>8--' + # Prints command and options in the debug output + # + # @param cmd [String] Command executed + # @param options [Hash] Command optioms + def print_cmd(cmd, options) + cmd_options = [] + + options.each do |key, value| + if value + cmd_options << "[#{key}, #{value}]" + else + cmd_options << key + end + end + + cmd_options = cmd_options.join(' ') + + OneProvisionLogger.debug("Executing command: `#{cmd}`") + OneProvisionLogger.debug("Command options: #{cmd_options}") + end + # Checks if the file can be read # # @param name [String] Path to file to read