opennebula-cli 5.12.4 → 5.13.80.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/bin/oneacct +9 -4
  3. data/bin/oneacl +8 -5
  4. data/bin/onecluster +10 -7
  5. data/bin/onedatastore +10 -7
  6. data/bin/oneflow +85 -13
  7. data/bin/oneflow-template +45 -8
  8. data/bin/onegroup +10 -7
  9. data/bin/onehook +10 -7
  10. data/bin/onehost +8 -5
  11. data/bin/oneimage +99 -8
  12. data/bin/onemarket +10 -7
  13. data/bin/onemarketapp +117 -10
  14. data/bin/onesecgroup +13 -7
  15. data/bin/oneshowback +23 -10
  16. data/bin/onetemplate +16 -9
  17. data/bin/oneuser +30 -7
  18. data/bin/onevcenter +9 -4
  19. data/bin/onevdc +10 -7
  20. data/bin/onevm +147 -12
  21. data/bin/onevmgroup +13 -7
  22. data/bin/onevnet +8 -5
  23. data/bin/onevntemplate +11 -7
  24. data/bin/onevrouter +10 -7
  25. data/bin/onezone +10 -7
  26. data/lib/cli_helper.rb +5 -7
  27. data/lib/command_parser.rb +1 -1
  28. data/lib/one_helper.rb +414 -46
  29. data/lib/one_helper/oneacct_helper.rb +8 -17
  30. data/lib/one_helper/oneacl_helper.rb +1 -1
  31. data/lib/one_helper/onecluster_helper.rb +1 -1
  32. data/lib/one_helper/onedatastore_helper.rb +11 -1
  33. data/lib/one_helper/oneflow_helper.rb +20 -5
  34. data/lib/one_helper/oneflowtemplate_helper.rb +28 -2
  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 +1 -5
  38. data/lib/one_helper/oneimage_helper.rb +11 -7
  39. data/lib/one_helper/onemarket_helper.rb +1 -1
  40. data/lib/one_helper/onemarketapp_helper.rb +494 -96
  41. data/lib/one_helper/onequota_helper.rb +1 -1
  42. data/lib/one_helper/onesecgroup_helper.rb +1 -1
  43. data/lib/one_helper/onetemplate_helper.rb +16 -4
  44. data/lib/one_helper/oneuser_helper.rb +11 -3
  45. data/lib/one_helper/onevcenter_helper.rb +176 -146
  46. data/lib/one_helper/onevdc_helper.rb +1 -1
  47. data/lib/one_helper/onevm_helper.rb +4 -3
  48. data/lib/one_helper/onevmgroup_helper.rb +1 -1
  49. data/lib/one_helper/onevnet_helper.rb +1 -1
  50. data/lib/one_helper/onevntemplate_helper.rb +1 -1
  51. data/lib/one_helper/onevrouter_helper.rb +1 -20
  52. data/lib/one_helper/onezone_helper.rb +12 -1
  53. data/share/schemas/xsd/acct.xsd +179 -0
  54. data/share/schemas/xsd/acl_pool.xsd +22 -0
  55. data/share/schemas/xsd/api_info.xsd +43 -0
  56. data/share/schemas/xsd/cluster.xsd +34 -0
  57. data/share/schemas/xsd/cluster_pool.xsd +12 -0
  58. data/share/schemas/xsd/datastore.xsd +67 -0
  59. data/share/schemas/xsd/datastore_pool.xsd +12 -0
  60. data/share/schemas/xsd/document.xsd +42 -0
  61. data/share/schemas/xsd/document_pool.xsd +12 -0
  62. data/share/schemas/xsd/group.xsd +179 -0
  63. data/share/schemas/xsd/group_pool.xsd +194 -0
  64. data/share/schemas/xsd/hook.xsd +59 -0
  65. data/share/schemas/xsd/hook_message_api.xsd +14 -0
  66. data/share/schemas/xsd/hook_message_retry.xsd +12 -0
  67. data/share/schemas/xsd/hook_message_state.xsd +25 -0
  68. data/share/schemas/xsd/hook_pool.xsd +12 -0
  69. data/share/schemas/xsd/host.xsd +164 -0
  70. data/share/schemas/xsd/host_pool.xsd +12 -0
  71. data/share/schemas/xsd/image.xsd +123 -0
  72. data/share/schemas/xsd/image_pool.xsd +12 -0
  73. data/share/schemas/xsd/index.xsd +49 -0
  74. data/share/schemas/xsd/marketplace.xsd +44 -0
  75. data/share/schemas/xsd/marketplace_pool.xsd +12 -0
  76. data/share/schemas/xsd/marketplaceapp.xsd +56 -0
  77. data/share/schemas/xsd/marketplaceapp_pool.xsd +12 -0
  78. data/share/schemas/xsd/opennebula_configuration.xsd +412 -0
  79. data/share/schemas/xsd/raftstatus.xsd +18 -0
  80. data/share/schemas/xsd/security_group.xsd +74 -0
  81. data/share/schemas/xsd/security_group_pool.xsd +12 -0
  82. data/share/schemas/xsd/showback.xsd +29 -0
  83. data/share/schemas/xsd/user.xsd +186 -0
  84. data/share/schemas/xsd/user_pool.xsd +201 -0
  85. data/share/schemas/xsd/vdc.xsd +76 -0
  86. data/share/schemas/xsd/vdc_pool.xsd +12 -0
  87. data/share/schemas/xsd/vm.xsd +251 -0
  88. data/share/schemas/xsd/vm_group.xsd +59 -0
  89. data/share/schemas/xsd/vm_group_pool.xsd +12 -0
  90. data/share/schemas/xsd/vm_pool.xsd +114 -0
  91. data/share/schemas/xsd/vmtemplate.xsd +52 -0
  92. data/share/schemas/xsd/vmtemplate_pool.xsd +12 -0
  93. data/share/schemas/xsd/vnet.xsd +137 -0
  94. data/share/schemas/xsd/vnet_pool.xsd +85 -0
  95. data/share/schemas/xsd/vntemplate.xsd +50 -0
  96. data/share/schemas/xsd/vntemplate_pool.xsd +12 -0
  97. data/share/schemas/xsd/vrouter.xsd +49 -0
  98. data/share/schemas/xsd/vrouter_pool.xsd +12 -0
  99. data/share/schemas/xsd/zone.xsd +40 -0
  100. data/share/schemas/xsd/zone_pool.xsd +36 -0
  101. metadata +75 -14
  102. data/lib/one_helper/oneprovision_helper.rb +0 -362
