From 13391ab282583e764e6a6d341a4804f7222de5d0 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 6 Nov 2012 15:30:58 +0100 Subject: [PATCH 01/26] bug #1641: Bug detecting an object from parameters (network or disk) --- src/cli/one_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 786fea1756..87ed26ce55 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -557,7 +557,7 @@ EOT template<<"#{section.upcase}=[\n" template<<" #{name.upcase}_UNAME=\"#{user}\",\n" if user - if object.match(/^\d$/) + if object.match(/^\d+$/) template<<" #{name.upcase}_ID=#{object}\n" else template<<" #{name.upcase}=\"#{object}\"\n" From 0cee3d65c8df5e322a2b884b90a08ed2cf0f893d Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 6 Nov 2012 15:43:29 +0100 Subject: [PATCH 02/26] feature #1642: Add --dry option to onevm and onetemplate create --- src/cli/one_helper.rb | 5 +++++ src/cli/onetemplate | 7 ++++++- src/cli/onevm | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 87ed26ce55..9797452543 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -132,6 +132,11 @@ EOT :large => '--raw string', :description => 'Raw string to add to the template. Not to be confused with the RAW attribute', :format => String + }, + { + :name => 'dry', + :large => '--dry', + :description => 'Just print the template' } ] diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 462613b616..e1c6904359 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -121,7 +121,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do template = res.last end - tmpl.allocate(template) + if options[:dry] + puts template + exit 0 + else + tmpl.allocate(template) + end rescue => e STDERR.puts e.messsage exit -1 diff --git a/src/cli/onevm b/src/cli/onevm index 9d612629d3..b5df5cd319 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -139,6 +139,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do template = res.last end + + if options[:dry] + puts template + exit 0 + end rescue Exception => e STDERR.puts "Error reading template." next -1 From 32f66f59b831fabac3a55a042fcfe105a6c04ae7 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 6 Nov 2012 15:45:24 +0100 Subject: [PATCH 03/26] feature #1642: Add --vnc option to template creation --- src/cli/one_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 9797452543..3507acefb2 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -133,6 +133,11 @@ EOT :description => 'Raw string to add to the template. Not to be confused with the RAW attribute', :format => String }, + { + :name => 'vnc', + :large => '--vnc', + :description => 'Add VNC server to the VM' + }, { :name => 'dry', :large => '--dry', @@ -596,6 +601,9 @@ EOT template< Date: Tue, 6 Nov 2012 15:51:00 +0100 Subject: [PATCH 04/26] feature #1642: Add ssh and network contextualization options --- src/cli/one_helper.rb | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 3507acefb2..c11a107814 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -138,6 +138,24 @@ EOT :large => '--vnc', :description => 'Add VNC server to the VM' }, + { + :name => 'ssh', + :large => '--ssh [key]', + :description => 'Add an ssh public key to the context', + :format => String, + :proc => lambda do |o, options| + if !o + [0, true] + else + [0, o] + end + end + }, + { + :name => 'net_context', + :large => '--net_context', + :description => 'Add network contextualization parameters' + }, { :name => 'dry', :large => '--dry', @@ -578,6 +596,38 @@ EOT [0, template] end + def self.create_context(options) + if !(options.keys & [:ssh]).empty? + lines=[] + + if options[:ssh] + if options[:ssh]==true + lines<<"SSH_PUBLIC_KEY=\"$USER[SSH_PUBLIC_KEY]\"" + else + lines<<"SSH_PUBLIC_KEY=\"#{options[:ssh]}\"" + end + end + + if options[:net_context] && options[:network] + nets=options[:network] + nets.each_with_index do |str, index| + net=parse_user_object(str) + name=net.last + + lines<<"ETH#{index}_IP = \"$NIC[IP, NETWORK=\\\"#{name}\\\"]\"" + lines<<"ETH#{index}_NETWORK = \"$NETWORK[NETWORK_ADDRESS, NETWORK=\\\"#{name}\\\"]\"" + lines<<"ETH#{index}_MASK = \"$NETWORK[NETWORK_MASK, NETWORK=\\\"#{name}\\\"]\"" + lines<<"ETH#{index}_GATEWAY = \"$NETWORK[GATEWAY, NETWORK=\\\"#{name}\\\"]\"" + lines<<"ETH#{index}_DNS = \"$NETWORK[DNS, NETWORK=\\\"#{name}\\\"]\"" + end + end + + "CONTEXT=[\n"< Date: Wed, 7 Nov 2012 16:22:42 +0100 Subject: [PATCH 05/26] feature #1642: bugs adding context --- src/cli/one_helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index c11a107814..a7668a0ff5 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -597,7 +597,7 @@ EOT end def self.create_context(options) - if !(options.keys & [:ssh]).empty? + if !(options.keys & [:ssh, :net_context]).empty? lines=[] if options[:ssh] @@ -622,7 +622,11 @@ EOT end end - "CONTEXT=[\n"< Date: Wed, 7 Nov 2012 16:23:36 +0100 Subject: [PATCH 06/26] feature #1642: bug with --dry option on onevm --- src/cli/onevm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cli/onevm b/src/cli/onevm index b5df5cd319..d1bf271973 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -140,15 +140,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do template = res.last end - if options[:dry] - puts template - exit 0 - end rescue Exception => e STDERR.puts "Error reading template." next -1 end + if options[:dry] + puts template + exit 0 + end + number.times do exit_code = helper.create_resource(options) do |vm| error = vm.allocate(template) From bc86858083d2eccab6d7eeb99b57c0f24222c288 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 7 Nov 2012 16:58:02 +0100 Subject: [PATCH 07/26] feature #1642: do not let context be created for vm's with repeated net names --- src/cli/one_helper.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index a7668a0ff5..2828740c83 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -609,11 +609,16 @@ EOT end if options[:net_context] && options[:network] - nets=options[:network] - nets.each_with_index do |str, index| - net=parse_user_object(str) - name=net.last + nets=options[:network].map {|n| parse_user_object(n).last } + if nets!=nets.uniq + STDERR.puts "Network context generation from command "<< + "line is not supported for VMs with\n"<< + "more than one network with the same name." + exit(-1) + end + + nets.each_with_index do |name, index| lines<<"ETH#{index}_IP = \"$NIC[IP, NETWORK=\\\"#{name}\\\"]\"" lines<<"ETH#{index}_NETWORK = \"$NETWORK[NETWORK_ADDRESS, NETWORK=\\\"#{name}\\\"]\"" lines<<"ETH#{index}_MASK = \"$NETWORK[NETWORK_MASK, NETWORK=\\\"#{name}\\\"]\"" From 19a8422dd16b7092004c64a34c539ef355d41c35 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 12 Nov 2012 17:34:27 +0100 Subject: [PATCH 08/26] feature #1642: now --ssh uses a file as input --- src/cli/one_helper.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 2828740c83..f3a80f5239 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -140,8 +140,10 @@ EOT }, { :name => 'ssh', - :large => '--ssh [key]', - :description => 'Add an ssh public key to the context', + :large => '--ssh [file]', + :description => "Add an ssh public key to the context. If the \n"<< + (' '*31)<<"file is omited then the user variable \n"<< + (' '*31)<<"SSH_PUBLIC_KEY will be used.", :format => String, :proc => lambda do |o, options| if !o @@ -604,7 +606,13 @@ EOT if options[:ssh]==true lines<<"SSH_PUBLIC_KEY=\"$USER[SSH_PUBLIC_KEY]\"" else - lines<<"SSH_PUBLIC_KEY=\"#{options[:ssh]}\"" + begin + key=File.read(options[:ssh]).strip + rescue Exception => e + STDERR.puts e.message + exit(-1) + end + lines<<"SSH_PUBLIC_KEY=\"#{key}\"" end end From 156ffa6cebe45f63473759bf3b5ee7bf452744c8 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 12 Nov 2012 17:37:46 +0100 Subject: [PATCH 09/26] feature #1650: support urls in oneimage --path --- src/cli/one_helper/oneimage_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 44bc84c3b5..83fa36edc1 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -76,7 +76,9 @@ class OneImageHelper < OpenNebulaHelper::OneHelper :description => "Path of the image file", :format => String, :proc => lambda do |o, options| - if o[0,1]=='/' + if o.match(/^https?:\/\//) + next [0, o] + elsif o[0,1]=='/' path=o else path=Dir.pwd+"/"+o From 6382b18bbd31a5d39d2585fdcde9ea42f9421b8d Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 13 Nov 2012 17:53:57 +0100 Subject: [PATCH 10/26] feature #1653: add --filter to list commands --- src/cli/cli_helper.rb | 58 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/src/cli/cli_helper.rb b/src/cli/cli_helper.rb index 570ffd1a24..f6f3460e31 100644 --- a/src/cli/cli_helper.rb +++ b/src/cli/cli_helper.rb @@ -31,13 +31,13 @@ module CLIHelper # :description => "Order by these columns, column starting with - means decreasing order" #} # - #FILTER = { - # :name => "filter", - # :short => "-f x,y,z", - # :large => "--filter x,y,z", - # :format => Array, - # :description => "Filter data. An array is specified with column=value pairs." - #} + FILTER = { + :name => "filter", + :short => "-f x,y,z", + :large => "--filter x,y,z", + :format => Array, + :description => "Filter data. An array is specified with column=value pairs." + } # #HEADER = { # :name => "header", @@ -55,7 +55,7 @@ module CLIHelper } #OPTIONS = [LIST, ORDER, FILTER, HEADER, DELAY] - OPTIONS = [LIST, DELAY] + OPTIONS = [LIST, DELAY, FILTER] # Sets bold font def CLIHelper.scr_bold @@ -287,7 +287,47 @@ module CLIHelper }.compact.join(' ') end - # TBD def filter_data! + def filter_data!(data, filter) + # TBD: add more operators + # operators=/(==|=|!=|<|<=|>|>=)/ + operators=/(=)/ + + stems=filter.map do |s| + m=s.match(/^(.*?)#{operators}(.*?)$/) + if m + left, operator, right=m[1..3] + index=@default_columns.index(left.to_sym) + + if index + { + :left => left, + :operator => operator, + :right => right, + :index => index + } + else + STDERR.puts "Column '#{left}' not found" + exit(-1) + end + else + STDERR.puts "Expresion '#{s}' incorrect" + exit(-1) + end + end + + data.reject! do |d| + pass=true + + stems.each do |s| + if d[s[:index]]!=s[:right] + pass=false + break + end + end + + !pass + end + end # TBD def sort_data! end From c3972b4f9ab9c829a1fce7ebadf1ea0352f52ee1 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 13 Nov 2012 18:15:46 +0100 Subject: [PATCH 11/26] feature #1640: show active VMs in onehost show --- src/cli/one_helper/onehost_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index a0bf424e70..a594c09633 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -15,6 +15,7 @@ #--------------------------------------------------------------------------- # require 'one_helper' +require 'one_helper/onevm_helper' class OneHostHelper < OpenNebulaHelper::OneHelper def self.rname @@ -192,5 +193,12 @@ class OneHostHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false) puts host.template_str + + puts + CLIHelper.print_header("VIRTUAL MACHINES", false) + puts + + onevm_helper=OneVMHelper.new + onevm_helper.list_pool({:filter=>["HOST=#{host.name}"]}, false) end end From ad9e86dca52a8405f240d231e4ac4c87a2880cb2 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 15 Nov 2012 16:14:30 +0100 Subject: [PATCH 12/26] feature #1642: add support for --context in vm creation --- src/cli/one_helper.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index f3a80f5239..e298a816b3 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -158,6 +158,12 @@ EOT :large => '--net_context', :description => 'Add network contextualization parameters' }, + { + :name => 'context', + :large => '--context line1,line2,line3', + :format => Array, + :description => 'Lines to add to the context section' + }, { :name => 'dry', :large => '--dry', @@ -599,7 +605,7 @@ EOT end def self.create_context(options) - if !(options.keys & [:ssh, :net_context]).empty? + if !(options.keys & [:ssh, :net_context, :context]).empty? lines=[] if options[:ssh] @@ -635,6 +641,8 @@ EOT end end + lines+=options[:context] + if !lines.empty? "CONTEXT=[\n"< Date: Thu, 15 Nov 2012 16:15:10 +0100 Subject: [PATCH 13/26] feature #1642: add support for --boot on vm creation --- src/cli/one_helper.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index e298a816b3..d382ffaf13 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -164,6 +164,12 @@ EOT :format => Array, :description => 'Lines to add to the context section' }, + { + :name => 'boot', + :large => '--boot device', + :description => 'Select boot device (hd|fd|cdrom|network)', + :format => String + }, { :name => 'dry', :large => '--dry', @@ -657,7 +663,19 @@ EOT template='' template<<"NAME=\"#{options[:name]}\"\n" if options[:name] - template<<"OS = [ ARCH = \"#{options[:arch]}\" ]\n" if options[:arch] + + if options[:arch] || options[:boot] + template<<"OS = [\n" + + lines=[] + lines<<" ARCH = \"#{options[:arch]}\"" if options[:arch] + lines<<" BOOT = \"#{options[:boot]}\"" if options[:boot] + + template< Date: Fri, 16 Nov 2012 16:40:08 +0100 Subject: [PATCH 14/26] feature #1570: execute a proc before each command call --- src/cli/command_parser.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index ab6c05e33b..879e19220c 100644 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -65,6 +65,8 @@ module CommandParser @args = args @options = Hash.new + @before_proc=nil + define_default_formats instance_eval(&block) @@ -97,6 +99,12 @@ module CommandParser @name = str end + # Defines a proc to be called before any command + # @param [Proc] block + def before_proc(&block) + @before_proc = block + end + # Defines a block that will be used to parse the arguments # of the command. Formats defined using this method con be used # in the arguments section of the command method, when defining a new @@ -413,6 +421,8 @@ module CommandParser parse(extra_options) if comm + @before_proc.call if @before_proc + check_args!(comm_name, comm[:arity], comm[:args_format]) rc = comm[:proc].call From cec5c8aa4148c1137712166071cef813f0931707 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 16 Nov 2012 16:41:49 +0100 Subject: [PATCH 15/26] feature #1570: execute argument procs after all the arguments are parsed --- src/cli/command_parser.rb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index 879e19220c..1bc3d8a661 100644 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -438,9 +438,12 @@ module CommandParser private def parse(extra_options) + with_proc=Array.new + @cmdparse=OptionParser.new do |opts| merge = @available_options merge = @available_options + extra_options if extra_options + merge.flatten.each do |e| args = [] args << e[:short] if e[:short] @@ -450,16 +453,8 @@ module CommandParser opts.on(*args) do |o| if e[:proc] - rc = e[:proc].call(o, @options) - if rc.instance_of?(Array) - if rc[0] == 0 - options[e[:name].to_sym] = rc[1] - else - puts rc[1] - puts "option #{e[:name]}: Parsing error" - exit -1 - end - end + @options[e[:name].to_sym]=o + with_proc< Date: Fri, 16 Nov 2012 16:42:57 +0100 Subject: [PATCH 16/26] feature #1570: add support for user, password and endpoint parameters --- src/cli/one_helper.rb | 87 +++++++++++++++++++++++++--- src/cli/one_helper/onehost_helper.rb | 1 + src/cli/oneacct | 4 +- src/cli/oneacl | 6 +- src/cli/onecluster | 6 +- src/cli/onedatastore | 6 +- src/cli/onegroup | 6 +- src/cli/onehost | 6 +- src/cli/oneimage | 6 +- src/cli/onetemplate | 6 +- src/cli/oneuser | 26 +++------ src/cli/onevm | 5 +- src/cli/onevnet | 6 +- 13 files changed, 133 insertions(+), 38 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index d382ffaf13..8312b40904 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -76,6 +76,27 @@ EOT :format => String } + CLIENT_OPTIONS=[ + { + :name => 'user', + :large => '--user name', + :description => 'User name used to connect to OpenNebula', + :format => String + }, + { + :name => 'password', + :large => '--password password', + :description => 'Password to authenticate with OpenNebula', + :format => String + }, + { + :name => 'endpoint', + :large => '--endpoint endpoing', + :description => 'URL of OpenNebula xmlrpc frontend', + :format => String + } + ] + TEMPLATE_OPTIONS=[ { :name => 'cpu', @@ -182,17 +203,67 @@ EOT OPTIONS = XML, NUMERIC, KILOBYTES class OneHelper - def initialize(secret=nil, endpoint=nil) - begin - @client = OpenNebula::Client.new(secret,endpoint) - rescue Exception => e - puts e.message - exit -1 + attr_accessor :client + + def self.get_client(options) + if defined?(@@client) + @@client + else + secret=nil + user=options[:user] + if user + password=options[:password]||self.get_password + secret="#{user}:#{password}" + end + + endpoint=options[:endpoint] + + @@client=OpenNebula::Client.new(secret, endpoint) end + end + + def self.client + if defined?(@@client) + @@client + else + self.get_client({}) + end + end + + if RUBY_VERSION>="1.9.3" + require 'io/console' + def self.get_password + print "Password: " + pass=nil + STDIN.noecho {|io| pass=io.gets } + puts + + pass.chop! if pass + pass + end + else + def self.get_password + print "Password: " + system("stty", "-echo") + begin + return gets.chop + ensure + system("stty", "echo") + print "\n" + end + end + end + + def initialize(secret=nil, endpoint=nil) + @client=nil @translation_hash = nil end + def set_client(options) + @client=OpenNebulaHelper::OneHelper.get_client(options) + end + def create_resource(options, &block) resource = factory @@ -411,7 +482,7 @@ EOT end def pool_to_array(pool) - if !pool.instance_of?(Hash) + if !pool.instance_of?(Hash) phash = pool.to_hash else phash = pool @@ -450,7 +521,7 @@ EOT def OpenNebulaHelper.rname_to_id(name, poolname) return 0, name.to_i if name.match(/^[0123456789]+$/) - client = OpenNebula::Client.new + client=OneHelper.client pool = case poolname when "HOST" then OpenNebula::HostPool.new(client) diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index a594c09633..e52c4a1704 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -199,6 +199,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper puts onevm_helper=OneVMHelper.new + onevm_helper.client=@client onevm_helper.list_pool({:filter=>["HOST=#{host.name}"]}, false) end end diff --git a/src/cli/oneacct b/src/cli/oneacct index 728984a53d..97a269c029 100755 --- a/src/cli/oneacct +++ b/src/cli/oneacct @@ -37,6 +37,7 @@ cmd = CommandParser::CmdParser.new(ARGV) do description "" version OpenNebulaHelper::ONE_VERSION + client = OpenNebulaHelper::OneHelper.get_client({}) option AcctHelper::ACCT_OPTIONS + CommandParser::OPTIONS @@ -53,10 +54,8 @@ cmd = CommandParser::CmdParser.new(ARGV) do :xpath => options[:xpath] } - client = OpenNebula::Client.new pool = OpenNebula::VirtualMachinePool.new(client) - if options[:json] || options[:xml] xml_str = pool.accounting_xml(filter_flag, common_opts) if OpenNebula.is_error?(xml_str) @@ -85,6 +84,7 @@ cmd = CommandParser::CmdParser.new(ARGV) do exit -1 end + if ( start_time != -1 or end_time != -1 ) AcctHelper.print_start_end_time_header(start_time, end_time) end diff --git a/src/cli/oneacl b/src/cli/oneacl index 7dc5281c2a..9ad216f9a5 100755 --- a/src/cli/oneacl +++ b/src/cli/oneacl @@ -36,10 +36,14 @@ cmd = CommandParser::CmdParser.new(ARGV) do helper = OneAclHelper.new + before_proc do + helper.set_client(options) + end + ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS ######################################################################## # Formatters for arguments diff --git a/src/cli/onecluster b/src/cli/onecluster index 9fc41c2e6b..0362d908bb 100755 --- a/src/cli/onecluster +++ b/src/cli/onecluster @@ -36,10 +36,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneClusterHelper.new + before_proc do + helper.set_client(options) + end + ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML diff --git a/src/cli/onedatastore b/src/cli/onedatastore index 550d015003..9f58d16f6c 100755 --- a/src/cli/onedatastore +++ b/src/cli/onedatastore @@ -37,10 +37,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneDatastoreHelper.new + before_proc do + helper.set_client(options) + end + ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML diff --git a/src/cli/onegroup b/src/cli/onegroup index bb191bc84d..6fc81e561e 100755 --- a/src/cli/onegroup +++ b/src/cli/onegroup @@ -36,10 +36,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneGroupHelper.new + before_proc do + helper.set_client(options) + end + ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML diff --git a/src/cli/onehost b/src/cli/onehost index d08a487223..364dfcaf61 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -37,10 +37,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneHostHelper.new + before_proc do + helper.set_client(options) + end + ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS IM = { :name => "im", diff --git a/src/cli/oneimage b/src/cli/oneimage index c63ca447c8..df71c6a568 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -37,10 +37,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneImageHelper.new + before_proc do + helper.set_client(options) + end + ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML diff --git a/src/cli/onetemplate b/src/cli/onetemplate index e1c6904359..af2da5f1cc 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -36,10 +36,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneTemplateHelper.new + before_proc do + helper.set_client(options) + end + ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML diff --git a/src/cli/oneuser b/src/cli/oneuser index 12600e0412..1c0dac8bbb 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -37,10 +37,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do usage "`oneuser` [] []" version OpenNebulaHelper::ONE_VERSION + helper = OneUserHelper.new + + before_proc do + helper.set_client(options) + end + ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML @@ -135,12 +141,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do end set :format, :userid, OneUserHelper.to_id_desc do |arg| - helper = OneUserHelper.new helper.to_id(arg) end set :format, :userid_list, OneUserHelper.list_to_id_desc do |arg| - helper = OneUserHelper.new helper.list_to_id(arg) end @@ -164,8 +168,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :create, create_desc, :username, [:password, nil], :options=>create_options do - helper = OneUserHelper.new - if args[1] pass = args[1] else @@ -190,8 +192,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :userid, [:file, nil] do - helper = OneUserHelper.new - helper.perform_action(args[0],options,"modified") do |user| str = OpenNebulaHelper.update_template(args[0], user, args[1]) user.update(str) @@ -204,8 +204,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :quota, quota_desc, :userid, [:file, nil] do - helper = OneUserHelper.new - helper.perform_action(args[0], options, "modified") do |user| str = OneQuotaHelper.set_quota(user, args[1]) rc = user.set_quota(str) @@ -224,8 +222,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :batchquota, batchquota_desc, [:range, :userid_list], [:file, nil] do - helper = OneUserHelper.new - batch_str = OneQuotaHelper.get_batch_quota(args[1]) helper.perform_actions(args[0], options, "modified") do |user| @@ -282,7 +278,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :delete, delete_desc, [:range, :userid_list] do - helper = OneUserHelper.new helper.perform_actions(args[0], options, "deleted") do |user| user.delete end @@ -294,8 +289,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :passwd, passwd_desc, :userid, [:password, nil], :options=>create_options do - helper = OneUserHelper.new - if args[1] pass = args[1] else @@ -317,7 +310,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :chgrp, chgrp_desc, [:range, :userid_list], :groupid do - helper = OneUserHelper.new helper.perform_actions(args[0],options,"Group changed") do |user| user.chgrp(args[1].to_i) end @@ -344,8 +336,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do exit_with_code 0, "An Auth driver should be specified" end - helper = OneUserHelper.new - if args[2] pass = args[2] else @@ -369,7 +359,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :list, list_desc, :options=>list_options do - helper = OneUserHelper.new helper.list_pool(options) end @@ -380,7 +369,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :show, show_desc, [:userid, nil], :options=>OpenNebulaHelper::XML do user=args[0] || OpenNebula::User::SELF - helper = OneUserHelper.new helper.show_resource(user,options) end diff --git a/src/cli/onevm b/src/cli/onevm index d1bf271973..0e1f3c15de 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -36,6 +36,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneVMHelper.new + before_proc do + helper.set_client(options) + end TYPE={ :name => "type", @@ -56,7 +59,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS ######################################################################## # Formatters for arguments diff --git a/src/cli/onevnet b/src/cli/onevnet index 7c28994113..12638fc2a8 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -37,10 +37,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneVNetHelper.new + before_proc do + helper.set_client(options) + end + ######################################################################## # Global Options ######################################################################## - set :option, CommandParser::OPTIONS + set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS CREATE_OPTIONS = [OneClusterHelper::CLUSTER] From b9d7067a1667ad3355432ca82fdf70c68798a93f Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 16 Nov 2012 17:10:02 +0100 Subject: [PATCH 17/26] feature #1570: nothice where the get_password function is copied from --- src/cli/one_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 8312b40904..4eb6f58aef 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -242,6 +242,7 @@ EOT pass end else + # This function is copied from ruby net/imap.rb def self.get_password print "Password: " system("stty", "-echo") From b3e9c1c10933eae4c3ba6d295bdd45ec782c5b13 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 16 Nov 2012 17:10:57 +0100 Subject: [PATCH 18/26] feature #1570: typo in --endpoint help --- src/cli/one_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 4eb6f58aef..97724f4ccb 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -91,7 +91,7 @@ EOT }, { :name => 'endpoint', - :large => '--endpoint endpoing', + :large => '--endpoint endpoint', :description => 'URL of OpenNebula xmlrpc frontend', :format => String } From 90b981060219accbb81c3146f42a2ba79a3530d7 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 16 Nov 2012 18:49:13 +0100 Subject: [PATCH 19/26] feature #1568: show help for each command --- src/cli/command_parser.rb | 63 +++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index 1bc3d8a661..a1455e987d 100644 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -66,6 +66,7 @@ module CommandParser @options = Hash.new @before_proc=nil + @comm_name=nil define_default_formats @@ -407,7 +408,7 @@ module CommandParser comm = @main elsif if @args[0] && !@args[0].match(/^-/) - comm_name = @args.shift.to_sym + @comm_name = comm_name = @args.shift.to_sym comm = @commands[comm_name] end end @@ -568,6 +569,14 @@ module CommandParser ######################################################################## def print_help + if @comm_name + print_command_help(@comm_name) + else + print_all_commands_help + end + end + + def print_all_commands_help if @usage puts "## SYNOPSIS" puts @@ -588,37 +597,53 @@ module CommandParser end end + def print_command_help(name) + command=@commands[name] + + puts "## USAGE" + print "#{name} " + print_command(@commands[name]) + + puts "## OPTIONS" + command[:options].flatten.each do |o| + print_option(o) + end + + @available_options.each do |o| + print_option o + end + end def print_options puts "## OPTIONS" shown_opts = Array.new - opt_format = "#{' '*5}%-25s %s" - @commands.each{ |key,value| - value[:options].flatten.each { |o| + @commands.each do |key,value| + value[:options].flatten.each do |o| if shown_opts.include?(o[:name]) next else shown_opts << o[:name] - str = "" - str << o[:short].split(' ').first << ', ' if o[:short] - str << o[:large] - - printf opt_format, str, o[:description] - puts + print_option(o) end - } - } + end + end - @available_options.each{ |o| - str = "" - str << o[:short].split(' ').first << ', ' if o[:short] - str << o[:large] + @available_options.each do |o| + print_option o + end + end - printf opt_format, str, o[:description] - puts - } + def print_option(o) + opt_format = "#{' '*5}%-25s %s" + + str = "" + str << o[:short].split(' ').first << ', ' if o[:short] + str << o[:large] + + printf opt_format, str, o[:description] + puts end def print_commands From 6947f7ae1d0517773357e104aa52ca02889bff4a Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 19 Nov 2012 12:41:21 +0100 Subject: [PATCH 20/26] feature #1640: reformat descriptions for 80 columns --- src/cli/cli_helper.rb | 3 ++- src/cli/one_helper.rb | 12 ++++++++---- src/cli/one_helper/oneimage_helper.rb | 10 ++++++---- src/cli/oneuser | 3 ++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cli/cli_helper.rb b/src/cli/cli_helper.rb index f6f3460e31..4518d633b3 100644 --- a/src/cli/cli_helper.rb +++ b/src/cli/cli_helper.rb @@ -36,7 +36,8 @@ module CLIHelper :short => "-f x,y,z", :large => "--filter x,y,z", :format => Array, - :description => "Filter data. An array is specified with column=value pairs." + :description => "Filter data. An array is specified with\n"<< + " "*31<<"column=value pairs." } # #HEADER = { diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 97724f4ccb..cbdcae2c55 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -102,7 +102,8 @@ EOT :name => 'cpu', :large => '--cpu cpu', :description => - 'CPU percentage reserved for the VM (1=100% one CPU)', + "CPU percentage reserved for the VM (1=100% one\n"<< + " "*31<<"CPU)", :format => Float }, { @@ -139,19 +140,22 @@ EOT { :name => 'disk', :large => '--disk disk0,disk1', - :description => 'Disks to attach. To use a disk owned by other user use user[disk]', + :description => "Disks to attach. To use a disk owned by other\n"<< + " "*31<<"user use user[disk]", :format => Array }, { :name => 'network', :large => '--network network0,network1', - :description => 'Networks to attach. To use a network owned by other user use user[network]', + :description => "Networks to attach. To use a network owned by\n"<< + " "*31<<"other user use user[network]", :format => Array }, { :name => 'raw', :large => '--raw string', - :description => 'Raw string to add to the template. Not to be confused with the RAW attribute', + :description => "Raw string to add to the template. Not to be\n"<< + " "*31<<"confused with the RAW attribute", :format => String }, { diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 83fa36edc1..6e1f796fc7 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -53,7 +53,8 @@ class OneImageHelper < OpenNebulaHelper::OneHelper { :name => "prefix", :large => "--prefix prefix", - :description => "Device prefix for the disk (eg. hd, sd, xvd or vd)", + :description => "Device prefix for the disk (eg. hd, sd, xvd\n"<< + " "*31<<"or vd)", :format => String, :proc => lambda do |o, options| prefix=o.strip.downcase @@ -115,7 +116,8 @@ class OneImageHelper < OpenNebulaHelper::OneHelper :name => "source", :large => "--source source", :description => - "Source to be used. Useful for not file-based images", + "Source to be used. Useful for not file-based\n"<< + " "*31<<"images", :format => String }, { @@ -149,8 +151,8 @@ class OneImageHelper < OpenNebulaHelper::OneHelper { :name => "fstype", :large => "--fstype fstype", - :description => "Type of file system to be built. This can be "<< - "any value understood by mkfs unix command.", + :description => "Type of file system to be built. This can be \n"<< + " "*31<<"any value understood by mkfs unix command.", :format => String, :proc => lambda do |o, options| if !options[:type] || !(options[:type].upcase=='DATABLOCK') diff --git a/src/cli/oneuser b/src/cli/oneuser index 1c0dac8bbb..5973f6e2ee 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -63,7 +63,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do SHA1={ :name => "sha1", :large => "--sha1", - :description => "The password will be hashed using the sha1 algorithm" + :description => "The password will be hashed using the sha1\n"<< + " "*31<<"algorithm" } SSH={ From 8d3c79334f7c10a1e6ded7183bdeff390b09fa3e Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 20 Nov 2012 11:25:42 +0100 Subject: [PATCH 21/26] feature #1642: bug adding context variables --- src/cli/one_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index cbdcae2c55..46321ccb91 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -723,7 +723,7 @@ EOT end end - lines+=options[:context] + lines+=options[:context] if options[:context] if !lines.empty? "CONTEXT=[\n"< Date: Tue, 20 Nov 2012 14:40:09 +0100 Subject: [PATCH 22/26] feature #1640: add --dry option to oneimage --- src/cli/one_helper.rb | 13 +++++++------ src/cli/one_helper/oneimage_helper.rb | 5 +++-- src/cli/oneimage | 7 ++++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 46321ccb91..e1433bcd01 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -76,6 +76,12 @@ EOT :format => String } + DRY={ + :name => 'dry', + :large => '--dry', + :description => 'Just print the template' + } + CLIENT_OPTIONS=[ { :name => 'user', @@ -194,15 +200,10 @@ EOT :large => '--boot device', :description => 'Select boot device (hd|fd|cdrom|network)', :format => String - }, - { - :name => 'dry', - :large => '--dry', - :description => 'Just print the template' } ] - TEMPLATE_OPTIONS_VM=[TEMPLATE_NAME_VM]+TEMPLATE_OPTIONS + TEMPLATE_OPTIONS_VM=[TEMPLATE_NAME_VM]+TEMPLATE_OPTIONS+[DRY] OPTIONS = XML, NUMERIC, KILOBYTES diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 6e1f796fc7..727413d855 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -161,7 +161,8 @@ class OneImageHelper < OpenNebulaHelper::OneHelper [0, o] end end - } + }, + OpenNebulaHelper::DRY ] def self.rname @@ -322,7 +323,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper end template=create_image_variables( - options, template_options-[:persistent]) + options, template_options-[:persistent, :dry]) template<<"PERSISTENT=YES\n" if options[:persistent] diff --git a/src/cli/oneimage b/src/cli/oneimage index df71c6a568..c414c4046d 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -107,7 +107,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :create, create_desc, [:file, nil], :options=>CREATE_OPTIONS + OneImageHelper::TEMPLATE_OPTIONS do - if options[:datastore].nil? + if options[:datastore].nil? && !options[:dry] STDERR.puts "Datastore to save the image is mandatory: " STDERR.puts "\t -d datastore_id" exit -1 @@ -134,6 +134,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do template = res.last end + if options[:dry] + puts template + exit 0 + end + image.allocate(template, options[:datastore]) rescue => e STDERR.puts e.messsage From 7b7d13320d23f58435eb047c908af909c301d052 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 20 Nov 2012 16:20:12 +0100 Subject: [PATCH 23/26] feature #1640: add --dry again to onetemplate --- src/cli/onetemplate | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli/onetemplate b/src/cli/onetemplate index af2da5f1cc..41409317bb 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -102,7 +102,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :create, create_desc, [:file, nil], :options => - [OneTemplateHelper::VM_NAME]+OpenNebulaHelper::TEMPLATE_OPTIONS do + [OneTemplateHelper::VM_NAME]+OpenNebulaHelper::TEMPLATE_OPTIONS+ + [OpenNebulaHelper::DRY] do if args[0] && OpenNebulaHelper.create_template_options_used?(options) STDERR.puts "You can not use both template file and template"<< From 5832c709e2d3733217bdeb7c15143855cda65e1b Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 20 Nov 2012 16:21:22 +0100 Subject: [PATCH 24/26] feature #1568: show all help if when the command is not known --- src/cli/command_parser.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index a1455e987d..41bcce9b78 100644 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -600,6 +600,11 @@ module CommandParser def print_command_help(name) command=@commands[name] + if !command + STDERR.puts "Command '#{name}' not found" + return print_all_commands_help + end + puts "## USAGE" print "#{name} " print_command(@commands[name]) From 898181d4a5514d555d23f2e460810a49c013a3a7 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 20 Nov 2012 18:30:40 +0100 Subject: [PATCH 25/26] feature #1640: add --vcpu parameter --- src/cli/one_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index e1433bcd01..8330a43446 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -112,6 +112,13 @@ EOT " "*31<<"CPU)", :format => Float }, + { + :name => 'vcpu', + :large => '--vcpu vcpu', + :description => + "Number of virtualized CPUs", + :format => Integer + }, { :name => 'arch', :large => '--arch arch', @@ -754,6 +761,7 @@ EOT end template<<"CPU=#{options[:cpu]}\n" if options[:cpu] + template<<"VCPU=#{options[:vcpu]}\n" if options[:vcpu] template<<"MEMORY=#{options[:memory]}\n" if options[:memory] template<<"#{options[:raw]}\n" if options[:raw] From fe50465a9873e80f3b2e3051761743823f323178 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 20 Nov 2012 19:02:55 +0100 Subject: [PATCH 26/26] feature #1571: enumerate image types in the CLI --- src/cli/oneimage | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cli/oneimage b/src/cli/oneimage index c414c4046d..2021463aa7 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -76,6 +76,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper.filterflag_to_i(arg) end + format(:type, 'Image type: OS, DATABLOCK or CDROM') do |arg| + type=arg.strip.upcase + if %w{OS DATABLOCK CDROM}.include? type + [0, type] + else + [1, "Image type not supported. Must be OS, DATABLOCK or CDROM."] + end + end + ######################################################################## # Commands ########################################################################