opennebula-cli 5.12.0.1 → 5.12.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf03af73280a7f88580018b9dc1bcd1edb12975a
4
- data.tar.gz: b55f9fb61f690572670d6b9a029bd9f3c543acac
3
+ metadata.gz: d83e153918c260f5bc09db239c77f492324e1f40
4
+ data.tar.gz: 7fcca13a86384ec0fb65ebcb7688179df29f55af
5
5
  SHA512:
6
- metadata.gz: e72d448c240092614852b8adbca32b535ec7b855d785bcc3e79109d317460d43aa86e79bac367e6d73e83d38e54b11e2a9ee20081a740c66e5b09eca746890f9
7
- data.tar.gz: 2889b20a9bb830381c58af98f8e98be9442d13d829da84419505c3efc84f36dd50cc4266f018f3c785732a726340a74f5c71758847691b31c03a6a62a3e26ff7
6
+ metadata.gz: 5fa4092f03463ac4db38f8b395321bd2a41d662c3497c76487eb063511663dd091690e15e7e056addfaffe33bc9602293177ed4b74eaade5d00b485cd12a7c73
7
+ data.tar.gz: 365a24105b7d6e1a934cc1f1f5b23f5902a55aec06fbad0606affba56950c4216c66aa511672297e7db86d610b18d84d5aa7af2e08cf28562aad2c4cbfe61466
data/bin/onevm CHANGED
@@ -1250,7 +1250,12 @@ CommandParser::CmdParser.new(ARGV) do
1250
1250
  helper.perform_action(args[0], options,
1251
1251
  'Updating VM configuration') do |vm|
1252
1252
  if template.empty?
1253
- vm.info
1253
+ rc = vm.info
1254
+
1255
+ if OpenNebula.is_error?(rc)
1256
+ STDERR.puts "ERROR: #{rc.message}"
1257
+ exit(-1)
1258
+ end
1254
1259
 
