1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

M #-: print provision CMD and options (#702)

This commit is contained in:
Alejandro Huertas Herrero 2021-01-25 11:43:49 +01:00 committed by GitHub
parent 6abf26dd1b
commit aea18de8b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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