opennebula-cli 5.6.2 → 5.7.80.pre

Sign up to get free protection for your applications and to get access to all the features.
data/bin/onevm CHANGED
@@ -16,22 +16,22 @@
16
16
  # limitations under the License. #
17
17
  #--------------------------------------------------------------------------- #
18
18
 
19
- ONE_LOCATION=ENV["ONE_LOCATION"]
19
+ ONE_LOCATION = ENV['ONE_LOCATION']
20
20
 
21
21
  if !ONE_LOCATION
22
- RUBY_LIB_LOCATION="/usr/lib/one/ruby"
22
+ RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
23
23
  else
24
- RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
24
+ RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
25
25
  end
26
26
 
27
- $: << RUBY_LIB_LOCATION
28
- $: << RUBY_LIB_LOCATION+"/cli"
27
+ $LOAD_PATH << RUBY_LIB_LOCATION
28
+ $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
29
29
 
30
30
  require 'command_parser'
31
31
  require 'one_helper/onevm_helper'
32
32
 
33
- cmd=CommandParser::CmdParser.new(ARGV) do
34
- usage "`onevm` <command> [<args>] [<options>]"
33
+ CommandParser::CmdParser.new(ARGV) do
34
+ usage '`onevm` <command> [<args>] [<options>]'
35
35
  version OpenNebulaHelper::ONE_VERSION
36
36
 
37
37
  helper = OneVMHelper.new
@@ -40,149 +40,158 @@ cmd=CommandParser::CmdParser.new(ARGV) do
40
40
  helper.set_client(options)
41
41
  end
42
42
 