1255
1260
  template = vm.template_like_str('TEMPLATE', true,
1256
1261
  'OS | FEATURES | INPUT | '\
@@ -1298,6 +1303,86 @@ CommandParser::CmdParser.new(ARGV) do
1298
1303
  end
1299
1304
  end
1300
1305
 
1306
+ ########################### Charters Management ############################
1307
+
1308
+ create_chart_desc = <<-EOT.unindent
1309
+ Adds a charter to the VM, these are some consecutive scheduled actions
1310
+
1311
+ You can configure the actions in /etc/one/cli/onevm.yaml
1312
+ EOT
1313
+
1314
+ command :'create-chart', create_chart_desc, [:range, :vmid_list] do
1315
+ charters = helper.get_charters
1316
+
1317
+ if charters.nil?
1318
+ STDERR.puts 'No charters found on configuration file'
1319
+ exit(-1)
1320
+ end
1321
+
1322
+ acc_t = 0
1323
+ acc_w = 0
1324
+
1325
+ charters.each do |action, time|
1326
+ sched = "+#{time[:time].to_i + acc_t}"
1327
+
1328
+ helper.schedule_actions(args[0],
1329
+ { :schedule => sched },
1330
+ action.to_s,
1331
+ time[:warning][:time] + acc_w)
1332
+
1333
+ acc_t += time[:time].to_i
1334
+ acc_w += time[:warning][:time].to_i
1335
+ end
1336
+
1337
+ 0
1338
+ end
1339
+
1340
+ delete_chart_desc = <<-EOT.unindent
1341
+ Deletes a charter from the VM
1342
+ EOT
1343
+
1344
+ command :'delete-chart', delete_chart_desc, :vmid, :sched_id do
1345
+ helper.perform_action(args[0], {}, 'Charter deleted') do |vm|
1346
+ rc = vm.info
1347
+
1348
+ if OpenNebula.is_error?(rc)
1349
+ STDERR.puts "Error #{rc.message}"
1350
+ exit(-1)
1351
+ end
1352
+
1353
+ xpath = "USER_TEMPLATE/SCHED_ACTION[ID=#{args[1]}]"
1354
+
1355
+ unless vm.retrieve_elements(xpath)
1356
+ STDERR.puts "Sched action #{args[1]} not found"
1357
+ exit(-1)
1358
+ end
1359
+
1360
+ vm.delete_element(xpath)
1361
+ rc = vm.update(vm.user_template_str)
1362
+
1363
+ if OpenNebula.is_error?(rc)
1364
+ STDERR.puts "Error deleting: #{rc.message}"
1365
+ exit(-1)
1366
+ end
1367
+ end
1368
+
1369
+ 0
1370
+ end
1371
+
1372
+ update_chart_desc = <<-EOT.unindent
1373
+ Updates a charter from a VM
1374
+ EOT
1375
+
1376
+ command :'update-chart',
1377
+ update_chart_desc,
1378
+ :vmid,
1379
+ :sched_id,
1380
+ [:file, nil] do
1381
+ helper.update_schedule_action(args[0], args[1], args[2])
1382
+
1383
+ 0
1384
+ end
1385
+
1301
1386
  # Deprecated commands
1302
1387
 
1303
1388
  deprecated_command(:shutdown, 'terminate')
@@ -351,43 +351,9 @@ CommandParser::CmdParser.new(ARGV) do
351
351
  Update Address Range variables. SIZE, IP, MAC and TYPE cannot be updated
352
352
  EOT
353
353
 
354
- command :updatear, update_ar_desc, :vnetid, :ar_id, [:file, nil] do
355
- helper.perform_action(args[0], options, 'modified') do |obj|
356
- rc = obj.info
357
-
358
- if OpenNebula.is_error?(rc)
359
- puts rc.message
360
- exit(-1)
361
- end
362
-
363
- obj.delete_element("AR_POOL/AR[AR_ID!=#{args[1]}]")
364
- obj.delete_element('AR_POOL/AR/LEASES')
365
- obj.delete_element('AR_POOL/AR/USED_LEASES')
366
- obj.delete_element('AR_POOL/AR/MAC_END')
367
- obj.delete_element('AR_POOL/AR/IP_END')
368
- obj.delete_element('AR_POOL/AR/IP6_ULA')
369
- obj.delete_element('AR_POOL/AR/IP6_ULA_END')
370
- obj.delete_element('AR_POOL/AR/IP6_GLOBAL')
371
- obj.delete_element('AR_POOL/AR/IP6_GLOBAL_END')
372
-
373
- if obj.template_like_str('AR_POOL').empty?
374
- puts "Address Range #{args[1]} does not exist for " \
375
- "Virtual Network #{args[0]}"
376
- exit(-1)
377
- end
378
-
379
- str = OpenNebulaHelper.update_template_helper(false,
380
- args[0],
381
- obj,
382
- args[2],
383
- 'AR_POOL',
384
- false)
385
-
386
- helper.set_client(options)
387
- obj = helper.retrieve_resource(obj.id)
388
-
389
- obj.update_ar(str)
390
- end
354
+ command :updatear, update_ar_desc, :vnetid, :ar_id, [:file, nil],
355
+ :options => OpenNebulaHelper::APPEND do
356
+ helper.update_ar(args[0], args[1], args[2], options)
391
357
  end
392
358
 
393
359
  rename_desc = <<-EOT.unindent
@@ -325,9 +325,10 @@ module CLIHelper
325
325
  column[:size] = 5
326
326
 
327
327
  conf.each do |c|
328
- if c.is_a? Symbol
328
+ case c
329
+ when Symbol
329
330
  column[c] = true
330
- elsif c.is_a? Hash
331
+ when Hash
331
332
  c.each do |key, value|
332
333
  column[key] = value
333
334
  end
@@ -667,7 +668,9 @@ module CLIHelper
667
668
  def expand_columns(expand_columns, all = false)
668
669
  return if expand_columns.empty?
669
670
 
670
- if $stdout.tty? || (IO.console && IO.console.tty?)
671
+ if $stdout.isatty
672
+ terminal_size = $stdout.winsize[1]
673
+ elsif IO.console && IO.console.tty?
671
674
  terminal_size = IO.console.winsize[1]
672
675
  else
673
676
  terminal_size = nil
@@ -295,6 +295,11 @@ module CommandParser
295
295
  cmd[:arity]+=1 unless args.include?(nil)
296
296
  cmd[:args_format] << args
297
297
  elsif args.instance_of?(Hash) && args[:options]
298
+ if args[:options].is_a? Array
299
+ args[:options].flatten!
300
+ args[:options] = args[:options].sort_by {|o| o[:name] }
301
+ end
302
+
298
303
  cmd[:options] << args[:options]
299
304
  else
300
305
  cmd[:arity]+=1
@@ -679,7 +684,9 @@ module CommandParser
679
684
  def print_options
680
685
  puts "## OPTIONS"
681
686
 
682
- shown_opts = Array.new
687
+ shown_opts = []
688
+ options = []
689
+
683
690
  @command_list.each do |key|
684
691
  value = @commands[key]
685
692
 
@@ -688,14 +695,17 @@ module CommandParser
688
695
  next
689
696
  else
690
697
  shown_opts << o[:name]
691
-
692
- print_option(o)
698
+ options << o
693
699
  end
694
700
  end
695
701
  end
696
702
 
697
- @available_options.each do |o|
698
- print_option o
703
+ options << @available_options
704
+ options.flatten!
705
+ options = options.sort_by {|o| o[:name] }
706
+
707
+ options.each do |o|
708
+ print_option(o)
699
709
  end
700
710
  end
701
711
 
@@ -724,6 +734,8 @@ module CommandParser
724
734
  else
725
735
  puts "## COMMANDS"
726
736
 
737
+ @command_list.sort! if @command_list
738
+
727
739
  @command_list.each do |key|
728
740
  value = @commands[key]
729
741
  printf cmd_format5, "* #{key} "
@@ -766,6 +778,9 @@ module CommandParser
766
778
 
767
779
  cmd_format5 = "#{' '*3}%s"
768
780
  cmd_format10 = "#{' '*8}%s"
781
+
782
+ @formats = @formats.sort_by {|key, _| key } if @formats
783
+
769
784
  @formats.each{ |key,value|
770
785
  printf cmd_format5, "* #{key}"
771
786
  puts
@@ -115,7 +115,7 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
115
115
  def format_pool(_options)
116
116
  config_file = self.class.table_conf
117
117
 
118
- table = CLIHelper::ShowTable.new(config_file, self) do
118
+ CLIHelper::ShowTable.new(config_file, self) do
119
119
  column :ID,
120
120
  'Rule Identifier',
121
121
  :size => 5 do |d|
@@ -157,8 +157,6 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
157
157
 
158
158
  default :ID, :USER, :RES_VHNIUTGDCOZSvRMAPt, :RID, :OPE_UMAC, :ZONE
159
159
  end
160
-
161
- table
162
160
  end
163
161
  # rubocop:enable Lint/IneffectiveAccessModifier
164
162
 
@@ -406,7 +406,11 @@ class OneFlowHelper < OpenNebulaHelper::OneHelper
406
406
 
407
407
  column :TIME, '', :left, :size => 67 do |d|
408
408
  if d['start_time']
409
- Time.parse(d['start_time']).to_s
409
+ if !d['start_time'].match(/^\d+$/)
410
+ Time.parse(d['start_time']).to_s
411
+ else
412
+ d['start_time']
413
+ end
410
414
  else
411
415
  d['recurrence']
412
416
  end
@@ -94,7 +94,7 @@ class OneHookHelper < OpenNebulaHelper::OneHelper
94
94
  def format_pool(_options)
95
95
  config_file = self.class.table_conf
96
96
 
97
- table = CLIHelper::ShowTable.new(config_file, self) do
97
+ CLIHelper::ShowTable.new(config_file, self) do
98
98
  column :ID, 'ONE identifier for the Hook', :size => 5 do |d|
99
99
  d['ID']
100
100
  end
@@ -109,8 +109,6 @@ class OneHookHelper < OpenNebulaHelper::OneHelper
109
109
 
110
110
  default :ID, :NAME, :TYPE
111
111
  end
112
-
113
- table
114
112
  end
115
113
 
116
114
  # Function to print Execution Log records as sent by oned using:
@@ -163,7 +161,11 @@ class OneHookHelper < OpenNebulaHelper::OneHelper
163
161
  end
164
162
  end
165
163
 
166
- default :HOOK, :ID, :TIMESTAMP, :RC, :EXECUTION
164
+ if !header
165
+ default :HOOK, :ID, :TIMESTAMP, :RC, :EXECUTION
166
+ else
167
+ default :ID, :TIMESTAMP, :RC, :EXECUTION
168
+ end
167
169
  end
168
170
 
169
171
  table.show(execs, :stat_column => :EXECUTION)
@@ -103,7 +103,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
103
103
  def format_pool(options)
104
104
  config_file = self.class.table_conf
105
105
 
106
- table = CLIHelper::ShowTable.new(config_file, self) do
106
+ CLIHelper::ShowTable.new(config_file, self) do
107
107
  column :ID, 'ONE identifier for Host', :size => 4 do |d|
108
108
  d['ID']
109
109
  end
@@ -233,8 +233,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
233
233
  default :ID, :NAME, :CLUSTER, :TVM,
234
234
  :ALLOCATED_CPU, :ALLOCATED_MEM, :STAT
235
235
  end
236
-
237
- table
238
236
  end
239
237
 
240
238
  def set_hybrid(type, path)
@@ -192,7 +192,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
192
192
  def format_pool(options)
193
193
  config_file = self.class.table_conf
194
194
 
195
- table = CLIHelper::ShowTable.new(config_file, self) do
195
+ CLIHelper::ShowTable.new(config_file, self) do
196
196
  column :ID, 'ONE identifier for the Image', :size=>4 do |d|
197
197
  d['ID']
198
198
  end
@@ -246,8 +246,6 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
246
246
  default :ID, :USER, :GROUP, :NAME, :DATASTORE, :SIZE, :TYPE,
247
247
  :PERSISTENT, :STAT, :RVMS
248
248
  end
249
-
250
- table
251
249
  end
252
250
 
253
251
  def check_orphans
@@ -49,7 +49,7 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
49
49
  def format_pool
50
50
  config_file = self.class.table_conf
51
51
 
52
- table = CLIHelper::ShowTable.new(config_file, self) do
52
+ CLIHelper::ShowTable.new(config_file, self) do
53
53
  column :ID, 'Identifier for the Provision', :size => 36 do |p|
54
54
  p['ID']
55
55
  end
@@ -80,8 +80,6 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
80
80
 
81
81
  default :ID, :NAME, :CLUSTERS, :HOSTS, :NETWORKS, :DATASTORES, :STAT
82
82
  end
83
-
84
- table
85
83
  end
86
84
 
87
85
  #######################################################################
@@ -228,11 +226,9 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
228
226
  end
229
227
 
230
228
  def names_to_ids(objects, type)
231
- objects = [objects].flatten.map do |obj|
229
+ [objects].flatten.map do |obj|
232
230
  OpenNebulaHelper.rname_to_id(obj.to_s, type)[1]
233
231
  end
234
-
235
- objects
236
232
  end
237
233
 
238
234
  def get_list(provision_list)
@@ -237,11 +237,11 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
237
237
  d[:import_id]
238
238
  end
239
239
 
240
- column :REF, "ref", :left, :size=>config[:REF] || 15 do |d|
240
+ column :REF, "ref", :left, :adjust, :size=>config[:REF] || 15 do |d|
241
241
  d[:ref]
242
242
  end
243
243
 
244
- column :NAME, "Name", :left, :size=>config[:NAME] || 20 do |d|
244
+ column :NAME, "Name", :left, :expand, :size=>config[:NAME] || 20 do |d|
245
245
  d[:name] || d[:simple_name]
246
246
  end
247
247
 
@@ -250,7 +250,7 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
250
250
  d[:one_ids] || d[:cluster].to_s
251
251
  end
252
252
 
253
- column :PATH, "PATH", :left, :size=>config[:PATH] || 10 do |d|
253
+ column :PATH, "PATH", :left, :expand, :size=>config[:PATH] || 10 do |d|
254
254
  d[:path]
255
255
  end
256
256
 
@@ -354,7 +354,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
354
354
 
355
355
  column :MEM, 'Memory asigned to the VM', :size => 7 do |d|
356
356
  OpenNebulaHelper.unit_to_str(d['TEMPLATE']['MEMORY'].to_i,
357
- options)
357
+ options, 'M')
358
358
  end
359
359
 
360
360
  column :HOST, 'Host where the VM is running',
@@ -402,7 +402,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
402
402
  table
403
403
  end
404
404
 
405
- def schedule_actions(ids, options, action)
405
+ def schedule_actions(ids, options, action, warning = nil)
406
406
  # Verbose by default
407
407
  options[:verbose] = true
408
408
 
@@ -453,18 +453,74 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
453
453
  id = ids.max + 1
454
454
  end
455
455
 
456
+ sched = options[:schedule]
457
+
458
+ # If the action is set to be executed from VM start to an specific
459
+ # amount of time later, we should preserve the + symbol
460
+ if ((sched.is_a? String) && !sched.include?('+')) ||
461
+ !(sched.is_a? String)
462
+ sched = sched.to_i
463
+ end
464
+
456
465
  tmp_str = vm.user_template_str
457
466
 
458
467
  tmp_str << "\nSCHED_ACTION = "
459
468
  tmp_str << "[ID = #{id}, ACTION = #{action}, "
469
+ tmp_str << "WARNING = #{warning}," if warning
460
470
  tmp_str << "ARGS = \"#{options[:args]}\"," if options[:args]
461
- tmp_str << "TIME = #{options[:schedule].to_i}"
471
+ tmp_str << "TIME = #{sched}"
462
472
  tmp_str << str_periodic << ']'
463
473
 
464
474
  vm.update(tmp_str)
465
475
  end
466
476
  end
467
477
 
478
+ # Update schedule action
479
+ #
480
+ # @param vm_id [Integer] Virtual Machine ID
481
+ # @param action_id [Integer] Sched action ID
482
+ # @param file [String] File path with update content
483
+ def update_schedule_action(vm_id, action_id, file)
484
+ perform_action(vm_id, {}, 'Sched action updated') do |vm|
485
+ rc = vm.info
486
+
487
+ if OpenNebula.is_error?(rc)
488
+ STDERR.puts "Error #{rc.message}"
489
+ exit(-1)
490
+ end
491
+
492
+ xpath = "USER_TEMPLATE/SCHED_ACTION[ID=#{action_id}]"
493
+
494
+ unless vm.retrieve_elements(xpath)
495
+ STDERR.puts "Sched action #{action_id} not found"
496
+ exit(-1)
497
+ end
498
+
499
+ # Get user information
500
+ if file
501
+ str = File.read(file)
502
+ else
503
+ str = OpenNebulaHelper.update_template(vm_id, vm, nil, xpath)
504
+ end
505
+
506
+ # Delete the current sched action
507
+ vm.delete_element(xpath)
508
+
509
+ # Add the modified sched action
510
+ tmp_str = vm.user_template_str
511
+ tmp_str << "\nSCHED_ACTION = ["
512
+ tmp_str << str.split("\n").join(',')
513
+ tmp_str << ']'
514
+
515
+ rc = vm.update(tmp_str)
516
+
517
+ if OpenNebula.is_error?(rc)
518
+ STDERR.puts "Error updating: #{rc.message}"
519
+ exit(-1)
520
+ end
521
+ end
522
+ end
523
+
468
524
  RECOVER_RETRY_STEPS = {
469
525
  :PROLOG_MIGRATE_FAILURE => :migrate,
470
526
  :PROLOG_MIGRATE_POWEROFF_FAILURE => :migrate,
@@ -602,6 +658,16 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
602
658
  end
603
659
  end
604
660
 
661
+ # Get charters configuration
662
+ #
663
+ # @return [Array]
664
+ # - action
665
+ # - time
666
+ # - warning
667
+ def get_charters
668
+ YAML.load_file(self.class.table_conf)[:charters]
669
+ end
670
+
605
671
  private
606
672
 
607
673
  def factory(id = nil)
@@ -1144,24 +1210,24 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1144
1210
  CLIHelper.print_header(str_h1 % 'SCHEDULED ACTIONS', false)
1145
1211
 
1146
1212
  CLIHelper::ShowTable.new(nil, self) do
1147
- column :ID, '', :size => 2 do |d|
1213
+ column :ID, '', :adjust => true do |d|
1148
1214
  d['ID'] unless d.nil?
1149
1215
  end
1150
1216
 
1151
- column :ACTION, '', :left, :size => 15 do |d|
1217
+ column :ACTION, '', :adjust => true do |d|
1152
1218
  d['ACTION'] unless d.nil?
1153
1219
  end
1154
1220
 
1155
- column :ARGS, '', :left, :size => 15 do |d|
1221
+ column :ARGS, '', :adjust => true do |d|
1156
1222
  d['ARGS'] ? d['ARGS'] : '-'
1157
1223
  end
1158
1224
 
1159
- column :SCHEDULED, '', :size => 12 do |d|
1225
+ column :SCHEDULED, '', :adjust => true do |d|
1160
1226
  OpenNebulaHelper.time_to_str(d['TIME'], false) \
1161
1227
  unless d.nil?
1162
1228
  end
1163
1229
 
1164
- column :REPEAT, '', :size => 20 do |d|
1230
+ column :REPEAT, '', :adjust => true do |d|
1165
1231
  str_rep = ''
1166
1232
  if !d.nil? && d.key?('REPEAT')
1167
1233
  if d['REPEAT'] == '0'
@@ -1180,7 +1246,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1180
1246
  str_rep unless d.nil?
1181
1247
  end
1182
1248
 
1183
- column :END, '', :size => 20 do |d|
1249
+ column :END, '', :adjust => true do |d|
1184
1250
  str_end = ''
1185
1251
  if !d.nil? && d.key?('END_TYPE')
1186
1252
  if d['END_TYPE'] == '0'
@@ -1197,25 +1263,50 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1197
1263
  str_end unless d.nil?
1198
1264
  end
1199
1265
 
1200
- column :DONE, '', :size => 12 do |d|
1266
+ column :DONE, '', :adjust => true do |d|
1201
1267
  OpenNebulaHelper.time_to_str(d['DONE'], false) \
1202
1268
  unless d.nil?
1203
1269
  end
1204
1270
 
1205
- column :MESSAGE, '', :left, :adjust, :size => 35 do |d|
1206
- d['MESSAGE'] unless d.nil?
1271
+ column :MESSAGE, '', :size => 35 do |d|
1272
+ d['MESSAGE'] ? d['MESSAGE'] : '-'
1273
+ end
1274
+
1275
+ column :CHARTER, '', :left, :adjust, :size => 15 do |d|
1276
+ t1 = Time.now
1277
+ t2 = Time.at(vm['STIME'].to_i + d['TIME'].to_i)
1278
+
1279
+ days = ((t2 - t1) / (24 * 3600)).round(2)
1280
+ hours = ((t2 - t1) / 3600).round(2)
1281
+ minutes = ((t2 - t1) / 60).round(2)
1282
+
1283
+ if days > 1
1284
+ show = "In #{days} days"
1285
+ elsif days < 1 && hours > 1
1286
+ show = "In #{hours} hours"
1287
+ elsif minutes > 0
1288
+ show = "In #{minutes} minutes"
1289
+ else
1290
+ show = 'Already done'
1291
+ end
1292
+
1293
+ if (t1 - vm['STIME'].to_i).to_i > d['WARNING'].to_i
1294
+ "#{show} *"
1295
+ else
1296
+ show
1297
+ end
1207
1298
  end
1208
1299
  end.show([vm_hash['VM']['USER_TEMPLATE']['SCHED_ACTION']].flatten,
1209
1300
  {})
1210
1301
  end
1211
1302
 
1303
+ if !options[:all]
1304
+ vm.delete_element('/VM/USER_TEMPLATE/SCHED_ACTION')
1305
+ end
1306
+
1212
1307
  if vm.has_elements?('/VM/USER_TEMPLATE')
1213
1308
  puts
1214
1309
 
1215
- if !options[:all]
1216
- vm.delete_element('/VM/USER_TEMPLATE/SCHED_ACTION')
1217
- end
1218
-
1219
1310
  CLIHelper.print_header(str_h1 % 'USER TEMPLATE', false)
1220
1311
  puts vm.template_like_str('USER_TEMPLATE')
1221
1312
  end
@@ -13,7 +13,6 @@
13
13
  # See the License for the specific language governing permissions and #
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
-
17
16
  require 'one_helper'
18
17
  require 'one_helper/onevm_helper'
19
18
 
@@ -215,6 +214,71 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
215
214
  orphans
216
215
  end
217
216
 
217
+ # Update VNet address range
218
+ #
219
+ # @param vnet_id [Intenger] Virtual Network ID
220
+ # @param ar_id [Intenger] Address Range ID
221
+ # @param file [String] Path to file to read
222
+ # @param options [Hash] User CLI options
223
+ def update_ar(vnet_id, ar_id, file, options)
224
+ perform_action(vnet_id, options, 'AR updated') do |obj|
225
+ rc = obj.info
226
+
227
+ if OpenNebula.is_error?(rc)
228
+ STDERR.puts rc.message
229
+ exit(-1)
230
+ end
231
+
232
+ obj.delete_element("AR_POOL/AR[AR_ID!=#{ar_id}]")
233
+ obj.delete_element('AR_POOL/AR/LEASES')
234
+ obj.delete_element('AR_POOL/AR/USED_LEASES')
235
+ obj.delete_element('AR_POOL/AR/MAC_END')
236
+ obj.delete_element('AR_POOL/AR/IP_END')
237
+ obj.delete_element('AR_POOL/AR/IP6_ULA')
238
+ obj.delete_element('AR_POOL/AR/IP6_ULA_END')
239
+ obj.delete_element('AR_POOL/AR/IP6_GLOBAL')
240
+ obj.delete_element('AR_POOL/AR/IP6_GLOBAL_END')
241
+
242
+ if obj.template_like_str('AR_POOL').empty?
243
+ STDERR.puts "Address Range #{ar_id} does not exist for " \
244
+ "Virtual Network #{vnet_id}"
245
+ exit(-1)
246
+ end
247
+
248
+ xpath = "AR_POOL/AR[AR_ID=#{ar_id}]"
249
+
250
+ if options[:append]
251
+ str = OpenNebulaHelper.append_template(vnet_id,
252
+ obj,
253
+ file,
254
+ xpath)
255
+ else
256
+ str = OpenNebulaHelper.update_template(vnet_id,
257
+ obj,
258
+ file,
259
+ xpath)
260
+ end
261
+
262
+ if options[:append]
263
+ # Insert element in current template
264
+ parts = obj.template_like_str('AR_POOL').split("\n")
265
+
266
+ # Insert it in second position, OpenNebula will sort it
267
+ parts.insert(1, "#{str.strip},")
268
+
269
+ parts = parts.join("\n")
270
+ str = parts
271
+ else
272
+ # Use the information from user
273
+ unless str.gsub(' ', '').match(/AR=\[/)
274
+ str = "AR=[\n#{str.split("\n").join(",\n")}]"
275
+ end
276
+ end
277
+
278
+ obj.update_ar(str)
279
+ end
280
+ end
281
+
218
282
  private
219
283
 
220
284
  def factory(id=nil)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opennebula-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.12.0.1
4
+ version: 5.12.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenNebula
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2020-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opennebula
@@ -16,19 +16,18 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.12.0.1
19
+ version: 5.12.0.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.12.0.1
26
+ version: 5.12.0.2
27
27
  description: Commands used to talk to OpenNebula
28
28
  email: contact@opennebula.io
29
29
  executables:
30
30
  - oneacct
31
- - onevcenter
32
31
  - oneacl
33
32
  - onecluster
34
33
  - onedatastore
@@ -44,6 +43,7 @@ executables:
44
43
  - oneshowback
45
44
  - onetemplate
46
45
  - oneuser
46
+ - onevcenter
47
47
  - onevdc
48
48
  - onevm
49
49
  - onevmgroup
@@ -55,7 +55,6 @@ extensions: []
55
55
  extra_rdoc_files: []
56
56
  files:
57
57
  - bin/oneacct
58
- - bin/onevcenter
59
58
  - bin/oneacl
60
59
  - bin/onecluster
61
60
  - bin/onedatastore
@@ -71,6 +70,7 @@ files:
71
70
  - bin/oneshowback
72
71
  - bin/onetemplate
73
72
  - bin/oneuser
73
+ - bin/onevcenter
74
74
  - bin/onevdc
75
75
  - bin/onevm
76
76
  - bin/onevmgroup
@@ -78,34 +78,34 @@ files:
78
78
  - bin/onevntemplate
79
79
  - bin/onevrouter
80
80
  - bin/onezone
81
- - lib/cli_helper.rb
82
81
  - lib/command_parser.rb
82
+ - lib/cli_helper.rb
83
83
  - lib/one_helper.rb
84
84
  - lib/one_helper/oneacl_helper.rb
85
85
  - lib/one_helper/onecluster_helper.rb
86
- - lib/one_helper/onedatastore_helper.rb
87
86
  - lib/one_helper/onegroup_helper.rb
88
87
  - lib/one_helper/onehook_helper.rb
89
- - lib/one_helper/onehost_helper.rb
90
- - lib/one_helper/oneimage_helper.rb
91
88
  - lib/one_helper/onemarket_helper.rb
92
- - lib/one_helper/onemarketapp_helper.rb
93
89
  - lib/one_helper/onequota_helper.rb
94
90
  - lib/one_helper/onesecgroup_helper.rb
95
91
  - lib/one_helper/onetemplate_helper.rb
96
- - lib/one_helper/oneuser_helper.rb
92
+ - lib/one_helper/onevcenter_helper.rb
97
93
  - lib/one_helper/onevdc_helper.rb
98
94
  - lib/one_helper/onevmgroup_helper.rb
95
+ - lib/one_helper/onevnet_helper.rb
99
96
  - lib/one_helper/onevntemplate_helper.rb
100
97
  - lib/one_helper/onevrouter_helper.rb
101
98
  - lib/one_helper/onezone_helper.rb
102
99
  - lib/one_helper/oneacct_helper.rb
100
+ - lib/one_helper/onedatastore_helper.rb
103
101
  - lib/one_helper/oneflow_helper.rb
104
102
  - lib/one_helper/oneflowtemplate_helper.rb
103
+ - lib/one_helper/onehost_helper.rb
104
+ - lib/one_helper/oneimage_helper.rb
105
+ - lib/one_helper/onemarketapp_helper.rb
105
106
  - lib/one_helper/oneprovision_helper.rb
106
- - lib/one_helper/onevcenter_helper.rb
107
+ - lib/one_helper/oneuser_helper.rb
107
108
  - lib/one_helper/onevm_helper.rb
108
- - lib/one_helper/onevnet_helper.rb
109
109
  - NOTICE
110
110
  - LICENSE
111
111
  homepage: http://opennebula.io