opennebula-cli 5.10.3 → 5.11.90.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/bin/oneacct +2 -1
  3. data/bin/oneacl +2 -1
  4. data/bin/onecluster +2 -1
  5. data/bin/onedatastore +2 -1
  6. data/bin/oneflow +149 -551
  7. data/bin/oneflow-template +171 -292
  8. data/bin/onegroup +2 -1
  9. data/bin/onehook +2 -1
  10. data/bin/onehost +9 -9
  11. data/bin/oneimage +2 -1
  12. data/bin/onemarket +2 -1
  13. data/bin/onemarketapp +15 -3
  14. data/bin/onesecgroup +2 -1
  15. data/bin/oneshowback +2 -1
  16. data/bin/onetemplate +2 -1
  17. data/bin/oneuser +2 -1
  18. data/bin/onevcenter +2 -1
  19. data/bin/onevdc +2 -1
  20. data/bin/onevm +88 -16
  21. data/bin/onevmgroup +2 -1
  22. data/bin/onevnet +11 -3
  23. data/bin/onevntemplate +2 -1
  24. data/bin/onevrouter +2 -1
  25. data/bin/onezone +5 -1
  26. data/lib/cli_helper.rb +32 -13
  27. data/lib/command_parser.rb +32 -13
  28. data/lib/one_helper.rb +193 -2
  29. data/lib/one_helper/oneacct_helper.rb +1 -1
  30. data/lib/one_helper/oneacl_helper.rb +1 -1
  31. data/lib/one_helper/onecluster_helper.rb +4 -4
  32. data/lib/one_helper/onedatastore_helper.rb +1 -1
  33. data/lib/one_helper/oneflow_helper.rb +419 -0
  34. data/lib/one_helper/oneflowtemplate_helper.rb +312 -0
  35. data/lib/one_helper/onegroup_helper.rb +1 -1
  36. data/lib/one_helper/onehook_helper.rb +1 -1
  37. data/lib/one_helper/onehost_helper.rb +32 -30
  38. data/lib/one_helper/oneimage_helper.rb +2 -2
  39. data/lib/one_helper/onemarket_helper.rb +1 -1
  40. data/lib/one_helper/onemarketapp_helper.rb +1 -1
  41. data/lib/one_helper/oneprovision_helper.rb +104 -60
  42. data/lib/one_helper/onequota_helper.rb +1 -1
  43. data/lib/one_helper/onesecgroup_helper.rb +1 -1
  44. data/lib/one_helper/onetemplate_helper.rb +9 -180
  45. data/lib/one_helper/oneuser_helper.rb +1 -1
  46. data/lib/one_helper/onevcenter_helper.rb +2 -1
  47. data/lib/one_helper/onevdc_helper.rb +1 -1
  48. data/lib/one_helper/onevm_helper.rb +11 -6
  49. data/lib/one_helper/onevmgroup_helper.rb +1 -1
  50. data/lib/one_helper/onevnet_helper.rb +1 -1
  51. data/lib/one_helper/onevntemplate_helper.rb +1 -1
  52. data/lib/one_helper/onevrouter_helper.rb +1 -1
  53. data/lib/one_helper/onezone_helper.rb +3 -1
  54. metadata +10 -8
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
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
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
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 #
@@ -19,6 +19,9 @@ require 'csv'
19
19
  # CLI Helper
20
20
  module CLIHelper
21
21
 
22
+ # Available operators for filtering operations
23
+ FILTER_OPS = %w[= != < <= > >= ~]
24
+
22
25
  # CLI general options
23
26
  LIST = {
24
27
  :name => 'list',
@@ -55,7 +58,10 @@ module CLIHelper
55
58
  :large => '--filter x,y,z',
56
59
  :format => Array,
57
60
  :description => "Filter data. An array is specified with\n" <<
58
- ' ' * 31 << 'column=value pairs.'
61
+ ' ' * 31 << 'column=value pairs.' <<
62
+ ' ' * 31 << "Valid operators #{FILTER_OPS.join(',')}" <<
63
+ ' ' * 31 << 'e.g. NAME=test (match name with test)' <<
64
+ ' ' * 31 << 'NAME~test (match test, te, tes..)'
59
65
  }
60
66
 
61
67
  OPERATOR = {
@@ -175,9 +181,15 @@ module CLIHelper
175
181
  ANSI_YELLOW = "\33[33m"
176
182
 
177
183
  # CLI states
178
- OK_STATES = %w[runn rdy on configured SUCCESS]
179
- BAD_STATES = %w[fail err error ERROR]
180
- REGULAR_STATES = %w[pending]
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]
181
193
 
182
194
  # Set state color
183
195
  #