data/bin/onesecgroup CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2021, 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 #
@@ -27,9 +27,12 @@ else
27
27
  end
28
28
 
29
29
  if File.directory?(GEMS_LOCATION)
30
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
31
- require 'rubygems'
32
- Gem.use_paths(File.realpath(GEMS_LOCATION))
30
+ real_gems_path = File.realpath(GEMS_LOCATION)
31
+ if !defined?(Gem) || Gem.path != [real_gems_path]
32
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
35
+ end
33
36
  end
34
37
 
35
38
  $LOAD_PATH << RUBY_LIB_LOCATION
@@ -53,8 +56,8 @@ CommandParser::CmdParser.new(ARGV) do
53
56
  ########################################################################
54
57
  set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
55
58
 
56
- list_options = CLIHelper::OPTIONS
57
- list_options << OpenNebulaHelper::XML
59
+ list_options = CLIHelper::OPTIONS
60
+ list_options += OpenNebulaHelper::FORMAT
58
61
  list_options << OpenNebulaHelper::NUMERIC
59
62
  list_options << OpenNebulaHelper::DESCRIBE
60
63
 
@@ -221,7 +224,10 @@ CommandParser::CmdParser.new(ARGV) do
221
224
  Shows information for the given Security Group
222
225
  EOT
223
226
 
224
- command :show, show_desc, :secgroupid, :options => OpenNebulaHelper::XML do
227
+ command :show,
228
+ show_desc,
229
+ :secgroupid,
230
+ :options => OpenNebulaHelper::FORMAT do
225
231
  helper.show_resource(args[0], options)