43
- TYPE={
44
- :name => "type",
45
- :short => "-t type",
46
- :large => "--type type",
43
+ TYPE = {
44
+ :name => 'type',
45
+ :short => '-t type',
46
+ :large => '--type type',
47
47
  :format => String,
48
- :description => "Type of the new Image"
48
+ :description => 'Type of the new Image'
49
49
  }
50
50
 
51
- TARGET={
52
- :name => "target",
53
- :short => "-t target",
54
- :large => "--target target",
51
+ TARGET = {
52
+ :name => 'target',
53
+ :short => '-t target',
54
+ :large => '--target target',
55
55
  :format => String,
56
- :description => "Device where the image will be attached"
56
+ :description => 'Device where the image will be attached'
57
57
  }
58
58
 
59
- PREFIX={
60
- :name => "prefix",
61
- :large => "--prefix prefix",
59
+ PREFIX = {
60
+ :name => 'prefix',
61
+ :large => '--prefix prefix',
62
62
  :format => String,
63
- :description => "Overrides the DEV_PREFIX of the image"
63
+ :description => 'Overrides the DEV_PREFIX of the image'
64
64
  }
65
65
 
66
- CACHE={
67
- :name => "cache",
68
- :large => "--cache cache_mode",
66
+ CACHE = {
67
+ :name => 'cache',
68
+ :large => '--cache cache_mode',
69
69
  :format => String,
70
- :description => "Hypervisor cache mode: default, none, writethrough,"<<
71
- " writeback, directsync or unsafe. (Only KVM driver)"
70
+ :description => 'Hypervisor cache mode: default, none, writethrough,'\
71
+ ' writeback, directsync or unsafe. (Only KVM driver)'
72
72
  }
73
73
 
74
- DISCARD={
75
- :name => "discard",
76
- :large => "--discard discard_mode",
74
+ DISCARD = {
75
+ :name => 'discard',
76
+ :large => '--discard discard_mode',
77
77
  :format => String,
78
- :description => "Hypervisor discard mode: ignore or unmap."<<
79
- " (Only KVM driver)"
78
+ :description => 'Hypervisor discard mode: ignore or unmap.'\
79
+ ' (Only KVM driver)'
80
80
  }
81
81
 
82
- ENFORCE={
83
- :name => "enforce",
84
- :short => "-e",
85
- :large => "--enforce",
86
- :description => "Enforce that the host capacity is not exceeded"
82
+ ENFORCE = {
83
+ :name => 'enforce',
84
+ :short => '-e',
85
+ :large => '--enforce',
86
+ :description => 'Enforce that the host capacity is not exceeded'
87
87
  }
88
88
 
89
- SUCCESS={
90
- :name => "success",
91
- :large => "--success",
92
- :description => "Recover a VM by succeeding the pending action"
89
+ SUCCESS = {
90
+ :name => 'success',
91
+ :large => '--success',
92
+ :description => 'Recover a VM by succeeding the pending action'
93
93
  }
94
94
 
95
- FAILURE={
96
- :name => "failure",
97
- :large => "--failure",
98
- :description => "Recover a VM by failing the pending action"
95
+ FAILURE = {
96
+ :name => 'failure',
97
+ :large => '--failure',
98
+ :description => 'Recover a VM by failing the pending action'
99
99
  }
100
100
 
101
- RETRY={
102
- :name => "retry",
103
- :large => "--retry",
104
- :description => "Recover a VM by retrying the last failed action"
101
+ RETRY = {
102
+ :name => 'retry',
103
+ :large => '--retry',
104
+ :description => 'Recover a VM by retrying the last failed action'
105
105
  }
106
106
 
107
- DELETE={
108
- :name => "delete",
109
- :large => "--delete",
110
- :description => "No recover action possible, delete the VM"
107
+ DELETE = {
108
+ :name => 'delete',
109
+ :large => '--delete',
110
+ :description => 'No recover action possible, delete the VM'
111
111
  }
112
112
 
113
- RECREATE={
114
- :name => "recreate",
115
- :large => "--recreate",
116
- :description => "No recover action possible, delete and recreate the VM"
113
+ RECREATE = {
114
+ :name => 'recreate',
115
+ :large => '--recreate',
116
+ :description => 'No recover action possible, delete and recreate the VM'
117
117
  }
118
118
 
119
- INTERACTIVE={
120
- :name => "interactive",
121
- :large => "--interactive",
122
- :description => "Enables interactive recovery. Only works alongside "<<
123
- " the --retry option."
119
+ DELETE_DB = {
120
+ :name => 'deletedb',
121
+ :large => '--delete-db',
122
+ :description => 'No recover action possible, delete the VM from the '\
123
+ 'DB. It does not trigger any action on the hypervisor'
124
124
  }
125
125
 
126
- SNAP={
127
- :name => "snapshot",
128
- :short => "-s snapshot",
129
- :large => "--snapshot snapshot",
126
+ INTERACTIVE = {
127
+ :name => 'interactive',
128
+ :large => '--interactive',
129
+ :description => 'Enables interactive recovery. Only works alongside '\
130
+ ' the --retry option.'
131
+ }
132
+
133
+ SNAP = {
134
+ :name => 'snapshot',
135
+ :short => '-s snapshot',
136
+ :large => '--snapshot snapshot',
130
137
  :format => String,
131
- :description => "ID of the Snapshot to save."
138
+ :description => 'ID of the Snapshot to save.'
132
139
  }
133
140
 
134
- PERSISTENT={
135
- :name => "persistent",
136
- :large => "--persistent",
137
- :description => "Make the new images persistent"
141
+ PERSISTENT = {
142
+ :name => 'persistent',
143
+ :large => '--persistent',
144
+ :description => 'Make the new images persistent'
138
145
  }
139
146
 
140
- USE={
141
- :name => "use",
142
- :large => "--use",
143
- :description => "lock use actions"
147
+ USE = {
148
+ :name => 'use',
149
+ :large => '--use',
150
+ :description => 'lock use actions'
144
151
  }
145
152
 
146
- MANAGE={
147
- :name => "manage",
148
- :large => "--manage",
149
- :description => "lock manage actions"
153
+ MANAGE = {
154
+ :name => 'manage',
155
+ :large => '--manage',
156
+ :description => 'lock manage actions'
150
157
  }
151
158
 
152
- ADMIN={
153
- :name => "admin",
154
- :large => "--admin",
155
- :description => "lock admin actions"
159
+ ADMIN = {
160
+ :name => 'admin',
161
+ :large => '--admin',
162
+ :description => 'lock admin actions'
156
163
  }
157
164
 
158
- ALL={
159
- :name => "all",
160
- :large => "--all",
161
- :description => "lock all actions"
165
+ ALL = {
166
+ :name => 'all',
167
+ :large => '--all',
168
+ :description => 'lock all actions'
162
169
  }
163
170
 
164
171
  ########################################################################
165
172
  # Global Options
166
173
  ########################################################################
167
- set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
174
+ set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
168
175
 
169
176
  ########################################################################
170
177
  # Formatters for arguments
171
178
  ########################################################################
172
- set :format, :hostid, OpenNebulaHelper.rname_to_id_desc("HOST") do |arg|
173
- OpenNebulaHelper.rname_to_id(arg, "HOST")
179
+ set :format, :hostid, OpenNebulaHelper.rname_to_id_desc('HOST') do |arg|
180
+ OpenNebulaHelper.rname_to_id(arg, 'HOST')
174
181
  end
175
182
 
176
- set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
177
- OpenNebulaHelper.rname_to_id(arg, "GROUP")
183
+ set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
184
+ OpenNebulaHelper.rname_to_id(arg, 'GROUP')
178
185
  end
179
186
 
180
- set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
181
- OpenNebulaHelper.rname_to_id(arg, "USER")
187
+ set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
188
+ OpenNebulaHelper.rname_to_id(arg, 'USER')
182
189
  end
183
190
 
184
- set :format, :datastoreid, OpenNebulaHelper.rname_to_id_desc("DATASTORE") do |arg|
185
- OpenNebulaHelper.rname_to_id(arg, "DATASTORE")
191
+ set :format,
192
+ :datastoreid,
193
+ OpenNebulaHelper.rname_to_id_desc('DATASTORE') do |arg|
194
+ OpenNebulaHelper.rname_to_id(arg, 'DATASTORE')
186
195
  end
187
196
 
188
197
  set :format, :vmid, OneVMHelper.to_id_desc do |arg|
@@ -199,15 +208,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
199
208
  helper.filterflag_to_i(arg)
200
209
  end
201
210
 
202
- set :format, :diskid, "Integer" do |arg|
211
+ set :format, :diskid, 'Integer' do |arg|
203
212
  format_int(arg)
204
213
  end
205
214
 
206
- set :format, :size, "Disk size in MiB" do |arg|
215
+ set :format, :size, 'Disk size in MiB' do |arg|
207
216
  OpenNebulaHelper.size_in_mb(arg)
208
217
  end
209
218
 
210
- format :snapshot_id, "Snapshot identifier" do |arg|
219
+ format :snapshot_id, 'Snapshot identifier' do |arg|
211
220
  helper.retrieve_snapshot_id(@current_vm, arg)
212
221
  end
213
222
 
@@ -238,34 +247,33 @@ cmd=CommandParser::CmdParser.new(ARGV) do
238
247
  EOT
239
248
 
240
249
  command :create, create_desc, [:file, nil], :options =>
241
- [OneVMHelper::MULTIPLE, OneVMHelper::HOLD]+
250
+ [OneVMHelper::MULTIPLE, OneVMHelper::HOLD] +
242
251
  OpenNebulaHelper::TEMPLATE_OPTIONS_VM do
243
252
 
244
253
  number = options[:multiple] || 1
245
254
  exit_code = nil
246
255
 
247
256
  if args[0] && OpenNebulaHelper.create_template_options_used?(options)
248
- STDERR.puts "You can not use both template file and template"<<
249
- " creation options."
250
- next -1
257
+ STDERR.puts 'You can not use both template file and template'\
258
+ ' creation options.'
259
+ exit(-1)
251
260
  end
252
261
 
253
262
  begin
254
263
  if args[0]
255
- template=File.read(args[0])
264
+ template = File.read(args[0])
256
265
  else
257
266
  res = OpenNebulaHelper.create_template(options)
258
267
 
259
268
  if res.first != 0
260
269
  STDERR.puts res.last
261
- next -1
270
+ exit(-1)
262
271
  end
263
272
 
264
273
  template = res.last
265
274
  end
266
-
267
- rescue Exception => e
268
- STDERR.puts "Error reading template."
275
+ rescue StandardError
276
+ STDERR.puts 'Error reading template.'
269
277
  next -1
270
278
  end
271
279
 
@@ -274,11 +282,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
274
282
  exit 0
275
283
  end
276
284
 
277
- on_hold = options[:hold] != nil
285
+ on_hold = !options[:hold].nil?
278
286
 
279
287
  number.times do
280
288
  exit_code = helper.create_resource(options) do |vm|
281
- error = vm.allocate(template, on_hold)
289
+ vm.allocate(template, on_hold)
282
290
  end
283
291
 
284
292
  break if exit_code == -1
@@ -293,12 +301,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
293
301
  EOT
294
302
 
295
303
  command :update, update_desc, :vmid, [:file, nil],
296
- :options=>OpenNebulaHelper::APPEND do
297
- helper.perform_action(args[0],options,"modified") do |obj|
304
+ :options => OpenNebulaHelper::APPEND do
305
+ helper.perform_action(args[0], options, 'modified') do |obj|
298
306
  if options[:append]
299
- str = OpenNebulaHelper.append_template(args[0], obj, args[1], 'USER_TEMPLATE')
307
+ str = OpenNebulaHelper
308
+ .append_template(args[0], obj, args[1], 'USER_TEMPLATE')
300
309
  else
301
- str = OpenNebulaHelper.update_template(args[0], obj, args[1], 'USER_TEMPLATE')
310
+ str = OpenNebulaHelper
311
+ .update_template(args[0], obj, args[1], 'USER_TEMPLATE')
302
312
  end
303
313
 
304
314
  helper.set_client(options)
@@ -315,12 +325,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
315
325
  States: PENDING
316
326
  EOT
317
327
 
318
- command :hold, hold_desc, [:range,:vmid_list],
319
- :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME] do
320
- if (!options[:schedule].nil?)
328
+ command :hold, hold_desc, [:range, :vmid_list],
329
+ :options => [OneVMHelper::SCHEDULE,
330
+ OneVMHelper::WEEKLY,
331
+ OneVMHelper::MONTHLY,
332
+ OneVMHelper::YEARLY,
333
+ OneVMHelper::HOURLY,
334
+ OneVMHelper::END_TIME] do
335
+ if !options[:schedule].nil?
321
336
  helper.schedule_actions(args[0], options, @comm_name)
322
337
  else
323
- helper.perform_actions(args[0],options,"put on hold") do |vm|
338
+ helper.perform_actions(args[0], options, 'put on hold') do |vm|
324
339
  vm.hold
325
340
  end
326
341
  end
@@ -332,12 +347,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
332
347
  States: HOLD
333
348
  EOT
334
349
 
335
- command :release, release_desc, [:range,:vmid_list],
336
- :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME] do
337
- if (!options[:schedule].nil?)
350
+ command :release, release_desc, [:range, :vmid_list],
351
+ :options => [OneVMHelper::SCHEDULE,
352
+ OneVMHelper::WEEKLY,
353
+ OneVMHelper::MONTHLY,
354
+ OneVMHelper::YEARLY,
355
+ OneVMHelper::HOURLY,
356
+ OneVMHelper::END_TIME] do
357
+ if !options[:schedule].nil?
338
358
  helper.schedule_actions(args[0], options, @comm_name)
339
359
  else
340
- helper.perform_actions(args[0],options,"released") do |vm|
360
+ helper.perform_actions(args[0], options, 'released') do |vm|
341
361
  vm.release
342
362
  end
343
363
  end
@@ -352,26 +372,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do
352
372
  EOT
353
373
 
354
374
  command :"disk-saveas", disk_saveas_desc, :vmid, :diskid, :img_name,
355
- :options=>[TYPE, SNAP] do
375
+ :options => [TYPE, SNAP] do
356
376
 
357
377
  disk_id = args[1].to_i
358
378
  image_name = args[2]
359
- image_type = options[:type] || ""
379
+ image_type = options[:type] || ''
360
380
  snapshot_id = options[:snapshot]
361
381
 
362
382
  if snapshot_id.nil? || snapshot_id.empty?
363
383
  snapshot_id = -1
364
384
 
365
- verbose = "disk #{disk_id} prepared to be saved in " <<
385
+ verbose = "disk #{disk_id} prepared to be saved in " \
366
386
  "the image #{image_name}"
367
387
  else
368
388
  snapshot_id = snapshot_id.to_i
369
389
 
370
- verbose = "disk #{disk_id} snapshot #{snapshot_id} prepared to " <<
390
+ verbose = "disk #{disk_id} snapshot #{snapshot_id} prepared to " \
371
391
  "be saved in the image #{image_name}"
372
392
  end
373
393
 
374
- helper.perform_action(args[0],options,verbose) do |vm|
394
+ helper.perform_action(args[0], options, verbose) do |vm|
375
395
  res = vm.disk_saveas(disk_id, image_name, image_type, snapshot_id)
376
396
 
377
397
  if !OpenNebula.is_error?(res)
@@ -390,17 +410,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do
390
410
  States: valid if no operation is being performed on the VM
391
411
  EOT
392
412
 
393
- command :terminate, terminate_desc, [:range,:vmid_list],
394
- :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME, OneVMHelper::HARD] do
413
+ command :terminate, terminate_desc, [:range, :vmid_list],
414
+ :options => [OneVMHelper::SCHEDULE,
415
+ OneVMHelper::WEEKLY,
416
+ OneVMHelper::MONTHLY,
417
+ OneVMHelper::YEARLY,
418
+ OneVMHelper::HOURLY,
419
+ OneVMHelper::END_TIME,
420
+ OneVMHelper::HARD] do
395
421
 
396
- command_name='terminate'
397
- command_name<<'-hard' if options[:hard]
422
+ command_name = 'terminate'
423
+ command_name << '-hard' if options[:hard]
398
424
 
399
- if (!options[:schedule].nil?)
425
+ if !options[:schedule].nil?
400
426
  helper.schedule_actions(args[0], options, command_name)
401
427
  else
402
- helper.perform_actions(args[0],options,"terminated") do |vm|
403
- vm.terminate(options[:hard]==true)
428
+ helper.perform_actions(args[0], options, 'terminated') do |vm|
429
+ vm.terminate(options[:hard] == true)
404
430
  end
405
431
  end
406
432
  end
@@ -413,17 +439,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do
413
439
  States: RUNNING
414
440
  EOT
415
441
 
416
- command :undeploy, undeploy_desc, [:range,:vmid_list],
417
- :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME, OneVMHelper::HARD] do
442
+ command :undeploy, undeploy_desc, [:range, :vmid_list],
443
+ :options => [OneVMHelper::SCHEDULE,
444
+ OneVMHelper::WEEKLY,
445
+ OneVMHelper::MONTHLY,
446
+ OneVMHelper::YEARLY,
447
+ OneVMHelper::HOURLY,
448
+ OneVMHelper::END_TIME,
449
+ OneVMHelper::HARD] do
418
450
 
419
- command_name='undeploy'
420
- command_name<<'-hard' if options[:hard]
451
+ command_name = 'undeploy'
452
+ command_name << '-hard' if options[:hard]
421
453
 
422
- if (!options[:schedule].nil?)
454
+ if !options[:schedule].nil?
423
455
  helper.schedule_actions(args[0], options, command_name)
424
456
  else
425
- helper.perform_actions(args[0],options,"shutting down") do |vm|
426
- vm.undeploy(options[:hard]==true)
457
+ helper.perform_actions(args[0], options, 'shutting down') do |vm|
458
+ vm.undeploy(options[:hard] == true)
427
459
  end
428
460
  end
429
461
  end
@@ -435,17 +467,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do
435
467
  States: RUNNING
436
468
  EOT
437
469
 
438
- command :poweroff, poweroff_desc, [:range,:vmid_list],
439
- :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME, OneVMHelper::HARD] do
470
+ command :poweroff, poweroff_desc, [:range, :vmid_list],
471
+ :options => [OneVMHelper::SCHEDULE,
472
+ OneVMHelper::WEEKLY,
473
+ OneVMHelper::MONTHLY,
474
+ OneVMHelper::YEARLY,
475
+ OneVMHelper::HOURLY,
476
+ OneVMHelper::END_TIME,
477
+ OneVMHelper::HARD] do
440
478
 
441
- command_name='poweroff'
442
- command_name<<'-hard' if options[:hard]
479
+ command_name = 'poweroff'
480
+ command_name << '-hard' if options[:hard]
443
481
 
444
- if (!options[:schedule].nil?)
482
+ if !options[:schedule].nil?
445
483
  helper.schedule_actions(args[0], options, @comm_name)
446
484
  else
447
- helper.perform_actions(args[0],options,"shutting down") do |vm|
448
- vm.poweroff(options[:hard]==true)
485
+ helper.perform_actions(args[0], options, 'shutting down') do |vm|
486
+ vm.poweroff(options[:hard] == true)
449
487
  end
450
488
  end
451
489
  end
@@ -459,16 +497,22 @@ cmd=CommandParser::CmdParser.new(ARGV) do
459
497
  States: RUNNING
460
498
  EOT
461
499
 
462
- command :reboot, reboot_desc, [:range,:vmid_list],
463
- :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME, OneVMHelper::HARD] do
500
+ command :reboot, reboot_desc, [:range, :vmid_list],
501
+ :options => [OneVMHelper::SCHEDULE,
502
+ OneVMHelper::WEEKLY,
503
+ OneVMHelper::MONTHLY,
504
+ OneVMHelper::YEARLY,
505
+ OneVMHelper::HOURLY,
506
+ OneVMHelper::END_TIME,
507
+ OneVMHelper::HARD] do
464
508
 
465
- command_name='reboot'
466
- command_name<<'-hard' if options[:hard]
509
+ command_name = 'reboot'
510
+ command_name << '-hard' if options[:hard]
467
511
 
468
- if (!options[:schedule].nil?)
512
+ if !options[:schedule].nil?
469
513
  helper.schedule_actions(args[0], options, command_name)
470
514
  else
471
- helper.perform_actions(args[0],options,"rebooting") do |vm|
515
+ helper.perform_actions(args[0], options, 'rebooting') do |vm|
472
516
  vm.reboot(options[:hard])
473
517
  end
474
518
  end
@@ -482,16 +526,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do
482
526
  States: PENDING, HOLD, STOPPED, UNDEPLOYED
483
527
  EOT
484
528
 
485
- command :deploy, deploy_desc, [:range,:vmid_list], :hostid, [:datastoreid,nil],
486
- :options=>[ENFORCE] do
529
+ command :deploy,
530
+ deploy_desc,
531
+ [:range, :vmid_list],
532
+ :hostid,
533
+ [:datastoreid, nil],
534
+ :options => [ENFORCE, OneVMHelper::FILE] do
487
535
  host_id = args[1]
488
536
  verbose = "deploying in host #{host_id}"
489
537
 
490
- enforce = options[:enforce].nil? ? false : options[:enforce]
491
- ds_id = args[2].nil? ? -1 : args[2]
538
+ options[:enforce].nil? ? enforce = false : enforce = options[:enforce]
539
+ args[2].nil? ? ds_id = -1 : ds_id = args[2]
540
+
541
+ extra_template = nil
542
+
543
+ if options[:file]
544
+ extra_template = File.read(options[:file])
545
+ end
492
546
 
493
- helper.perform_actions(args[0],options,verbose) do |vm|
494
- vm.deploy(host_id, enforce, ds_id)
547
+ helper.perform_actions(args[0], options, verbose) do |vm|
548
+ vm.deploy(host_id, enforce, ds_id, extra_template)
495
549
  end
496
550
  end
497
551
 
@@ -502,18 +556,20 @@ cmd=CommandParser::CmdParser.new(ARGV) do
502
556
  States: RUNNING
503
557
  EOT
504
558
 
505
- command :migrate, migrate_desc, [:range,:vmid_list], :hostid, [:datastoreid,nil],
506
- :options=>[ENFORCE, OneVMHelper::LIVE] do
559
+ command :migrate, migrate_desc, [:range, :vmid_list], :hostid,
560
+ [:datastoreid, nil], :options => [ENFORCE, OneVMHelper::LIVE,
561
+ OneVMHelper::POFF, OneVMHelper::POFFHARD] do
507
562
  host_id = args[1]
508
563
  verbose = "migrating to #{host_id}"
509
564
 
510
- ds_id = args[2].nil? ? -1 : args[2]
565
+ args[2].nil? ? ds_id = -1 : ds_id = args[2]
511
566
 
512
- helper.perform_actions(args[0],options,verbose) do |vm|
513
- vm.migrate( host_id,
514
- options[:live]==true,
515
- options[:enforce]==true,
516
- ds_id)
567
+ helper.perform_actions(args[0], options, verbose) do |vm|
568
+ vm.migrate(host_id,
569
+ options[:live] == true,
570
+ options[:enforce] == true,
571
+ ds_id,
572
+ helper.get_migration_type(options))
517
573
  end
518
574
  end
519
575
 
@@ -524,12 +580,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
524
580
  States: RUNNING
525
581
  EOT
526
582
 
527
- command :stop, stop_desc, [:range,:vmid_list],
528
- :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME] do
529
- if (!options[:schedule].nil?)
583
+ command :stop, stop_desc, [:range, :vmid_list],
584
+ :options => [OneVMHelper::SCHEDULE,
585
+ OneVMHelper::WEEKLY,
586
+ OneVMHelper::MONTHLY,
587
+ OneVMHelper::YEARLY,
588
+ OneVMHelper::HOURLY,
589
+ OneVMHelper::END_TIME] do
590
+ if !options[:schedule].nil?
530
591
  helper.schedule_actions(args[0], options, @comm_name)
531
592
  else
532
- helper.perform_actions(args[0],options,"stopping") do |vm|
593
+ helper.perform_actions(args[0], options, 'stopping') do |vm|
533
594
  vm.stop
534
595
  end
535
596
  end
@@ -544,12 +605,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
544
605
  States: RUNNING
545
606
  EOT
546
607
 
547
- command :suspend, suspend_desc, [:range,:vmid_list],
548
- :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME] do
549
- if (!options[:schedule].nil?)
608
+ command :suspend, suspend_desc, [:range, :vmid_list],
609
+ :options => [OneVMHelper::SCHEDULE,
610
+ OneVMHelper::WEEKLY,
611
+ OneVMHelper::MONTHLY,
612
+ OneVMHelper::YEARLY,
613
+ OneVMHelper::HOURLY,
614
+ OneVMHelper::END_TIME] do
615
+ if !options[:schedule].nil?
550
616
  helper.schedule_actions(args[0], options, @comm_name)
551
617
  else
552
- helper.perform_actions(args[0],options,"suspending") do |vm|
618
+ helper.perform_actions(args[0], options, 'suspending') do |vm|
553
619
  vm.suspend
554
620
  end
555
621
  end
@@ -561,12 +627,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
561
627
  States: STOPPED, SUSPENDED, UNDEPLOYED, POWEROFF, UNKNOWN
562
628
  EOT
563
629
 
564
- command :resume, resume_desc, [:range,:vmid_list],
565
- :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME] do
566
- if (!options[:schedule].nil?)
630
+ command :resume, resume_desc, [:range, :vmid_list],
631
+ :options => [OneVMHelper::SCHEDULE,
632
+ OneVMHelper::WEEKLY,
633
+ OneVMHelper::MONTHLY,
634
+ OneVMHelper::YEARLY,
635
+ OneVMHelper::HOURLY,
636
+ OneVMHelper::END_TIME] do
637
+ if !options[:schedule].nil?
567
638
  helper.schedule_actions(args[0], options, @comm_name)
568
639
  else
569
- helper.perform_actions(args[0],options,"resuming") do |vm|
640
+ helper.perform_actions(args[0], options, 'resuming') do |vm|
570
641
  vm.resume
571
642
  end
572
643
  end
@@ -586,10 +657,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
586
657
  States for a retry recover: Any *FAILURE state
587
658
  States for delete: Any
588
659
  States for delete-recreate: Any but STOP/UNDEPLOYED
660
+ States for delete-db: Any
589
661
  EOT
590
662
 
591
- command :recover, recover_desc, [:range,:vmid_list],
592
- :options => [SUCCESS, FAILURE, RETRY, INTERACTIVE, DELETE, RECREATE] do
663
+ command :recover, recover_desc, [:range, :vmid_list],
664
+ :options => [SUCCESS, FAILURE, RETRY, INTERACTIVE,
665
+ DELETE, RECREATE, DELETE_DB] do
593
666
  if !options[:success].nil?
594
667
  result = 1
595
668
  elsif !options[:failure].nil?
@@ -600,17 +673,24 @@ cmd=CommandParser::CmdParser.new(ARGV) do
600
673
  result = 3
601
674
  elsif !options[:recreate].nil?
602
675
  result = 4
676
+ elsif !options[:deletedb].nil?
677
+ result = 5
603
678
  else
604
- STDERR.puts "Need to specify the result of the pending action."
605
- STDERR.puts "\t--success recover the VM by succeeding the missing action."
606
- STDERR.puts "\t--failure recover the VM by failing the missing action."
607
- STDERR.puts "\t--retry recover the VM by retrying the last failed action."
608
- STDERR.puts "\t--delete no recover possible, delete the VM."
609
- STDERR.puts "\t--recreate no recover possible, delete and recreate the VM."
610
- exit -1
679
+ error_message = <<-EOT.unindent
680
+ Need to specify the result of the pending action.
681
+ \t--success recover the VM by succeeding the missing action.
682
+ \t--failure recover the VM by failing the missing action.
683
+ \t--retry recover the VM by retrying the last failed action.
684
+ \t--delete no recover possible, delete the VM.
685
+ \t--recreate no recover possible, delete and recreate the VM.
686
+ \t--delete-db no recover possible, delete the VM from the DB. No action performed on the hypervisor
687
+ EOT
688
+
689
+ STDERR.puts error_message
690
+ exit(-1)
611
691
  end
612
692
 
613
- helper.perform_actions(args[0], options, "recovering") do |vm|
693
+ helper.perform_actions(args[0], options, 'recovering') do |vm|
614
694
  if options[:retry] && options[:interactive]
615
695
  helper.recover_retry_interactive(vm)
616
696
  else
@@ -630,11 +710,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
630
710
  :options => [OneVMHelper::FILE, OneVMHelper::IMAGE,
631
711
  TARGET, CACHE, DISCARD, PREFIX] do
632
712
 
633
- if options[:file].nil? and options[:image].nil?
634
- STDERR.puts "Provide a template file or an image:"
635
- STDERR.puts "\t--file <file>"
636
- STDERR.puts "\t--image <image>"
637
- exit -1
713
+ if options[:file].nil? && options[:image].nil?
714
+ STDERR.puts 'Provide a template file or an image:'
715
+ STDERR.puts '\t--file <file>'
716
+ STDERR.puts '\t--image <image>'
717
+ exit(-1)
638
718
  end
639
719
 
640
720
  if options[:file]
@@ -653,17 +733,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
653
733
  end
654
734
 
655
735
  if options[:cache]
656
- template<<", CACHE = \"#{options[:cache]}\""
736
+ template << ", CACHE = \"#{options[:cache]}\""
657
737
  end
658
738
 
659
739
  if options[:discard]
660
- template<<", DISCARD = \"#{options[:discard]}\""
740
+ template << ", DISCARD = \"#{options[:discard]}\""
661
741
  end
662
742
 
663
- template << " ]"
743
+ template << ' ]'
664
744
  end
665
745
 
666
- helper.perform_action(args[0],options,"Attach disk") do |vm|
746
+ helper.perform_action(args[0], options, 'Attach disk') do |vm|
667
747
  vm.disk_attach(template)
668
748
  end
669
749
  end
@@ -677,7 +757,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
677
757
  command :"disk-detach", disk_detach_desc, :vmid, :diskid do
678
758
  diskid = args[1].to_i
679
759
 
680
- helper.perform_action(args[0],options,"Detach disk") do |vm|
760
+ helper.perform_action(args[0], options, 'Detach disk') do |vm|
681
761
  vm.disk_detach(diskid)
682
762
  end
683
763
  end
@@ -686,17 +766,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do
686
766
  Attaches a NIC to a running VM. When using --file add only one
687
767
  NIC instance.
688
768
 
769
+ To attach a nic alias, use --file or --alias option.
770
+
689
771
  States: RUNNING, POWEROFF
690
772
  EOT
691
773
 
692
774
  command :"nic-attach", nic_attach_desc, :vmid,
693
- :options => [OneVMHelper::FILE, OneVMHelper::NETWORK, OneVMHelper::IP] do
694
-
695
- if options[:file].nil? and options[:network].nil?
696
- STDERR.puts "Provide a template file or a network:"
775
+ :options => [OneVMHelper::FILE,
776
+ OneVMHelper::NETWORK,
777
+ OneVMHelper::IP,
778
+ OneVMHelper::ALIAS,
779
+ OneVMHelper::NIC_NAME] do
780
+
781
+ if options[:file].nil? && options[:network].nil?
782
+ STDERR.puts 'Provide a template file or a network:'
697
783
  STDERR.puts "\t--file <file>"
698
784
  STDERR.puts "\t--network <network>"
699
- exit -1
785
+ exit(-1)
700
786
  end
701
787
 
702
788
  if options[:file]
@@ -704,14 +790,37 @@ cmd=CommandParser::CmdParser.new(ARGV) do
704
790
  else
705
791
  network_id = options[:network]
706
792
  ip = options[:ip]
793
+ nic_alias = options[:alias]
794
+ nic_name = options[:nic_name]
795
+
707
796
  if ip
708
- template = "NIC = [ NETWORK_ID = #{network_id}, IP = #{ip} ]"
797
+ if !nic_alias && !nic_name
798
+ template = "NIC = [ NETWORK_ID = #{network_id}, IP = #{ip} ]"
799
+ elsif !nic_alias && nic_name
800
+ template = "NIC = [ NETWORK_ID = #{network_id},
801
+ IP = #{ip},
802
+ NAME = #{nic_name} ]"
803
+ else
804
+ template = "NIC_ALIAS = \
805
+ [ NETWORK_ID = #{network_id},\
806
+ IP = #{ip},\
807
+ PARENT = #{nic_alias} ]"
808
+ end
709
809
  else
710
- template = "NIC = [ NETWORK_ID = #{network_id} ]"
810
+ if !nic_alias && !nic_name
811
+ template = "NIC = [ NETWORK_ID = #{network_id} ]"
812
+ elsif !nic_alias && nic_name
813
+ template = "NIC = [ NETWORK_ID = #{network_id},
814
+ NAME = #{nic_name} ]"
815
+ else
816
+ template = "NIC_ALIAS = \
817
+ [ NETWORK_ID = #{network_id},\
818
+ PARENT = #{nic_alias} ]"
819
+ end
711
820
  end
712
821
  end
713
822
 
714
- helper.perform_action(args[0],options,"Attach NIC") do |vm|
823
+ helper.perform_action(args[0], options, 'Attach NIC') do |vm|
715
824
  vm.nic_attach(template)
716
825
  end
717
826
  end
@@ -725,7 +834,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
725
834
  command :"nic-detach", nic_detach_desc, :vmid, :nicid do
726
835
  nicid = args[1].to_i
727
836
 
728
- helper.perform_action(args[0],options,"Detach NIC") do |vm|
837
+ helper.perform_action(args[0], options, 'Detach NIC') do |vm|
729
838
  vm.nic_detach(nicid)
730
839
  end
731
840
  end
@@ -734,8 +843,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
734
843
  Changes the VM group
735
844
  EOT
736
845
 
737
- command :chgrp, chgrp_desc,[:range, :vmid_list], :groupid do
738
- helper.perform_actions(args[0],options,"Group changed") do |vm|
846
+ command :chgrp, chgrp_desc, [:range, :vmid_list], :groupid do
847
+ helper.perform_actions(args[0], options, 'Group changed') do |vm|
739
848
  vm.chown(-1, args[1].to_i)
740
849
  end
741
850
  end
@@ -745,9 +854,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
745
854
  EOT
746
855
 
747
856
  command :chown, chown_desc, [:range, :vmid_list], :userid,
748
- [:groupid,nil] do
749
- gid = args[2].nil? ? -1 : args[2].to_i
750
- helper.perform_actions(args[0],options,"Owner/Group changed") do |vm|
857
+ [:groupid, nil] do
858
+ args[2].nil? ? gid = -1 : gid = args[2].to_i
859
+ helper.perform_actions(args[0], options, 'Owner/Group changed') do |vm|
751
860
  vm.chown(args[1].to_i, gid)
752
861
  end
753
862
  end
@@ -757,7 +866,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
757
866
  EOT
758
867
 
759
868
  command :chmod, chmod_desc, [:range, :vmid_list], :octet do
760
- helper.perform_actions(args[0],options, "Permissions changed") do |vm|
869
+ helper.perform_actions(args[0], options, 'Permissions changed') do |vm|
761
870
  vm.chmod_octet(args[1])
762
871
  end
763
872
  end
@@ -768,8 +877,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
768
877
  States: RUNNING
769
878
  EOT
770
879
 
771
- command :resched, resched_desc, [:range,:vmid_list] do
772
- helper.perform_actions(args[0],options,"Setting resched flag") do |vm|
880
+ command :resched, resched_desc, [:range, :vmid_list] do
881
+ helper.perform_actions(args[0], options, 'Setting resched flag') do |vm|
773
882
  vm.resched
774
883
  end
775
884
  end
@@ -780,8 +889,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
780
889
  States: RUNNING
781
890
  EOT
782
891
 
783
- command :unresched, unresched_desc, [:range,:vmid_list] do
784
- helper.perform_actions(args[0],options,"Clearing resched flag") do |vm|
892
+ command :unresched, unresched_desc, [:range, :vmid_list] do
893
+ helper.perform_actions(args[0],
894
+ options,
895
+ 'Clearing resched flag') do |vm|
785
896
  vm.unresched
786
897
  end
787
898
  end
@@ -791,7 +902,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
791
902
  EOT
792
903
 
793
904
  command :rename, rename_desc, :vmid, :name do
794
- helper.perform_action(args[0],options,"renamed") do |o|
905
+ helper.perform_action(args[0], options, 'renamed') do |o|
795
906
  o.rename(args[1])
796
907
  end
797
908
  end
@@ -803,13 +914,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do
803
914
  Creates a new VM snapshot
804
915
  EOT
805
916
 
806
- command :"snapshot-create", snapshot_create_desc, [:range,:vmid_list],
807
- [:name, nil], :options => [OneVMHelper::SCHEDULE, OneVMHelper::WEEKLY, OneVMHelper::MONTHLY, OneVMHelper::YEARLY, OneVMHelper::HOURLY, OneVMHelper::END_TIME] do
917
+ command :"snapshot-create", snapshot_create_desc, [:range, :vmid_list],
918
+ [:name, nil], :options => [OneVMHelper::SCHEDULE,
919
+ OneVMHelper::WEEKLY,
920
+ OneVMHelper::MONTHLY,
921
+ OneVMHelper::YEARLY,
922
+ OneVMHelper::HOURLY,
923
+ OneVMHelper::END_TIME] do
808
924
 
809
- if (!options[:schedule].nil?)
925
+ if !options[:schedule].nil?
810
926
  helper.schedule_actions(args[0], options, @comm_name)
811
927
  else
812
- helper.perform_actions(args[0],options,"snapshot created") do |o|
928
+ helper.perform_actions(args[0], options, 'snapshot created') do |o|
813
929
  o.snapshot_create(args[1])
814
930
  end
815
931
  end
@@ -821,8 +937,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
821
937
  EOT
822
938
 
823
939
  command :"snapshot-revert", snapshot_revert_desc, :vmid, :snapshot_id do
824
-
825
- helper.perform_action(args[0],options,"snapshot reverted") do |o|
940
+ helper.perform_action(args[0], options, 'snapshot reverted') do |o|
826
941
  o.snapshot_revert(args[1].to_i)
827
942
  end
828
943
  end
@@ -833,7 +948,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
833
948
  EOT
834
949
 
835
950
  command :"snapshot-delete", snapshot_delete_desc, :vmid, :snapshot_id do
836
- helper.perform_action(args[0],options,"snapshot deleted") do |o|
951
+ helper.perform_action(args[0], options, 'snapshot deleted') do |o|
837
952
  o.snapshot_delete(args[1])
838
953
  end
839
954
  end
@@ -846,9 +961,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
846
961
  EOT
847
962
 
848
963
  command :"disk-snapshot-create", disk_snapshot_create_desc,
849
- :vmid, :diskid, :name do
850
- helper.perform_action(args[0],options,"disk snapshot created") do |o|
851
- o.disk_snapshot_create(args[1].to_i, args[2])
964
+ :vmid, :diskid, :name do
965
+ helper.perform_action(args[0], options, 'disk snapshot created') do |o|
966
+ o.disk_snapshot_create(args[1].to_i, args[2])
852
967
  end
853
968
  end
854
969
 
@@ -859,9 +974,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
859
974
  EOT
860
975
 
861
976
  command :"disk-snapshot-revert", disk_snapshot_revert_desc,
862
- :vmid, :diskid, :disk_snapshot_id do
863
- helper.perform_action(args[0],options,"disk snapshot reverted") do |o|
864
- o.disk_snapshot_revert(args[1].to_i, args[2].to_i)
977
+ :vmid, :diskid, :disk_snapshot_id do
978
+ helper.perform_action(args[0], options, 'disk snapshot reverted') do |o|
979
+ o.disk_snapshot_revert(args[1].to_i, args[2].to_i)
865
980
  end
866
981
  end
867
982
 
@@ -870,10 +985,28 @@ cmd=CommandParser::CmdParser.new(ARGV) do
870
985
 
871
986
  States: RUNNING, POWEROFF, SUSPENDED
872
987
  EOT
988
+
873
989
  command :"disk-snapshot-delete", disk_snapshot_delete_desc,
874
- :vmid, :diskid, :disk_snapshot_id do
875
- helper.perform_action(args[0],options,"disk snapshot deleted") do |o|
876
- o.disk_snapshot_delete(args[1].to_i, args[2].to_i)
990
+ :vmid, :diskid, :disk_snapshot_id do
991
+ helper.perform_action(args[0], options, 'disk snapshot deleted') do |o|
992
+ o.disk_snapshot_delete(args[1].to_i, args[2].to_i)
993
+ end
994
+ end
995
+
996
+ disk_snapshot_rename_desc = <<-EOT.unindent
997
+ Renames a disk snapshot.
998
+ EOT
999
+
1000
+ command :"disk-snapshot-rename", disk_snapshot_rename_desc,
1001
+ :vmid, :diskid, :disk_snapshot_id, :new_snapshot_name do
1002
+ helper.perform_action(args[0], options, 'disk snapshot rename') do |o|
1003
+ is_num = true if Integer(args[2]) rescue false
1004
+
1005
+ if !is_num
1006
+ OpenNebula::Error.new('The disk snapshot ID must be an integer')
1007
+ else
1008
+ o.disk_snapshot_rename(args[1].to_i, args[2].to_i, args[3].to_s)
1009
+ end
877
1010
  end
878
1011
  end
879
1012
 
@@ -889,8 +1022,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
889
1022
  EOT
890
1023
 
891
1024
  command :"disk-resize", disk_resize_desc,
892
- :vmid, :diskid, :size do
893
- helper.perform_action(args[0],options,"disk resized") do |o|
1025
+ :vmid, :diskid, :size do
1026
+ helper.perform_action(args[0], options, 'disk resized') do |o|
894
1027
  o.info
895
1028
  size = o["/VM/TEMPLATE/DISK[DISK_ID='#{args[1]}']/SIZE"].to_i
896
1029
 
@@ -910,8 +1043,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
910
1043
  EOT
911
1044
 
912
1045
  command :list, list_desc, [:filterflag, nil],
913
- :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS+
914
- [OpenNebulaHelper::DESCRIBE] do
1046
+ :options => CLIHelper::OPTIONS + OpenNebulaHelper::OPTIONS +
1047
+ [OpenNebulaHelper::DESCRIBE] do
915
1048
  helper.list_pool(options, false, args[0])
916
1049
  end
917
1050
 
@@ -920,8 +1053,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
920
1053
  EOT
921
1054
 
922
1055
  command :show, show_desc, :vmid,
923
- :options=>[OpenNebulaHelper::XML, OneVMHelper::ALL_TEMPLATE] do
924
- helper.show_resource(args[0],options)
1056
+ :options => [OpenNebulaHelper::XML, OneVMHelper::ALL_TEMPLATE] do
1057
+ helper.show_resource(args[0], options)
925
1058
  end
926
1059
 
927
1060
  top_desc = <<-EOT.unindent
@@ -929,7 +1062,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
929
1062
  EOT
930
1063
 
931
1064
  command :top, top_desc, [:filterflag, nil],
932
- :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do
1065
+ :options => CLIHelper::OPTIONS + OpenNebulaHelper::OPTIONS do
933
1066
  helper.list_pool(options, true, args[0])
934
1067
  end
935
1068
 
@@ -939,13 +1072,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
939
1072
 
940
1073
  EOT
941
1074
 
942
- command :resize, resize_desc, :vmid, :options =>
943
- OpenNebulaHelper::CAPACITY_OPTIONS_VM + [ENFORCE, OneVMHelper::FILE] do
1075
+ command :resize, resize_desc, :vmid,
1076
+ :options => OpenNebulaHelper::CAPACITY_OPTIONS_VM +
1077
+ [ENFORCE, OneVMHelper::FILE] do
944
1078
 
945
1079
  if options[:file]
946
1080
  template = File.read(options[:file])
947
1081
  else
948
- template = ""
1082
+ template = ''
949
1083
 
950
1084
  if !options[:cpu].nil?
951
1085
  template << "CPU = #{options[:cpu]}\n"
@@ -962,7 +1096,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
962
1096
 
963
1097
  enforce = options[:enforce] || false
964
1098
 
965
- helper.perform_action(args[0], options, "Resizing VM") do |vm|
1099
+ helper.perform_action(args[0], options, 'Resizing VM') do |vm|
966
1100
  vm.resize(template, enforce)
967
1101
  end
968
1102
  end
@@ -974,9 +1108,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
974
1108
  States: POWEROFF
975
1109
  EOT
976
1110
 
977
- command :save, save_desc, :vmid, :name, :options=>[PERSISTENT] do
978
- helper.perform_action(args[0],options,"Saving VM") do |vm|
979
- res = vm.save_as_template(args[1], options[:persistent] )
1111
+ command :save, save_desc, :vmid, :name, :options => [PERSISTENT] do
1112
+ helper.perform_action(args[0], options, 'Saving VM') do |vm|
1113
+ res = vm.save_as_template(args[1], options[:persistent])
980
1114
 
981
1115
  if !OpenNebula.is_error?(res)
982
1116
  puts "Template ID: #{res}"
@@ -1003,22 +1137,24 @@ cmd=CommandParser::CmdParser.new(ARGV) do
1003
1137
  EOT
1004
1138
 
1005
1139
  command :updateconf, updateconf_desc, :vmid, [:file, nil] do
1006
- template = ""
1140
+ template = ''
1007
1141
 
1008
1142
  begin
1009
- template=File.read(args[1]) if args[1]
1010
- rescue Exception => e
1011
- STDERR.puts "Error reading template."
1012
- exit -1
1143
+ template = File.read(args[1]) if args[1]
1144
+ rescue StandardError => e
1145
+ STDERR.puts "Error reading template: #{e.message}."
1146
+ exit(-1)
1013
1147
  end
1014
1148
 
1015
- helper.perform_action(args[0], options, "Updating VM configuration") do |vm|
1149
+ helper.perform_action(args[0], options,
1150
+ 'Updating VM configuration') do |vm|
1016
1151
  if template.empty?
1017
1152
  vm.info
1018
1153
 
1019
1154
  template = vm.template_like_str('TEMPLATE', true,
1020
- 'OS | FEATURES | INPUT | GRAPHICS | RAW | CONTEXT')
1021
- template = OpenNebulaHelper::editor_input(template)
1155
+ 'OS | FEATURES | INPUT | '\
1156
+ 'GRAPHICS | RAW | CONTEXT')
1157
+ template = OpenNebulaHelper.editor_input(template)
1022
1158
  end
1023
1159
 
1024
1160
  vm.updateconf(template)
@@ -1032,8 +1168,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
1032
1168
  EOT
1033
1169
 
1034
1170
  command :lock, lock_desc, :vmid,
1035
- :options => [USE, MANAGE, ADMIN, ALL] do
1036
- helper.perform_action(args[0],options,"VM locked") do |vm|
1171
+ :options => [USE, MANAGE, ADMIN, ALL] do
1172
+ helper.perform_action(args[0], options, 'VM locked') do |vm|
1037
1173
  if !options[:use].nil?
1038
1174
  level = 1
1039
1175
  elsif !options[:manage].nil?
@@ -1055,7 +1191,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
1055
1191
  EOT
1056
1192
 
1057
1193
  command :unlock, unlock_desc, :vmid do
1058
- helper.perform_action(args[0],options,"VM unlocked") do |vm|
1194
+ helper.perform_action(args[0], options, 'VM unlocked') do |vm|
1059
1195
  vm.unlock
1060
1196
  end
1061
1197
  end