@@ -568,6 +580,10 @@ module CLIHelper
568
580
  filter_data!(res_data, options) if options[:filter]
569
581
  end
570
582
 
583
+ return res_data unless options[:list]
584
+
585
+ @default_columns = options[:list].collect {|o| o.upcase.to_sym }
586
+
571
587
  res_data
572
588
  end
573
589
 
@@ -785,10 +801,6 @@ module CLIHelper
785
801
  rescue StandardError => e
786
802
  CLIHelper.fail(e.message)
787
803
  end
788
-
789
- return unless options[:list]
790
-
791
- @default_columns = options[:list].collect {|o| o.upcase.to_sym }
792
804
  end
793
805
 
794
806
  # Filter data
@@ -796,7 +808,7 @@ module CLIHelper
796
808
  # @param data [Array] Array with data to filter
797
809
  # @param options [Hash] Object with CLI user options
798
810
  def filter_data!(data, options)
799
- operators = /(=|!=|<|<=|>|>=)/
811
+ operators = /(#{FILTER_OPS.join('|')})/
800
812
  filter = options[:filter]
801
813
 
802
814
  if options.key?(:operator)
@@ -809,7 +821,7 @@ module CLIHelper
809
821
  m = s.match(/^(.*?)#{operators}(.*?)$/)
810
822
 
811
823
  if m
812
- index = @default_columns.index(m[1].to_sym)
824
+ index = @columns.keys.index(m[1].to_sym)
813
825
 
814
826
  if index
815
827
  {
@@ -819,7 +831,7 @@ module CLIHelper
819
831
  :index => index
820
832
  }
821
833
  else
822
- CLIHelper.fail("Column '#{left}' not found")
834
+ CLIHelper.fail("Column '#{m[1]}' not found")
823
835
  end
824
836
  else
825
837
  CLIHelper.fail("Expression '#{s}' incorrect")
@@ -830,7 +842,14 @@ module CLIHelper
830
842
  pass = true
831
843
 
832
844
  stems.each do |s|
833
- s[:operator] == '=' ? op = '==' : op = s[:operator]
845
+ case s[:operator]
846
+ when '='
847
+ op = '=='
848
+ when '~'
849
+ op = 'include?'
850
+ else
851
+ op = s[:operator]
852
+ end
834
853
 
835
854
  if d[s[:index]].public_send(op, s[:right])
836
855
  if log_operator == 'OR'
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
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 -1
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
- @before_proc.call if @before_proc
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
- rc = comm[:proc].call
471
- if rc.instance_of?(Array)
472
- puts rc[1]
473
- exit rc.first
474
- else
475
- exit(@exit_code || rc)
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
- else
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
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
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,7 +30,7 @@ include OpenNebula
30
30
  module OpenNebulaHelper
31
31
  ONE_VERSION=<<-EOT
32
32
  OpenNebula #{OpenNebula::VERSION}
33
- Copyright 2002-2019, OpenNebula Project, OpenNebula Systems
33
+ Copyright 2002-2020, OpenNebula Project, OpenNebula Systems
34
34
 
35
35
  Licensed under the Apache License, Version 2.0 (the "License"); you may
36
36
  not use this file except in compliance with the License. You may obtain
@@ -1696,4 +1696,195 @@ EOT
1696
1696
  "-"
1697
1697
  end
1698
1698
  end
1699
+
1700
+ def OpenNebulaHelper.parse_user_inputs(inputs, get_defaults = false)
1701
+ unless get_defaults
1702
+ puts 'There are some parameters that require user input. ' \
1703
+ 'Use the string <<EDITOR>> to launch an editor ' \
1704
+ '(e.g. for multi-line inputs)'
1705
+ end
1706
+
1707
+ answers = {}
1708
+
1709
+ inputs.each do |key, val|
1710
+ input_cfg = val.split('|', -1)
1711
+
1712
+ if input_cfg.length < 3
1713
+ STDERR.puts 'Malformed user input. It should have at least 3 '\
1714
+ "parts separated by '|':"
1715
+ STDERR.puts " #{key}: #{val}"
1716
+ exit(-1)
1717
+ end
1718
+
1719
+ mandatory, type, description, params, initial = input_cfg
1720
+ optional = mandatory.strip == 'O'
1721
+ type.strip!
1722
+ description.strip!
1723
+
1724
+ if input_cfg.length > 3
1725
+ if input_cfg.length != 5
1726
+ STDERR.puts 'Malformed user input. It should have 5 parts'\
1727
+ " separated by '|':"
1728
+ STDERR.puts " #{key}: #{val}"
1729
+ exit(-1)
1730
+ end
1731
+
1732
+ params.strip!
1733
+ initial.strip!
1734
+ end
1735
+
1736
+ if get_defaults
1737
+ answers[key]= initial unless mandatory == 'M'
1738
+ next
1739
+ end
1740
+
1741
+ puts " * (#{key}) #{description}"
1742
+
1743
+ header = ' '
1744
+ if !initial.nil? && initial != ''
1745
+ header += "Press enter for default (#{initial}). "
1746
+ end
1747
+
1748
+ case type
1749
+ when 'text', 'text64'
1750
+ print header
1751
+
1752
+ answer = STDIN.readline.chop
1753
+
1754
+ if answer == '<<EDITOR>>'
1755
+ answer = OpenNebulaHelper.editor_input
1756
+ end
1757
+
1758
+ # use default in case it's empty
1759
+ answer = initial if answer.empty?
1760
+
1761
+ if type == 'text64'
1762
+ answer = Base64.encode64(answer).strip.delete("\n")
1763
+ end
1764
+
1765
+ when 'boolean'
1766
+ print header
1767
+
1768
+ answer = STDIN.readline.chop
1769
+
1770
+ # use default in case it's empty
1771
+ answer = initial if answer.empty?
1772
+
1773
+ unless %w[YES NO].include?(answer)
1774
+ STDERR.puts "Invalid boolean '#{answer}'"
1775
+ STDERR.puts 'Boolean has to be YES or NO'
1776
+ exit(-1)
1777
+ end
1778
+
1779
+ when 'password'
1780
+ print header
1781
+
1782
+ answer = OpenNebulaHelper::OneHelper.get_password
1783
+
1784
+ # use default in case it's empty
1785
+ answer = initial if answer.empty?
1786
+
1787
+ when 'number', 'number-float'
1788
+ if type == 'number'
1789
+ header += 'Integer: '
1790
+ exp = INT_EXP
1791
+ else
1792
+ header += 'Float: '
1793
+ exp = FLOAT_EXP
1794
+ end
1795
+
1796
+ begin
1797
+ print header
1798
+ answer = STDIN.readline.chop
1799
+
1800
+ answer = initial if answer == ''
1801
+ noanswer = ((answer == '') && optional)
1802
+ end while !noanswer && (answer =~ exp) == nil
1803
+
1804
+ if noanswer
1805
+ next
1806
+ end
1807
+
1808
+ when 'range', 'range-float'
1809
+ min, max = params.split('..')
1810
+
1811
+ if min.nil? || max.nil?
1812
+ STDERR.puts 'Malformed user input. '\
1813
+ "Parameters should be 'min..max':"
1814
+ STDERR.puts " #{key}: #{val}"
1815
+ exit(-1)
1816
+ end
1817
+
1818
+ if type == 'range'
1819
+ exp = INT_EXP
1820
+ min = min.to_i
1821
+ max = max.to_i
1822
+
1823
+ header += "Integer in the range [#{min}..#{max}]: "
1824
+ else
1825
+ exp = FLOAT_EXP
1826
+ min = min.to_f
1827
+ max = max.to_f
1828
+
1829
+ header += "Float in the range [#{min}..#{max}]: "
1830
+ end
1831
+
1832
+ begin
1833
+ print header
1834
+ answer = STDIN.readline.chop
1835
+
1836
+ answer = initial if answer == ''
1837
+
1838
+ noanswer = (answer == '') && optional
1839
+ end while !noanswer && ((answer =~ exp) == nil ||
1840
+ answer.to_f < min || answer.to_f > max)
1841
+
1842
+ if noanswer
1843
+ next
1844
+ end
1845
+
1846
+ when 'list'
1847
+ options = params.split(',')
1848
+
1849
+ options.each_with_index do |opt, i|
1850
+ puts " #{i} #{opt}"
1851
+ end
1852
+
1853
+ puts
1854
+
1855
+ header += 'Please type the selection number: '
1856
+
1857
+ begin
1858
+ print header
1859
+ answer = STDIN.readline.chop
1860
+
1861
+ if answer == ''
1862
+ answer = initial
1863
+ else
1864
+ answer = options[answer.to_i]
1865
+ end
1866
+
1867
+ noanswer = ((answer == '') && optional)
1868
+ end while !noanswer && !options.include?(answer)
1869
+
1870
+ if noanswer
1871
+ next
1872
+ end
1873
+
1874
+ when 'fixed'
1875
+ puts " Fixed value of (#{initial}). Cannot be changed"
1876
+ answer = initial
1877
+
1878
+ else
1879
+ STDERR.puts 'Wrong type for user input:'
1880
+ STDERR.puts " #{key}: #{val}"
1881
+ exit(-1)
1882
+ end
1883
+
1884
+ answers[key] = answer
1885
+ end
1886
+
1887
+ answers
1888
+ end
1889
+
1699
1890
  end