opennebula-cli 6.6.2 → 6.7.80.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,72 +112,6 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
112
112
  :description => 'Creates the new VM on hold state instead of pending'
113
113
  }
114
114
 
115
- SCHEDULE = {
116
- :name => 'schedule',
117
- :large => '--schedule TIME',
118
- :description => 'Schedules this action to be executed after' \
119
- 'the given time. For example: onevm resume 0 --schedule "09/23 14:15"',
120
- :format => String,
121
- :proc => lambda {|o, options|
122
- if o[0] == '+'
123
- options[:schedule] = o
124
- elsif o == 'now'
125
- options[:schedule] = Time.now.to_i
126
- else
127
- begin
128
- options[:schedule] = Time.parse(o).to_i
129
- rescue StandardError
130
- STDERR.puts "Error parsing time spec: #{o}"
131
- exit(-1)
132
- end
133
- end
134
- }
135
- }
136
-
137
- WEEKLY = {
138
- :name => 'weekly',
139
- :large => '--weekly days',
140
- :description => 'Repeats the schedule action the days of the week ' \
141
- 'specified, it can be a number between 0 (Sunday) to 6 (Saturday) ' \
142
- 'separated with commas. ' \
143
- 'For example: onevm resume 0 --schedule "09/23 14:15" --weekly 0,2,4',
144
- :format => String
145
- }
146
-
147
- MONTHLY = {
148
- :name => 'monthly',
149
- :large => '--monthly days',
150
- :description => 'Repeats the schedule action the days of the month ' \
151
- 'specified, it can be a number between 1,31 separated with commas. ' \
152
- 'For example: onevm resume 0 --schedule "09/23 14:15" --monthly 1,14',
153
- :format => String
154
- }
155
-
156
- YEARLY = {
157
- :name => 'yearly',
158
- :large => '--yearly days',
159
- :description => 'Repeats the schedule action the days of the year ' \
160
- 'specified, it can be a number between 0,365 separated with commas. ' \
161
- 'For example: onevm resume 0 --schedule "09/23 14:15" --yearly 30,60',
162
- :format => String
163
- }
164
-
165
- HOURLY = {
166
- :name => 'hourly',
167
- :large => '--hourly hour',
168
- :description => 'Repeats the schedule action each hours specified,' \
169
- 'it can be a number between 0,168 separated with commas. ' \
170
- 'For example: onevm resume 0 --schedule "09/23 14:15" --hourly 1,5',
171
- :format => Numeric
172
- }
173
-
174
- END_TIME = {
175
- :name => 'end',
176
- :large => '--end number|TIME',
177
- :description => '----',
178
- :format => String
179
- }
180
-
181
115
  ALL_TEMPLATE = {
182
116
  :name => 'all',
183
117
  :large => '--all',
@@ -267,8 +201,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
267
201
  end
268
202
 
269
203
  vm_nics.each do |nic|
270
- %w[IP EXTERNAL_IP IP6_GLOBAL IP6_ULA IP6
271
- VROUTER_IP VROUTER_IP6_GLOBAL VROUTER_IP6_ULA].each do |attr|
204
+ ['IP', 'EXTERNAL_IP', 'IP6_GLOBAL', 'IP6_ULA', 'IP6', 'VROUTER_IP',
205
+ 'VROUTER_IP6_GLOBAL', 'VROUTER_IP6_ULA'].each do |attr|
272
206
  if nic.key?(attr)
273
207
  ips.push(nic[attr])
274
208
  end
@@ -333,7 +267,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
333
267
  end
334
268
  end
335
269
 
336
- table = CLIHelper::ShowTable.new(config_file, self) do
270
+ CLIHelper::ShowTable.new(config_file, self) do
337
271
  column :ID, 'ONE identifier for Virtual Machine', :size => 6 do |d|
338
272
  d['ID']
339
273
  end
@@ -377,7 +311,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
377
311
  :left, :size => 10 do |d|
378
312
  if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY']
379
313
  state_str = VirtualMachine::VM_STATE[d['STATE'].to_i]
380
- if %w[ACTIVE SUSPENDED POWEROFF].include? state_str
314
+ if ['ACTIVE', 'SUSPENDED', 'POWEROFF'].include? state_str
381
315
  d['HISTORY_RECORDS']['HISTORY']['HOSTNAME']
382
316
  end
383
317
  end
@@ -414,8 +348,6 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
414
348
  default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOST,
415
349
  :TIME
416
350
  end
417
-
418
- table
419
351
  end
420
352
 
421
353
  def schedule_actions(ids, options, action, warning = nil)
@@ -428,46 +360,14 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
428
360
  "#{action} scheduled after #{options[:schedule]}s from start"
429
361
  end
430
362
 
431
- perform_actions( ids, options, message) do |vm|
432
-
433
- str_periodic = ''
434
-
435
- if options.key?(:weekly)
436
- str_periodic << ", REPEAT = 0, DAYS = \"#{options[:weekly]}\""
437
- elsif options.key?(:monthly)
438
- str_periodic << ", REPEAT = 1, DAYS = \"#{options[:monthly]}\""
439
- elsif options.key?(:yearly)
440
- str_periodic << ", REPEAT = 2, DAYS = \"#{options[:yearly]}\""
441
- elsif options.key?(:hourly)
442
- str_periodic << ", REPEAT = 3, DAYS = \"#{options[:hourly]}\""
443
- end
444
-
445
- if options.key?(:end)
446
- begin
447
- end_date = Date.parse(options[:end])
448
- str_periodic << ', END_TYPE = 2, ' \
449
- "END_VALUE = #{end_date.to_time.to_i}"
450
- rescue ArgumentError
451
- if options[:end].to_i > 0
452
- str_periodic << ', END_TYPE = 1, ' \
453
- "END_VALUE = #{options[:end].to_i}"
454
- end
455
- end
456
- elsif str_periodic != ''
457
- str_periodic << ', END_TYPE = 0'
458
- end
459
-
460
- tmp_str = "SCHED_ACTION = ["
461
- tmp_str << "ACTION = #{action}, "
462
- tmp_str << "WARNING = #{warning}," if warning
463
- tmp_str << "ARGS = \"#{options[:args]}\"," if options[:args]
464
- tmp_str << "TIME = #{options[:schedule]}"
465
- tmp_str << str_periodic << ']'
363
+ tmp_str = OpenNebulaHelper.schedule_action_tmpl(options, action, warning)
466
364
 
365
+ perform_actions(ids, options, message) do |vm|
467
366
  rc = vm.sched_action_add(tmp_str)
468
367
 
469
368
  if OpenNebula.is_error?(rc)
470
- return rc
369
+ STDERR.puts rc.message
370
+ return -1
471
371
  end
472
372
  end
473
373
  end
@@ -477,8 +377,9 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
477
377
  # @param vm_id [Integer] Virtual Machine ID
478
378
  # @param action_id [Integer] Sched action ID
479
379
  # @param file [String] File path with update content
480
- def update_schedule_action(vm_id, action_id, file)
481
- perform_action(vm_id, {}, 'Sched action updated') do |vm|
380
+ # @param options
381
+ def update_schedule_action(vm_id, action_id, file, options)
382
+ perform_action(vm_id, options, 'Sched action updated') do |vm|
482
383
  rc = vm.info
483
384
 
484
385
  if OpenNebula.is_error?(rc)
@@ -600,7 +501,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
600
501
  EOF
601
502
 
602
503
  ans = ''
603
- until %w[n a r q].include?(ans)
504
+ until ['n', 'a', 'r', 'q'].include?(ans)
604
505
  printf '> '
605
506
  ans = STDIN.gets.strip.downcase
606
507
 
@@ -618,7 +519,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
618
519
 
619
520
  if result == 'SUCCESS'
620
521
  success = true
621
- puts result.to_s
522
+ puts result
622
523
  else
623
524
  puts
624
525
  puts "#{result}. Repeat command.".red
@@ -660,7 +561,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
660
561
  # - action
661
562
  # - time
662
563
  # - warning
663
- def get_charters
564
+ def charters
664
565
  YAML.load_file(self.class.table_conf)[:charters]
665
566
  end
666
567
 
@@ -725,9 +626,9 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
725
626
  options[:ssh_opts].nil? ? opts = '' : opts = options[:ssh_opts]
726
627
 
727
628
  if opts.empty?
728
- exec(*%W[ssh #{login}@#{ip} -p #{port} #{cmd}])
629
+ exec('ssh', "#{login}@#{ip}", '-p', port.to_s, cmd.to_s)
729
630
  else
730
- exec('ssh', *opts.split, *%W[#{login}@#{ip} -p #{port} #{cmd}])
631
+ exec('ssh', *opts.split, "#{login}@#{ip}", '-p', port.to_s, cmd.to_s)
731
632
  end
732
633
  end
733
634
 
@@ -759,7 +660,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
759
660
 
760
661
  vm_hash = vm.to_hash
761
662
 
762
- if %w[ACTIVE SUSPENDED POWEROFF].include? vm.state_str
663
+ if ['ACTIVE', 'SUSPENDED', 'POWEROFF'].include? vm.state_str
763
664
  cluster_id = vm['/VM/HISTORY_RECORDS/HISTORY[last()]/CID']
764
665
  else
765
666
  cluster_id = nil
@@ -794,7 +695,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
794
695
  OpenNebulaHelper.level_lock_to_str(vm['LOCK/LOCKED']))
795
696
  puts format(str, 'RESCHED',
796
697
  OpenNebulaHelper.boolean_to_str(vm['RESCHED']))
797
- if %w[ACTIVE SUSPENDED POWEROFF].include? vm.state_str
698
+ if ['ACTIVE', 'SUSPENDED', 'POWEROFF'].include? vm.state_str
798
699
  puts format(str, 'HOST',
799
700
  vm['/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME'])
800
701
  end
@@ -823,7 +724,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
823
724
  end
824
725
  end
825
726
 
826
- order_attrs = %w[CPU MEMORY NETTX NETRX]
727
+ order_attrs = ['CPU', 'MEMORY', 'NETTX', 'NETRX']
827
728
 
828
729
  vm_monitoring_sort = []
829
730
  order_attrs.each do |key|
@@ -834,7 +735,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
834
735
 
835
736
  vm_monitoring_sort.sort_by {|a| a[0] }
836
737
 
837
- filter_attrs = %w[STATE DISK_SIZE SNAPSHOT_SIZE]
738
+ filter_attrs = ['STATE', 'DISK_SIZE', 'SNAPSHOT_SIZE']
838
739
  vm_monitoring.each do |key, val|
839
740
  if !filter_attrs.include?(key)
840
741
  vm_monitoring_sort << [key, val]
@@ -856,7 +757,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
856
757
 
857
758
  CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
858
759
 
859
- %w[OWNER GROUP OTHER].each do |e|
760
+ ['OWNER', 'GROUP', 'OTHER'].each do |e|
860
761
  mask = '---'
861
762
  mask[0] = 'u' if vm["PERMISSIONS/#{e}_U"] == '1'
862
763
  mask[1] = 'm' if vm["PERMISSIONS/#{e}_M"] == '1'
@@ -969,9 +870,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
969
870
  end.show(vm_disks, {})
970
871
 
971
872
  if !options[:all]
972
- while vm.has_elements?('/VM/TEMPLATE/DISK')
973
- vm.delete_element('/VM/TEMPLATE/DISK')
974
- end
873
+ vm.delete_element('/VM/TEMPLATE/DISK') while vm.has_elements?('/VM/TEMPLATE/DISK')
975
874
  end
976
875
  end
977
876
 
@@ -1006,17 +905,17 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1006
905
  # array. Duplicate IPs are not shown.
1007
906
  extra_ips = []
1008
907
 
1009
- if (val = vm['/VM/MONITORING/GUEST_IP'])
1010
- extra_ips << val if val && !val.empty?
908
+ if (val = vm['/VM/MONITORING/GUEST_IP']) && (val && !val.empty?)
909
+ extra_ips << val
1011
910
  end
1012
911
 
1013
- if (val = vm['/VM/MONITORING/GUEST_IP_ADDRESSES'])
1014
- extra_ips += val.split(',') if val && !val.empty?
912
+ if (val = vm['/VM/MONITORING/GUEST_IP_ADDRESSES']) && (val && !val.empty?)
913
+ extra_ips += val.split(',')
1015
914
  end
1016
915
 
1017
916
  extra_ips.uniq!
1018
917
 
1019
- %w[NIC NIC_ALIAS].each do |type|
918
+ ['NIC', 'NIC_ALIAS'].each do |type|
1020
919
  next unless vm.has_elements?("/VM/TEMPLATE/#{type}") ||
1021
920
  vm.has_elements?('/VM/TEMPLATE/PCI[NIC_ID>-1]') ||
1022
921
  !extra_ips.empty?
@@ -1052,7 +951,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1052
951
  vm_nics.each do |nic|
1053
952
  next if nic.key?('CLI_DONE')
1054
953
 
1055
- %w[EXTERNAL_IP IP6_LINK IP6_ULA IP6_GLOBAL IP6].each do |attr|
954
+ ['EXTERNAL_IP', 'IP6_LINK', 'IP6_ULA', 'IP6_GLOBAL', 'IP6'].each do |attr|
1056
955
  next unless nic.key?(attr)
1057
956
 
1058
957
  shown_ips << nic[attr]
@@ -1065,8 +964,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1065
964
  array_id += 1
1066
965
  end
1067
966
 
1068
- %w[VROUTER_IP VROUTER_IP6_LINK
1069
- VROUTER_IP6_ULA VROUTER_IP6_GLOBAL].each do |attr|
967
+ ['VROUTER_IP', 'VROUTER_IP6_LINK', 'VROUTER_IP6_ULA',
968
+ 'VROUTER_IP6_GLOBAL'].each do |attr|
1070
969
  next unless nic.key?(attr)
1071
970
 
1072
971
  shown_ips << nic[attr]
@@ -1148,15 +1047,13 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1148
1047
 
1149
1048
  next if options[:all]
1150
1049
 
1151
- while vm.has_elements?("/VM/TEMPLATE/#{type}")
1152
- vm.delete_element("/VM/TEMPLATE/#{type}")
1153
- end
1050
+ vm.delete_element("/VM/TEMPLATE/#{type}") while vm.has_elements?("/VM/TEMPLATE/#{type}")
1154
1051
  end
1155
1052
 
1156
1053
  if vm_hash['VM']['TEMPLATE']['NIC']
1157
1054
  nic = [vm_hash['VM']['TEMPLATE']['NIC']]
1158
1055
  nic = nic.flatten
1159
- nic = nic.select {|v| !v['EXTERNAL_PORT_RANGE'].nil? }[0]
1056
+ nic = nic.reject {|v| v['EXTERNAL_PORT_RANGE'].nil? }[0]
1160
1057
 
1161
1058
  if nic
1162
1059
  ip = vm_hash['VM']['HISTORY_RECORDS']['HISTORY']
@@ -1174,9 +1071,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1174
1071
  end
1175
1072
 
1176
1073
  if !options[:all]
1177
- while vm.has_elements?('/VM/TEMPLATE/NIC')
1178
- vm.delete_element('/VM/TEMPLATE/NIC')
1179
- end
1074
+ vm.delete_element('/VM/TEMPLATE/NIC') while vm.has_elements?('/VM/TEMPLATE/NIC')
1180
1075
  end
1181
1076
 
1182
1077
  if vm.has_elements?('/VM/TEMPLATE/SECURITY_GROUP_RULE') && !is_hybrid
@@ -1298,91 +1193,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1298
1193
  puts
1299
1194
  CLIHelper.print_header(str_h1 % 'SCHEDULED ACTIONS', false)
1300
1195
 
1301
- CLIHelper::ShowTable.new(nil, self) do
1302
- column :ID, '', :adjust => true do |d|
1303
- d['ID'] unless d.nil?
1304
- end
1305
-
1306
- column :ACTION, '', :adjust => true do |d|
1307
- d['ACTION'] unless d.nil?
1308
- end
1309
-
1310
- column :ARGS, '', :adjust => true do |d|
1311
- d['ARGS'] ? d['ARGS'] : '-'
1312
- end
1313
-
1314
- column :SCHEDULED, '', :adjust => true do |d|
1315
- t2 = d['TIME'].to_i
1316
- t2 += vm['STIME'].to_i unless d['TIME'] =~ /^[0-9].*/
1317
-
1318
- OpenNebulaHelper.time_to_str(t2, false) \
1319
- unless d.nil?
1320
- end
1321
-
1322
- column :REPEAT, '', :adjust => true do |d|
1323
- str_rep = ''
1324
- if !d.nil? && d.key?('REPEAT')
1325
- if d['REPEAT'] == '0'
1326
- str_rep << 'Weekly '
1327
- elsif d['REPEAT'] == '1'
1328
- str_rep << 'Monthly '
1329
- elsif d['REPEAT'] == '2'
1330
- str_rep << 'Yearly '
1331
- elsif d['REPEAT'] == '3'
1332
- str_rep << 'Each ' << d['DAYS'] << ' hours'
1333
- end
1334
- if d['REPEAT'] != '3'
1335
- str_rep << d['DAYS']
1336
- end
1337
- end
1338
- str_rep unless d.nil?
1339
- end
1340
-
1341
- column :END, '', :adjust => true do |d|
1342
- str_end = ''
1343
- if !d.nil? && d.key?('END_TYPE')
1344
- if d['END_TYPE'] == '0'
1345
- str_end << 'None'
1346
- elsif d['END_TYPE'] == '1'
1347
- str_end << 'After ' << d['END_VALUE'] << ' times'
1348
- elsif d['END_TYPE'] == '2'
1349
- str_end << 'On ' << \
1350
- OpenNebulaHelper.time_to_str(d['END_VALUE'],
1351
- false, false,
1352
- true)
1353
- end
1354
- end
1355
- str_end unless d.nil?
1356
- end
1357
- column :STATUS, '', :left, :size => 50 do |d|
1358
- if d['DONE'] && !d['REPEAT']
1359
- "Done on #{OpenNebulaHelper.time_to_str(d['DONE'], false)}"
1360
- elsif d['MESSAGE']
1361
- "Error! #{d['MESSAGE']}"
1362
- else
1363
- t1 = Time.now
1364
- t2 = d['TIME'].to_i
1365
- t2 += vm['STIME'].to_i unless d['TIME'] =~ /^[0-9].*/
1366
-
1367
- t2 = Time.at(t2)
1368
-
1369
- days = ((t2 - t1) / (24 * 3600)).round(2)
1370
- hours = ((t2 - t1) / 3600).round(2)
1371
- minutes = ((t2 - t1) / 60).round(2)
1372
-
1373
- if days > 1
1374
- "Next in #{days} days"
1375
- elsif days <= 1 && hours > 1
1376
- "Next in #{hours} hours"
1377
- elsif minutes > 0
1378
- "Next in #{minutes} minutes"
1379
- else
1380
- "Overdue!"
1381
- end
1382
- end
1383
- end
1384
- end.show([vm_hash['VM']['TEMPLATE']['SCHED_ACTION']].flatten,
1385
- {})
1196
+ table = OpenNebulaHelper.scheduled_action_table(self)
1197
+ table.show([vm_hash['VM']['TEMPLATE']['SCHED_ACTION']].flatten, {})
1386
1198
  end
1387
1199
 
1388
1200
  if !options[:all]
@@ -1427,18 +1239,18 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1427
1239
  def print_backups(vm, vm_hash)
1428
1240
  if vm.has_elements?('/VM/BACKUPS/BACKUP_CONFIG')
1429
1241
  puts
1430
- CLIHelper.print_header('%-80s' % 'BACKUP CONFIGURATION', false)
1242
+ CLIHelper.print_header(format('%-80s', 'BACKUP CONFIGURATION'), false)
1431
1243
  puts vm.template_like_str('BACKUPS/BACKUP_CONFIG')
1432
1244
  end
1433
1245
 
1434
- if vm.has_elements?('/VM/BACKUPS/BACKUP_IDS')
1435
- puts
1436
- CLIHelper.print_header('%-80s' % 'VM BACKUPS', false)
1246
+ return unless vm.has_elements?('/VM/BACKUPS/BACKUP_IDS')
1437
1247
 
1438
- ids = [vm_hash['VM']['BACKUPS']['BACKUP_IDS']['ID']].flatten
1248
+ puts
1249
+ CLIHelper.print_header(format('%-80s', 'VM BACKUPS'), false)
1439
1250
 
1440
- puts format('IMAGE IDS: %s', ids.join(','))
1441
- end
1251
+ ids = [vm_hash['VM']['BACKUPS']['BACKUP_IDS']['ID']].flatten
1252
+
1253
+ puts format('IMAGE IDS: %s', ids.join(','))
1442
1254
  end
1443
1255
 
1444
1256
  def print_numa_nodes(numa_nodes)
@@ -81,6 +81,21 @@ class OneVMGroupHelper < OpenNebulaHelper::OneHelper
81
81
  table
82
82
  end
83
83
 
84
+ def retrieve_role_id(vmg_id, id)
85
+ return [0, id.to_i] if id =~ /\A\d+\z/
86
+
87
+ puts vmg_id
88
+ vmg = retrieve_resource(vmg_id)
89
+ vmg.info
90
+
91
+ ids = vmg.retrieve_elements("ROLES/ROLE[NAME='#{id}']/ID")
92
+
93
+ return [-1, "#{id} not found or duplicated"] \
94
+ if ids.nil? || ids.size > 1
95
+
96
+ [0, ids[0].to_i]
97
+ end
98
+
84
99
  private
85
100
 
86
101
  def factory(id=nil)