226
232
  end
227
233
  end
data/bin/oneshowback CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2021, 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 #
@@ -27,9 +27,12 @@ else
27
27
  end
28
28
 
29
29
  if File.directory?(GEMS_LOCATION)
30
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
31
- require 'rubygems'
32
- Gem.use_paths(File.realpath(GEMS_LOCATION))
30
+ real_gems_path = File.realpath(GEMS_LOCATION)
31
+ if !defined?(Gem) || Gem.path != [real_gems_path]
32
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
35
+ end
33
36
  end
34
37
 
35
38
  $LOAD_PATH << RUBY_LIB_LOCATION
@@ -92,27 +95,31 @@ CommandParser::CmdParser.new(ARGV) do
92
95
 
93
96
  pool = OpenNebula::VirtualMachinePool.new(helper.client)
94
97
 
95
- if options[:json] || options[:xml]
98
+ if options[:json] || options[:xml] || options[:yaml]
96
99
  xml_str = pool.showback_xml(filter_flag, common_opts)
97
100
  if OpenNebula.is_error?(xml_str)
98
101
  puts xml_str.message
99
102
  exit(-1)
100
103
  end
101
104
 
102
- if options[:json]
103
- xmldoc = XMLElement.new
104
- xmldoc.initialize_xml(xml_str, 'SHOWBACK_RECORDS')
105
+ xmldoc = XMLElement.new
106
+ xmldoc.initialize_xml(xml_str, 'SHOWBACK_RECORDS')
105
107
 
108
+ if options[:json]
106
109
  puts JSON.pretty_generate(xmldoc.to_hash)
110
+ elsif options[:yaml]
111
+ puts xmldoc.to_hash.to_yaml(:indent => 4)
107
112
  elsif options[:xml]
108
113
  puts xml_str
109
114
  end
110
115
  else
116
+ # rubocop:disable Naming/VariableNumber
111
117
  order_by = {}
112
118
  if !options[:csv]
113
119
  order_by[:order_by_1] = 'YEAR'
114
120
  order_by[:order_by_2] = 'MONTH'
115
121
  end
122
+ # rubocop:enable Naming/VariableNumber
116
123
 
117
124
  data_hash = pool.showback(filter_flag,
118
125
  common_opts.merge(order_by))
@@ -172,8 +179,14 @@ CommandParser::CmdParser.new(ARGV) do
172
179
  end_year)
173
180
 
174
181
  if OpenNebula.is_error?(rc)
175
- warn rc.message
176
- exit(-1)
182
+ if rc.message.include? 'ReadTimeout'
183
+ warn 'Showback calculation takes too long, '\
184
+ 'continuing in background'
185
+ exit_code 0
186
+ else
187
+ warn rc.message
188
+ exit(-1)
189
+ end
177
190
  else
178
191
  puts rc
179
192
  exit_code 0
data/bin/onetemplate CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2021, 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 #
@@ -27,9 +27,12 @@ else
27
27
  end
28
28
 
29
29
  if File.directory?(GEMS_LOCATION)
30
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
31
- require 'rubygems'
32
- Gem.use_paths(File.realpath(GEMS_LOCATION))
30
+ real_gems_path = File.realpath(GEMS_LOCATION)
31
+ if !defined?(Gem) || Gem.path != [real_gems_path]
32
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
35
+ end
33
36
  end
34
37
 
35
38
  $LOAD_PATH << RUBY_LIB_LOCATION
@@ -78,8 +81,8 @@ CommandParser::CmdParser.new(ARGV) do
78
81
  ########################################################################
79
82
  set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
80
83
 
81
- list_options = CLIHelper::OPTIONS
82
- list_options << OpenNebulaHelper::XML
84
+ list_options = CLIHelper::OPTIONS
85
+ list_options += OpenNebulaHelper::FORMAT
83
86
  list_options << OpenNebulaHelper::NUMERIC
84
87
  list_options << OpenNebulaHelper::DESCRIBE
