opennebula-cli 5.10.4 → 5.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/oneacct +2 -1
- data/bin/oneacl +2 -1
- data/bin/onecluster +2 -1
- data/bin/onedatastore +2 -1
- data/bin/oneflow +149 -551
- data/bin/oneflow-template +171 -292
- data/bin/onegroup +2 -1
- data/bin/onehook +2 -1
- data/bin/onehost +76 -9
- data/bin/oneimage +2 -1
- data/bin/onemarket +2 -1
- data/bin/onemarketapp +15 -3
- data/bin/onesecgroup +2 -1
- data/bin/oneshowback +2 -1
- data/bin/onetemplate +2 -1
- data/bin/oneuser +2 -1
- data/bin/onevcenter +2 -1
- data/bin/onevdc +2 -1
- data/bin/onevm +88 -16
- data/bin/onevmgroup +2 -1
- data/bin/onevnet +11 -3
- data/bin/onevntemplate +2 -1
- data/bin/onevrouter +2 -1
- data/bin/onezone +5 -1
- data/lib/cli_helper.rb +54 -30
- data/lib/command_parser.rb +33 -14
- data/lib/one_helper.rb +258 -6
- data/lib/one_helper/oneacct_helper.rb +1 -1
- data/lib/one_helper/oneacl_helper.rb +1 -1
- data/lib/one_helper/onecluster_helper.rb +4 -4
- data/lib/one_helper/onedatastore_helper.rb +1 -1
- data/lib/one_helper/oneflow_helper.rb +419 -0
- data/lib/one_helper/oneflowtemplate_helper.rb +312 -0
- data/lib/one_helper/onegroup_helper.rb +1 -1
- data/lib/one_helper/onehook_helper.rb +1 -1
- data/lib/one_helper/onehost_helper.rb +148 -68
- data/lib/one_helper/oneimage_helper.rb +2 -2
- data/lib/one_helper/onemarket_helper.rb +1 -1
- data/lib/one_helper/onemarketapp_helper.rb +1 -1
- data/lib/one_helper/oneprovision_helper.rb +104 -60
- data/lib/one_helper/onequota_helper.rb +1 -1
- data/lib/one_helper/onesecgroup_helper.rb +1 -1
- data/lib/one_helper/onetemplate_helper.rb +9 -180
- data/lib/one_helper/oneuser_helper.rb +1 -1
- data/lib/one_helper/onevcenter_helper.rb +2 -1
- data/lib/one_helper/onevdc_helper.rb +1 -1
- data/lib/one_helper/onevm_helper.rb +11 -6
- data/lib/one_helper/onevmgroup_helper.rb +1 -1
- data/lib/one_helper/onevnet_helper.rb +1 -1
- data/lib/one_helper/onevntemplate_helper.rb +1 -1
- data/lib/one_helper/onevrouter_helper.rb +1 -1
- data/lib/one_helper/onezone_helper.rb +3 -1
- metadata +8 -6
data/bin/onevmgroup
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -28,6 +28,7 @@ end
|
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
30
|
Gem.use_paths(GEMS_LOCATION)
|
31
|
+
$LOAD_PATH.reject! {|l| l =~ /(vendor|site)_ruby/ }
|
31
32
|
end
|
32
33
|
|
33
34
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
data/bin/onevnet
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -28,6 +28,7 @@ end
|
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
30
|
Gem.use_paths(GEMS_LOCATION)
|
31
|
+
$LOAD_PATH.reject! {|l| l =~ /(vendor|site)_ruby/ }
|
31
32
|
end
|
32
33
|
|
33
34
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
@@ -71,6 +72,13 @@ CommandParser::CmdParser.new(ARGV) do
|
|
71
72
|
:description => 'lock all actions'
|
72
73
|
}
|
73
74
|
|
75
|
+
FORCE = {
|
76
|
+
:name => 'force',
|
77
|
+
:large => '--force',
|
78
|
+
:description => 'Force execution of action, ' \
|
79
|
+
'bypass the consistency checks'
|
80
|
+
}
|
81
|
+
|
74
82
|
########################################################################
|
75
83
|
# Global Options
|
76
84
|
########################################################################
|
@@ -169,9 +177,9 @@ CommandParser::CmdParser.new(ARGV) do
|
|
169
177
|
Removes an address range from the Virtual Network
|
170
178
|
EOT
|
171
179
|
|
172
|
-
command :rmar, rmar_desc, :vnetid, :ar_id do
|
180
|
+
command :rmar, rmar_desc, :vnetid, :ar_id, :options => FORCE do
|
173
181
|
helper.perform_action(args[0], options, 'address range removed') do |vn|
|
174
|
-
vn.rm_ar(args[1])
|
182
|
+
vn.rm_ar(args[1], options[:force] || false)
|
175
183
|
end
|
176
184
|
end
|
177
185
|
|
data/bin/onevntemplate
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -28,6 +28,7 @@ end
|
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
30
|
Gem.use_paths(GEMS_LOCATION)
|
31
|
+
$LOAD_PATH.reject! {|l| l =~ /(vendor|site)_ruby/ }
|
31
32
|
end
|
32
33
|
|
33
34
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
data/bin/onevrouter
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -28,6 +28,7 @@ end
|
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
30
|
Gem.use_paths(GEMS_LOCATION)
|
31
|
+
$LOAD_PATH.reject! {|l| l =~ /(vendor|site)_ruby/ }
|
31
32
|
end
|
32
33
|
|
33
34
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
data/bin/onezone
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -28,6 +28,7 @@ end
|
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
30
|
Gem.use_paths(GEMS_LOCATION)
|
31
|
+
$LOAD_PATH.reject! {|l| l =~ /(vendor|site)_ruby/ }
|
31
32
|
end
|
32
33
|
|
33
34
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
@@ -230,6 +231,9 @@ CommandParser::CmdParser.new(ARGV) do
|
|
230
231
|
|
231
232
|
command :serversync, sync_desc, :server, :options => [DATABASE] do
|
232
233
|
begin
|
234
|
+
# Suppress augeas require warning message
|
235
|
+
$VERBOSE = nil
|
236
|
+
|
233
237
|
gem 'augeas', '~> 0.6'
|
234
238
|
require 'augeas'
|
235
239
|
rescue Gem::LoadError
|
data/lib/cli_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -181,9 +181,15 @@ module CLIHelper
|
|
181
181
|
ANSI_YELLOW = "\33[33m"
|
182
182
|
|
183
183
|
# CLI states
|
184
|
-
OK_STATES = %w[runn rdy on configured SUCCESS]
|
185
|
-
BAD_STATES = %w[fail
|
186
|
-
|
184
|
+
OK_STATES = %w[runn rdy on configured SUCCESS RUNNING]
|
185
|
+
BAD_STATES = %w[fail
|
186
|
+
err
|
187
|
+
error
|
188
|
+
ERROR
|
189
|
+
FAILED_DEPLOYING
|
190
|
+
FAILED_UNDEPLOYING
|
191
|
+
FAILED_SCALING]
|
192
|
+
REGULAR_STATES = %w[pending WARNING]
|
187
193
|
|
188
194
|
# Set state color
|
189
195
|
#
|
@@ -350,6 +356,12 @@ module CLIHelper
|
|
350
356
|
# @param options [Hash] Object with CLI user options
|
351
357
|
# @param top [Boolean] True to not update columns again
|
352
358
|
def show(data, options = {}, top = false)
|
359
|
+
if options[:list]
|
360
|
+
@cli_columns = options[:list].collect {|o| o.upcase.to_sym }
|
361
|
+
else
|
362
|
+
@cli_columns = @default_columns
|
363
|
+
end
|
364
|
+
|
353
365
|
update_columns(options) unless top
|
354
366
|
|
355
367
|
if data.is_a? Hash
|
@@ -471,7 +483,7 @@ module CLIHelper
|
|
471
483
|
|
472
484
|
# Get header in string format
|
473
485
|
def header_str
|
474
|
-
@
|
486
|
+
@cli_columns.collect do |c|
|
475
487
|
if @columns[c]
|
476
488
|
format_str(c, c.to_s)
|
477
489
|
else
|
@@ -489,12 +501,12 @@ module CLIHelper
|
|
489
501
|
|
490
502
|
update_columns_size(options)
|
491
503
|
|
504
|
+
options[:csv_del] ? del = options[:csv_del] : del = ','
|
505
|
+
|
492
506
|
if !options[:csv] && (!options.key? :no_header)
|
493
507
|
CLIHelper.print_header(header_str)
|
494
|
-
|
495
|
-
|
496
|
-
if options[:csv] && (!options.key? :no_header)
|
497
|
-
print_csv_data([@default_columns], options[:csv_del])
|
508
|
+
elsif options[:csv] && (!options.key? :no_header)
|
509
|
+
puts CSV.generate_line(@cli_columns, :col_sep => del)
|
498
510
|
end
|
499
511
|
|
500
512
|
@res_data ? print_data(@res_data, options) : puts
|
@@ -522,7 +534,13 @@ module CLIHelper
|
|
522
534
|
del ? del = del : del = ','
|
523
535
|
|
524
536
|
data.each do |l|
|
525
|
-
|
537
|
+
result = []
|
538
|
+
|
539
|
+
@cli_columns.each do |col|
|
540
|
+
result << l[@default_columns.index(col)]
|
541
|
+
end
|
542
|
+
|
543
|
+
puts CSV.generate_line(result, :col_sep => del)
|
526
544
|
end
|
527
545
|
end
|
528
546
|
|
@@ -531,25 +549,26 @@ module CLIHelper
|
|
531
549
|
# @param data [Array] Array with data to show
|
532
550
|
# @param stat_column [String] Name of the state column
|
533
551
|
def print_normal_data(data, stat_column)
|
534
|
-
ncolumns = @default_columns.length
|
535
|
-
|
536
552
|
if stat_column
|
537
|
-
stat
|
538
|
-
stat_column = @default_columns.index(stat)
|
553
|
+
stat = stat_column.upcase.to_sym
|
539
554
|
else
|
540
|
-
|
555
|
+
stat = :STAT
|
541
556
|
end
|
542
557
|
|
543
558
|
data.each do |l|
|
544
559
|
result = []
|
545
560
|
|
546
|
-
|
561
|
+
@cli_columns.each do |col|
|
562
|
+
i = @default_columns.index(col)
|
563
|
+
|
564
|
+
# Column might not exist
|
565
|
+
next unless i
|
566
|
+
|
547
567
|
dat = l[i]
|
548
|
-
col = @default_columns[i]
|
549
568
|
|
550
569
|
str = format_str(col, dat)
|
551
570
|
|
552
|
-
str = CLIHelper.color_state(str) if
|
571
|
+
str = CLIHelper.color_state(str) if col == stat
|
553
572
|
|
554
573
|
result << str
|
555
574
|
end
|
@@ -564,8 +583,17 @@ module CLIHelper
|
|
564
583
|
#
|
565
584
|
# @return [Array] Array with selected columns information
|
566
585
|
def data_array(data, options)
|
586
|
+
# Take default table columns and desired ones by the user
|
587
|
+
cols = @default_columns
|
588
|
+
|
589
|
+
@cli_columns.each do |col|
|
590
|
+
next if @default_columns.include?(col)
|
591
|
+
|
592
|
+
@default_columns.insert(@cli_columns.index(col) + 1, col)
|
593
|
+
end
|
594
|
+
|
567
595
|
res_data = data.collect do |d|
|
568
|
-
|
596
|
+
cols.collect do |c|
|
569
597
|
@columns[c][:proc].call(d).to_s if @columns[c]
|
570
598
|
end
|
571
599
|
end
|
@@ -602,7 +630,7 @@ module CLIHelper
|
|
602
630
|
def config_expand_data
|
603
631
|
ret = []
|
604
632
|
|
605
|
-
@
|
633
|
+
@cli_columns.each do |column|
|
606
634
|
expand_c = @columns[column][:expand]
|
607
635
|
|
608
636
|
next unless expand_c
|
@@ -623,7 +651,7 @@ module CLIHelper
|
|
623
651
|
def config_adjust_data
|
624
652
|
ret = []
|
625
653
|
|
626
|
-
@
|
654
|
+
@cli_columns.each do |column|
|
627
655
|
next unless @columns[column][:adjust]
|
628
656
|
|
629
657
|
ret << column.to_s.downcase
|
@@ -647,13 +675,13 @@ module CLIHelper
|
|
647
675
|
|
648
676
|
return if terminal_size.nil?
|
649
677
|
|
650
|
-
default_columns = columns_info(@
|
678
|
+
default_columns = columns_info(@cli_columns)
|
651
679
|
expand_columns = columns_info(expand_columns)
|
652
680
|
|
653
681
|
total_size = total_columns_size(default_columns)
|
654
682
|
columns_size = total_columns_size(expand_columns)
|
655
683
|
|
656
|
-
terminal_size -= (@
|
684
|
+
terminal_size -= (@cli_columns.size - 1)
|
657
685
|
left_size = terminal_size - total_size
|
658
686
|
remaining_size = left_size
|
659
687
|
|
@@ -725,7 +753,7 @@ module CLIHelper
|
|
725
753
|
expand_data = []
|
726
754
|
|
727
755
|
if expand_all
|
728
|
-
expand_data = @
|
756
|
+
expand_data = @cli_columns
|
729
757
|
elsif expand
|
730
758
|
expand_data += options[:expand]
|
731
759
|
end
|
@@ -739,7 +767,7 @@ module CLIHelper
|
|
739
767
|
unless expand_all
|
740
768
|
adjust.each do |column|
|
741
769
|
column = column.upcase.to_sym
|
742
|
-
size = max_size(@
|
770
|
+
size = max_size(@cli_columns.index(column))
|
743
771
|
|
744
772
|
if size && size > @columns[column][:size]
|
745
773
|
@columns[column][:adjust] = true
|
@@ -791,10 +819,6 @@ module CLIHelper
|
|
791
819
|
rescue StandardError => e
|
792
820
|
CLIHelper.fail(e.message)
|
793
821
|
end
|
794
|
-
|
795
|
-
return unless options[:list]
|
796
|
-
|
797
|
-
@default_columns = options[:list].collect {|o| o.upcase.to_sym }
|
798
822
|
end
|
799
823
|
|
800
824
|
# Filter data
|
@@ -815,7 +839,7 @@ module CLIHelper
|
|
815
839
|
m = s.match(/^(.*?)#{operators}(.*?)$/)
|
816
840
|
|
817
841
|
if m
|
818
|
-
index = @default_columns.index(m[1].to_sym)
|
842
|
+
index = @default_columns.index(m[1].upcase.to_sym)
|
819
843
|
|
820
844
|
if index
|
821
845
|
{
|
data/lib/command_parser.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -140,6 +140,7 @@ module CommandParser
|
|
140
140
|
# @option options [String] :name
|
141
141
|
# @option options [String] :short
|
142
142
|
# @option options [String] :large
|
143
|
+
# @option options [Boolean] :multiple
|
143
144
|
# @option options [String] :description
|
144
145
|
# @option options [Class] :format
|
145
146
|
# @option options [Block] :proc The block receives the value of the
|
@@ -452,7 +453,7 @@ module CommandParser
|
|
452
453
|
|
453
454
|
if comm.nil?
|
454
455
|
print_help
|
455
|
-
exit
|
456
|
+
exit 0
|
456
457
|
end
|
457
458
|
|
458
459
|
if comm[:deprecated]
|
@@ -463,16 +464,27 @@ module CommandParser
|
|
463
464
|
parse(extra_options)
|
464
465
|
|
465
466
|
if comm
|
466
|
-
|
467
|
+
begin
|
468
|
+
@before_proc.call if @before_proc
|
469
|
+
rescue StandardError => e
|
470
|
+
STDERR.puts e.message
|
471
|
+
exit(-1)
|
472
|
+
end
|
467
473
|
|
468
474
|
check_args!(comm_name, comm[:arity], comm[:args_format])
|
469
475
|
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
+
begin
|
477
|
+
rc = comm[:proc].call
|
478
|
+
|
479
|
+
if rc.instance_of?(Array)
|
480
|
+
puts rc[1]
|
481
|
+
exit rc.first
|
482
|
+
else
|
483
|
+
exit(@exit_code || rc)
|
484
|
+
end
|
485
|
+
rescue StandardError => e
|
486
|
+
STDERR.puts e.message
|
487
|
+
exit(-1)
|
476
488
|
end
|
477
489
|
end
|
478
490
|
end
|
@@ -490,21 +502,28 @@ module CommandParser
|
|
490
502
|
args = []
|
491
503
|
args << e[:short] if e[:short]
|
492
504
|
args << e[:large]
|
505
|
+
args << e[:multiple] if e[:multiple]
|
493
506
|
args << e[:format]
|
494
507
|
args << e[:description]
|
495
508
|
|
496
509
|
opts.on(*args) do |o|
|
497
|
-
if e[:proc]
|
510
|
+
if e[:proc] && !e[:multiple]
|
498
511
|
@options[e[:name].to_sym]=o
|
499
512
|
with_proc<<e
|
500
513
|
elsif e[:name]=="help"
|
501
514
|
print_help
|
502
|
-
exit
|
515
|
+
exit 0
|
503
516
|
elsif e[:name]=="version"
|
504
517
|
puts @version
|
505
|
-
exit
|
506
|
-
|
518
|
+
exit 0
|
519
|
+
elsif !e[:multiple]
|
507
520
|
@options[e[:name].to_sym]=o
|
521
|
+
else
|
522
|
+
if @options[e[:name].to_sym].nil?
|
523
|
+
@options[e[:name].to_sym] = []
|
524
|
+
end
|
525
|
+
|
526
|
+
@options[e[:name].to_sym] << o
|
508
527
|
end
|
509
528
|
end
|
510
529
|
end
|
@@ -630,7 +649,7 @@ module CommandParser
|
|
630
649
|
print_formatters
|
631
650
|
puts
|
632
651
|
if @version
|
633
|
-
puts "##
|
652
|
+
puts "## VERSION"
|
634
653
|
puts @version
|
635
654
|
end
|
636
655
|
end
|
data/lib/one_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -30,11 +30,7 @@ include OpenNebula
|
|
30
30
|
module OpenNebulaHelper
|
31
31
|
ONE_VERSION=<<-EOT
|
32
32
|
OpenNebula #{OpenNebula::VERSION}
|
33
|
-
Copyright 2002-
|
34
|
-
|
35
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
36
|
-
not use this file except in compliance with the License. You may obtain
|
37
|
-
a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
33
|
+
Copyright 2002-2020, OpenNebula Project, OpenNebula Systems
|
38
34
|
EOT
|
39
35
|
|
40
36
|
if ONE_LOCATION
|
@@ -1203,6 +1199,18 @@ EOT
|
|
1203
1199
|
end
|
1204
1200
|
end
|
1205
1201
|
|
1202
|
+
def OpenNebulaHelper.bytes_to_unit(value, unit = 'K')
|
1203
|
+
j = 0
|
1204
|
+
i = BinarySufix.index(unit).to_i
|
1205
|
+
|
1206
|
+
while j < i do
|
1207
|
+
value /= 1024.0
|
1208
|
+
j += 1
|
1209
|
+
end
|
1210
|
+
|
1211
|
+
value
|
1212
|
+
end
|
1213
|
+
|
1206
1214
|
# If the cluster name is empty, returns a '-' char.
|
1207
1215
|
#
|
1208
1216
|
# @param str [String || Hash] Cluster name, or empty Hash (when <CLUSTER/>)
|
@@ -1696,4 +1704,248 @@ EOT
|
|
1696
1704
|
"-"
|
1697
1705
|
end
|
1698
1706
|
end
|
1707
|
+
|
1708
|
+
def OpenNebulaHelper.parse_user_inputs(inputs, get_defaults = false)
|
1709
|
+
unless get_defaults
|
1710
|
+
puts 'There are some parameters that require user input. ' \
|
1711
|
+
'Use the string <<EDITOR>> to launch an editor ' \
|
1712
|
+
'(e.g. for multi-line inputs)'
|
1713
|
+
end
|
1714
|
+
|
1715
|
+
answers = {}
|
1716
|
+
|
1717
|
+
inputs.each do |key, val|
|
1718
|
+
input_cfg = val.split('|', -1)
|
1719
|
+
|
1720
|
+
if input_cfg.length < 3
|
1721
|
+
STDERR.puts 'Malformed user input. It should have at least 3 '\
|
1722
|
+
"parts separated by '|':"
|
1723
|
+
STDERR.puts " #{key}: #{val}"
|
1724
|
+
exit(-1)
|
1725
|
+
end
|
1726
|
+
|
1727
|
+
mandatory, type, description, params, initial = input_cfg
|
1728
|
+
optional = mandatory.strip == 'O'
|
1729
|
+
type.strip!
|
1730
|
+
description.strip!
|
1731
|
+
|
1732
|
+
if input_cfg.length > 3
|
1733
|
+
if input_cfg.length != 5
|
1734
|
+
STDERR.puts 'Malformed user input. It should have 5 parts'\
|
1735
|
+
" separated by '|':"
|
1736
|
+
STDERR.puts " #{key}: #{val}"
|
1737
|
+
exit(-1)
|
1738
|
+
end
|
1739
|
+
|
1740
|
+
params.strip!
|
1741
|
+
initial.strip!
|
1742
|
+
end
|
1743
|
+
|
1744
|
+
if get_defaults
|
1745
|
+
answers[key]= initial unless mandatory == 'M'
|
1746
|
+
next
|
1747
|
+
end
|
1748
|
+
|
1749
|
+
puts " * (#{key}) #{description}"
|
1750
|
+
|
1751
|
+
header = ' '
|
1752
|
+
if !initial.nil? && initial != ''
|
1753
|
+
header += "Press enter for default (#{initial}). "
|
1754
|
+
end
|
1755
|
+
|
1756
|
+
case type
|
1757
|
+
when 'text', 'text64'
|
1758
|
+
print header
|
1759
|
+
|
1760
|
+
answer = STDIN.readline.chop
|
1761
|
+
|
1762
|
+
if answer == '<<EDITOR>>'
|
1763
|
+
answer = OpenNebulaHelper.editor_input
|
1764
|
+
end
|
1765
|
+
|
1766
|
+
# use default in case it's empty
|
1767
|
+
answer = initial if answer.empty?
|
1768
|
+
|
1769
|
+
if type == 'text64'
|
1770
|
+
answer = Base64.encode64(answer).strip.delete("\n")
|
1771
|
+
end
|
1772
|
+
|
1773
|
+
when 'boolean'
|
1774
|
+
print header
|
1775
|
+
|
1776
|
+
answer = STDIN.readline.chop
|
1777
|
+
|
1778
|
+
# use default in case it's empty
|
1779
|
+
answer = initial if answer.empty?
|
1780
|
+
|
1781
|
+
unless %w[YES NO].include?(answer)
|
1782
|
+
STDERR.puts "Invalid boolean '#{answer}'"
|
1783
|
+
STDERR.puts 'Boolean has to be YES or NO'
|
1784
|
+
exit(-1)
|
1785
|
+
end
|
1786
|
+
|
1787
|
+
when 'password'
|
1788
|
+
print header
|
1789
|
+
|
1790
|
+
answer = OpenNebulaHelper::OneHelper.get_password
|
1791
|
+
|
1792
|
+
# use default in case it's empty
|
1793
|
+
answer = initial if answer.empty?
|
1794
|
+
|
1795
|
+
when 'number', 'number-float'
|
1796
|
+
if type == 'number'
|
1797
|
+
header += 'Integer: '
|
1798
|
+
exp = INT_EXP
|
1799
|
+
else
|
1800
|
+
header += 'Float: '
|
1801
|
+
exp = FLOAT_EXP
|
1802
|
+
end
|
1803
|
+
|
1804
|
+
begin
|
1805
|
+
print header
|
1806
|
+
answer = STDIN.readline.chop
|
1807
|
+
|
1808
|
+
answer = initial if answer == ''
|
1809
|
+
noanswer = ((answer == '') && optional)
|
1810
|
+
end while !noanswer && (answer =~ exp) == nil
|
1811
|
+
|
1812
|
+
if noanswer
|
1813
|
+
next
|
1814
|
+
end
|
1815
|
+
|
1816
|
+
when 'range', 'range-float'
|
1817
|
+
min, max = params.split('..')
|
1818
|
+
|
1819
|
+
if min.nil? || max.nil?
|
1820
|
+
STDERR.puts 'Malformed user input. '\
|
1821
|
+
"Parameters should be 'min..max':"
|
1822
|
+
STDERR.puts " #{key}: #{val}"
|
1823
|
+
exit(-1)
|
1824
|
+
end
|
1825
|
+
|
1826
|
+
if type == 'range'
|
1827
|
+
exp = INT_EXP
|
1828
|
+
min = min.to_i
|
1829
|
+
max = max.to_i
|
1830
|
+
|
1831
|
+
header += "Integer in the range [#{min}..#{max}]: "
|
1832
|
+
else
|
1833
|
+
exp = FLOAT_EXP
|
1834
|
+
min = min.to_f
|
1835
|
+
max = max.to_f
|
1836
|
+
|
1837
|
+
header += "Float in the range [#{min}..#{max}]: "
|
1838
|
+
end
|
1839
|
+
|
1840
|
+
begin
|
1841
|
+
print header
|
1842
|
+
answer = STDIN.readline.chop
|
1843
|
+
|
1844
|
+
answer = initial if answer == ''
|
1845
|
+
|
1846
|
+
noanswer = (answer == '') && optional
|
1847
|
+
end while !noanswer && ((answer =~ exp) == nil ||
|
1848
|
+
answer.to_f < min || answer.to_f > max)
|
1849
|
+
|
1850
|
+
if noanswer
|
1851
|
+
next
|
1852
|
+
end
|
1853
|
+
|
1854
|
+
when 'list'
|
1855
|
+
options = params.split(',')
|
1856
|
+
|
1857
|
+
options.each_with_index do |opt, i|
|
1858
|
+
puts " #{i} #{opt}"
|
1859
|
+
end
|
1860
|
+
|
1861
|
+
puts
|
1862
|
+
|
1863
|
+
header += 'Please type the selection number: '
|
1864
|
+
|
1865
|
+
begin
|
1866
|
+
print header
|
1867
|
+
answer = STDIN.readline.chop
|
1868
|
+
|
1869
|
+
if answer == ''
|
1870
|
+
answer = initial
|
1871
|
+
else
|
1872
|
+
answer = options[answer.to_i]
|
1873
|
+
end
|
1874
|
+
|
1875
|
+
noanswer = ((answer == '') && optional)
|
1876
|
+
end while !noanswer && !options.include?(answer)
|
1877
|
+
|
1878
|
+
if noanswer
|
1879
|
+
next
|
1880
|
+
end
|
1881
|
+
|
1882
|
+
when 'fixed'
|
1883
|
+
puts " Fixed value of (#{initial}). Cannot be changed"
|
1884
|
+
answer = initial
|
1885
|
+
|
1886
|
+
else
|
1887
|
+
STDERR.puts 'Wrong type for user input:'
|
1888
|
+
STDERR.puts " #{key}: #{val}"
|
1889
|
+
exit(-1)
|
1890
|
+
end
|
1891
|
+
|
1892
|
+
answers[key] = answer
|
1893
|
+
end
|
1894
|
+
|
1895
|
+
answers
|
1896
|
+
end
|
1897
|
+
|
1898
|
+
# Returns plot object to print it on the CLI
|
1899
|
+
#
|
1900
|
+
# @param x [Array] Data to x axis (Time axis)
|
1901
|
+
# @param y [Array] Data to y axis
|
1902
|
+
# @param attr [String] Parameter to y axis
|
1903
|
+
# @param title [String] Plot title
|
1904
|
+
#
|
1905
|
+
# @return Gnuplot plot object
|
1906
|
+
def OpenNebulaHelper.get_plot(x, y, attr, title)
|
1907
|
+
# Require gnuplot gem only here
|
1908
|
+
begin
|
1909
|
+
require 'gnuplot'
|
1910
|
+
rescue LoadError, Gem::LoadError
|
1911
|
+
STDERR.puts(
|
1912
|
+
'Gnuplot gem is not installed, run `gem install gnuplot` '\
|
1913
|
+
'to install it'
|
1914
|
+
)
|
1915
|
+
exit(-1)
|
1916
|
+
end
|
1917
|
+
|
1918
|
+
# Check if gnuplot is installed on the system
|
1919
|
+
unless system('gnuplot --version')
|
1920
|
+
STDERR.puts(
|
1921
|
+
'Gnuplot is not installed, install it depending on your distro'
|
1922
|
+
)
|
1923
|
+
exit(-1)
|
1924
|
+
end
|
1925
|
+
|
1926
|
+
Gnuplot.open do |gp|
|
1927
|
+
Gnuplot::Plot.new(gp) do |p|
|
1928
|
+
p.title title
|
1929
|
+
|
1930
|
+
p.xlabel 'Time'
|
1931
|
+
p.ylabel attr
|
1932
|
+
|
1933
|
+
p.xdata 'time'
|
1934
|
+
p.timefmt "'%H:%M'"
|
1935
|
+
p.format "x '%H:%M'"
|
1936
|
+
|
1937
|
+
p.style 'data lines'
|
1938
|
+
p.terminal 'dumb'
|
1939
|
+
|
1940
|
+
p.data << Gnuplot::DataSet.new([x, y]) do |ds|
|
1941
|
+
ds.with = 'linespoints'
|
1942
|
+
ds.linewidth = '3'
|
1943
|
+
ds.using = '1:2'
|
1944
|
+
|
1945
|
+
ds.notitle
|
1946
|
+
end
|
1947
|
+
end
|
1948
|
+
end
|
1949
|
+
end
|
1950
|
+
|
1699
1951
|
end
|