85
88
 
@@ -261,8 +264,11 @@ CommandParser::CmdParser.new(ARGV) do
261
264
  if !user_inputs
262
265
  user_inputs = OneTemplateHelper.get_user_inputs(t.to_hash)
263
266
  else
264
- optionals = OneTemplateHelper.get_user_inputs(t.to_hash,
265
- true)
267
+ optionals = OneTemplateHelper.get_user_inputs(
268
+ t.to_hash,
269
+ options[:user_inputs_keys]
270
+ )
271
+
266
272
  user_inputs = user_inputs + "\n" + optionals
267
273
  end
268
274
 
@@ -366,7 +372,8 @@ CommandParser::CmdParser.new(ARGV) do
366
372
  EOT
367
373
 
368
374
  command :show, show_desc, :templateid,
369
- :options => [OpenNebulaHelper::XML, OneTemplateHelper::EXTENDED] do
375
+ :options => [OpenNebulaHelper::FORMAT,
376
+ OneTemplateHelper::EXTENDED] do
370
377
  helper.show_resource(args[0], options)
371
378
  end
372
379
 
data/bin/oneuser CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2021, 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 #
@@ -27,9 +27,12 @@ else
27
27
  end
28
28
 
29
29
  if File.directory?(GEMS_LOCATION)
30
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
31
- require 'rubygems'
32
- Gem.use_paths(File.realpath(GEMS_LOCATION))
30
+ real_gems_path = File.realpath(GEMS_LOCATION)
31
+ if !defined?(Gem) || Gem.path != [real_gems_path]
32
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
35
+ end
33
36
  end
34
37
 
35
38
  $LOAD_PATH << RUBY_LIB_LOCATION
@@ -68,8 +71,8 @@ CommandParser::CmdParser.new(ARGV) do
68
71
  ########################################################################
69
72
  set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
70
73
 
71
- list_options = CLIHelper::OPTIONS
72
- list_options << OpenNebulaHelper::XML
74
+ list_options = CLIHelper::OPTIONS
75
+ list_options += OpenNebulaHelper::FORMAT
73
76
  list_options << OpenNebulaHelper::NUMERIC
74
77
  list_options << OpenNebulaHelper::DESCRIBE
75
78
 
@@ -559,7 +562,7 @@ CommandParser::CmdParser.new(ARGV) do
559
562
  EOT
560
563
 
561
564
  command :show, show_desc, [:userid, nil],
562
- :options => OpenNebulaHelper::XML do
565
+ :options => OpenNebulaHelper::FORMAT do
563
566
  user = args[0] || OpenNebula::User::SELF
564
567
  helper.show_resource(user, options)
565
568
  end
@@ -801,4 +804,24 @@ CommandParser::CmdParser.new(ARGV) do
801
804
  user.login(username, '', 0)
802
805
  end
803
806
  end
807
+
808
+ enable_desc = <<-EOT.unindent
809
+ Enables the given User
810
+ EOT
811
+
812
+ command :enable, enable_desc, [:range, :userid_list] do
813
+ helper.perform_actions(args[0], options, 'enabled') do |user|
814
+ user.enable
815
+ end
816
+ end
817
+
818
+ disable_desc = <<-EOT.unindent
819
+ Disables the given User
820
+ EOT
821
+
822
+ command :disable, disable_desc, [:range, :userid_list] do
823
+ helper.perform_actions(args[0], options, 'disabled') do |user|
824
+ user.disable
825
+ end
826
+ end
804
827
  end
data/bin/onevcenter CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2021, 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 #
@@ -29,9 +29,12 @@ else
29
29
  end
30
30
 
31
31
  if File.directory?(GEMS_LOCATION)
32
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
- require 'rubygems'
34
- Gem.use_paths(File.realpath(GEMS_LOCATION))
32
+ real_gems_path = File.realpath(GEMS_LOCATION)
33
+ if !defined?(Gem) || Gem.path != [real_gems_path]
34
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
35
+ require 'rubygems'
36
+ Gem.use_paths(real_gems_path)
37
+ end
35
38
  end
36
39
 
37
40
  $LOAD_PATH << RUBY_LIB_LOCATION
@@ -155,6 +158,7 @@ CommandParser::CmdParser.new(ARGV) do
155
158
  begin
156
159
  args = helper.parse_opts(options)
157
160
  args[:filter] = true
161
+ args[:short] = true
158
162
  vi_client = VCenterDriver::VIClient.new_from_host(options[:host])
159
163
  importer = VCenterDriver::VcImporter
160
164
  .new_child(helper.client, vi_client, options[:object])
@@ -185,6 +189,7 @@ CommandParser::CmdParser.new(ARGV) do
185
189
  begin
186
190
  args = helper.parse_opts(options)
187
191
  args[:filter] = false
192
+ args[:short] = true
188
193
  vi_client = VCenterDriver::VIClient.new_from_host(options[:host])
189
194
  importer = VCenterDriver::VcImporter
190
195
  .new_child(helper.client, vi_client, options[:object])
data/bin/onevdc CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2021, 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 #
@@ -27,9 +27,12 @@ else
27
27
  end
28
28
 
29
29
  if File.directory?(GEMS_LOCATION)
30
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
31
- require 'rubygems'
32
- Gem.use_paths(File.realpath(GEMS_LOCATION))
30
+ real_gems_path = File.realpath(GEMS_LOCATION)
31
+ if !defined?(Gem) || Gem.path != [real_gems_path]
32
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
35
+ end
33
36
  end
34
37
 
35
38
  $LOAD_PATH << RUBY_LIB_LOCATION
@@ -53,8 +56,8 @@ CommandParser::CmdParser.new(ARGV) do
53
56
  ########################################################################
54
57
  set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
55
58
 
56
- list_options = CLIHelper::OPTIONS
57
- list_options << OpenNebulaHelper::XML
59
+ list_options = CLIHelper::OPTIONS
60
+ list_options += OpenNebulaHelper::FORMAT
58
61
  list_options << OpenNebulaHelper::NUMERIC
59
62
  list_options << OpenNebulaHelper::DESCRIBE
60
63
 
@@ -297,7 +300,7 @@ CommandParser::CmdParser.new(ARGV) do
297
300
  Shows information for the given VDC
298
301
  EOT
299
302
 
300
- command :show, show_desc, :vdcid, :options => OpenNebulaHelper::XML do
303
+ command :show, show_desc, :vdcid, :options => OpenNebulaHelper::FORMAT do
301
304
  helper.show_resource(args[0], options)
302
305
  end
303
306
  end
data/bin/onevm CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2021, 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 #
@@ -27,9 +27,12 @@ else
27
27
  end
28
28
 
29
29
  if File.directory?(GEMS_LOCATION)
30
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
31
- require 'rubygems'
32
- Gem.use_paths(File.realpath(GEMS_LOCATION))
30
+ real_gems_path = File.realpath(GEMS_LOCATION)
31
+ if !defined?(Gem) || Gem.path != [real_gems_path]
32
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
35
+ end
33
36
  end
34
37
 
35
38
  $LOAD_PATH << RUBY_LIB_LOCATION
@@ -37,6 +40,8 @@ $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
37
40
 
38
41
  require 'command_parser'
39
42
  require 'one_helper/onevm_helper'
43
+ require 'one_helper/onedatastore_helper'
44
+ require 'opennebula/virtual_machine_ext'
40
45
 
41
46
  CommandParser::CmdParser.new(ARGV) do
42
47
  usage '`onevm` <command> [<args>] [<options>]'
@@ -176,6 +181,32 @@ CommandParser::CmdParser.new(ARGV) do
176
181
  :description => 'lock all actions'
177
182
  }
178
183
 
184
+ LOGGER = {
185
+ :name => 'logger',
186
+ :large => '--logger logger',
187
+ :format => String,
188
+ :description => 'Set logger to STDOUT or FILE'
189
+ }
190
+
191
+ KEEP = {
192
+ :name => 'keep',
193
+ :large => '--keep-backup',
194
+ :description => 'Keep previous backup when creating a new one'
195
+ }
196
+
197
+ ONESHOT = {
198
+ :name => 'oneshot',
199
+ :large => '--oneshot',
200
+ :description => 'Take an snapshot of the VM without saving backup info'
201
+ }
202
+
203
+ MARKET = {
204
+ :name => 'market',
205
+ :large => '--market market_id',
206
+ :format => Integer,
207
+ :description => 'Market to save oneshot'
208
+ }
209
+
179
210
  ########################################################################
180
211
  # Global Options
181
212
  ########################################################################
@@ -1152,7 +1183,7 @@ CommandParser::CmdParser.new(ARGV) do
1152
1183
  EOT
1153
1184
 
1154
1185
  command :show, show_desc, :vmid,
1155
- :options => [OpenNebulaHelper::XML,
1186
+ :options => [OpenNebulaHelper::FORMAT,
1156
1187
  OpenNebulaHelper::DECRYPT,
1157
1188
  OneVMHelper::ALL_TEMPLATE] do
1158
1189
  helper.show_resource(args[0], options)
@@ -1210,7 +1241,11 @@ CommandParser::CmdParser.new(ARGV) do
1210
1241
 
1211
1242
  command :save, save_desc, :vmid, :name, :options => [PERSISTENT] do
1212
1243
  helper.perform_action(args[0], options, 'Saving VM') do |vm|
1213
- res = vm.save_as_template(args[1], options[:persistent])
1244
+ vm.extend(VirtualMachineExt)
1245
+
1246
+ res = vm.save_as_template(args[1],
1247
+ '',
1248
+ :persistent => options[:persistent])
1214
1249
 
1215
1250
  if !OpenNebula.is_error?(res)
1216
1251
  puts "Template ID: #{res}"
@@ -1221,15 +1256,16 @@ CommandParser::CmdParser.new(ARGV) do
1221
1256
  end
1222
1257
 
1223
1258
  updateconf_desc = <<-EOT.unindent
1224
- Updates the configuration of a VM. The VM cannot be in an active (running)
1225
- state, valid states are: pending, failure, poweroff, undeploy, hold or
1226
- cloning.
1259
+ Updates the configuration of a VM. Valid states are: running, pending,
1260
+ failure, poweroff, undeploy, hold or cloning.
1261
+ In running state only changes in CONTEXT take effect immediately,
1262
+ other values may need a VM restart.
1227
1263
 
1228
1264
  This command accepts a template file or opens an editor, the full list of
1229
1265
  configuration attributes are:
1230
1266
 
1231
- OS = ["ARCH", "MACHINE", "KERNEL", "INITRD", "BOOTLOADER", "BOOT"]
1232
- FEATURES = ["ACPI", "PAE", "APIC", "LOCALTIME", "HYPERV", "GUEST_AGENT"]
1267
+ OS = ["ARCH", "MACHINE", "KERNEL", "INITRD", "BOOTLOADER", "BOOT", "UUID"]
1268
+ FEATURES = ["ACPI", "PAE", "APIC", "LOCALTIME", "HYPERV", "GUEST_AGENT", "IOTHREADS"]
1233
1269
  INPUT = ["TYPE", "BUS"]
1234
1270
  GRAPHICS = ["TYPE", "LISTEN", "PASSWD", "KEYMAP" ]
1235
1271
  RAW = ["DATA", "DATA_VMX", "TYPE"]
@@ -1271,7 +1307,7 @@ CommandParser::CmdParser.new(ARGV) do
1271
1307
  lock_desc = <<-EOT.unindent
1272
1308
  Locks a VM with differents levels for lock any actions with this VM, show and
1273
1309
  monitoring never will be locked.
1274
- Aalid states are: All.
1310
+ Valid states are: All.
1275
1311
  EOT
1276
1312
 
1277
1313
  command :lock, lock_desc, :vmid,
@@ -1383,6 +1419,105 @@ CommandParser::CmdParser.new(ARGV) do
1383
1419
  0
1384
1420
  end
1385
1421
 
1422
+ backup_vm_desc = <<-EOT.unindent
1423
+ Creates a VM backup and stores it in the marketplace
1424
+ EOT
1425
+
1426
+ command :backup,
1427
+ backup_vm_desc,
1428
+ :vmid,
1429
+ :options => [LOGGER, KEEP, ONESHOT, MARKET] do
1430
+ require 'logger'
1431
+
1432
+ if options.key?(:oneshot) && !options.key?(:market)
1433
+ STDERR.puts 'ERROR: no market given'
1434
+ exit(-1)
1435
+ end
1436
+
1437
+ helper.perform_action(args[0], options, 'Backup') do |vm|
1438
+ vm.extend(OpenNebula::VirtualMachineExt)
1439
+
1440
+ # If logger is specified use it, if not use STDOUT
1441
+ options[:logger].nil? ? log_to = STDOUT : log_to = options[:logger]
1442
+
1443
+ # Read user options
1444
+ keep = options.key?(:keep)
1445
+ logger = Logger.new(log_to)
1446
+ format = '%Y-%m-%d %H:%M:%S'
1447
+
1448
+ logger.formatter = proc do |severity, datetime, _p, msg|
1449
+ "#{datetime.strftime(format)} #{severity.ljust(5)} : #{msg}\n"
1450
+ end
1451
+
1452
+ if options.key?(:oneshot)
1453
+ binfo = {}
1454
+ binfo[:name] = "VM #{vm.id} BACKUP - " \
1455
+ "#{Time.now.strftime('%Y%m%d_%k%M')}"
1456
+ binfo[:freq] = 1
1457
+ binfo[:last] = Time.now.to_i - 100
1458
+ binfo[:market] = options[:market]
1459
+ end
1460
+
1461
+ begin
1462
+ rc = vm.backup(keep, logger, binfo)
1463
+
1464
+ if OpenNebula.is_error?(rc)
1465
+ STDERR.puts rc.message
1466
+ exit(-1)
1467
+ else
1468
+ 0
1469
+ end
1470
+ rescue StandardError => e
1471
+ STDERR.puts e
1472
+ exit(-1)
1473
+ end
1474
+ end
1475
+ end
1476
+
1477
+ restore_vm_desc = <<-EOT.unindent
1478
+ Restores a VM from a previous backup
1479
+ EOT
1480
+
1481
+ command :restore,
1482
+ restore_vm_desc,
1483
+ :vmid,
1484
+ :options => [OneDatastoreHelper::DATASTORE, LOGGER] do
1485
+ require 'logger'
1486
+
1487
+ unless options[:datastore]
1488
+ STDERR.puts 'ERROR: no datastore given'
1489
+ exit(-1)
1490
+ end
1491
+
1492
+ helper.perform_action(args[0], options, 'Restore') do |vm|
1493
+ vm.extend(OpenNebula::VirtualMachineExt)
1494
+
1495
+ # If logger is specified use it, if not use STDOUT
1496
+ options[:logger].nil? ? log_to = STDOUT : log_to = options[:logger]
1497
+ logger = Logger.new(log_to)
1498
+ format = '%Y-%m-%d %H:%M:%S'
1499
+
1500
+ logger.formatter = proc do |severity, datetime, _p, msg|
1501
+ "#{datetime.strftime(format)} #{severity.ljust(5)} : #{msg}\n"
1502
+ end
1503
+
1504
+ begin
1505
+ rc = vm.restore(options[:datastore], logger)
1506
+
1507
+ if OpenNebula.is_error?(rc)
1508
+ STDERR.puts rc.message
1509
+ exit(-1)
1510
+ else
1511
+ puts "ID: #{rc}"
1512
+ 0
1513
+ end
1514
+ rescue StandardError => e
1515
+ STDERR.puts e
1516
+ exit(-1)
1517
+ end
1518
+ end
1519
+ end
1520
+
1386
1521
  # Deprecated commands
1387
1522
 
1388
1523
  deprecated_command(:shutdown, 'terminate')