opennebula-cli 6.0.0.2 → 6.0.1

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.
data/bin/oneshowback CHANGED
@@ -26,25 +26,14 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
- # %%RUBYGEMS_SETUP_BEGIN%%
30
29
  if File.directory?(GEMS_LOCATION)
31
30
  real_gems_path = File.realpath(GEMS_LOCATION)
32
31
  if !defined?(Gem) || Gem.path != [real_gems_path]
33
32
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
34
-
35
- # Suppress warnings from Rubygems
36
- # https://github.com/OpenNebula/one/issues/5379
37
- begin
38
- verb = $VERBOSE
39
- $VERBOSE = nil
40
- require 'rubygems'
41
- Gem.use_paths(real_gems_path)
42
- ensure
43
- $VERBOSE = verb
44
- end
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
45
35
  end
46
36
  end
47
- # %%RUBYGEMS_SETUP_END%%
48
37
 
49
38
  $LOAD_PATH << RUBY_LIB_LOCATION
50
39
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
data/bin/onetemplate CHANGED
@@ -26,25 +26,14 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
- # %%RUBYGEMS_SETUP_BEGIN%%
30
29
  if File.directory?(GEMS_LOCATION)
31
30
  real_gems_path = File.realpath(GEMS_LOCATION)
32
31
  if !defined?(Gem) || Gem.path != [real_gems_path]
33
32
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
34
-
35
- # Suppress warnings from Rubygems
36
- # https://github.com/OpenNebula/one/issues/5379
37
- begin
38
- verb = $VERBOSE
39
- $VERBOSE = nil
40
- require 'rubygems'
41
- Gem.use_paths(real_gems_path)
42
- ensure
43
- $VERBOSE = verb
44
- end
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
45
35
  end
46
36
  end
47
- # %%RUBYGEMS_SETUP_END%%
48
37
 
49
38
  $LOAD_PATH << RUBY_LIB_LOCATION
50
39
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
@@ -225,17 +214,8 @@ CommandParser::CmdParser.new(ARGV) do
225
214
  Creates a new VM instance from the given Template. This VM can be
226
215
  managed with the 'onevm' command.
227
216
 
228
- The source Template can be modified by replacing existing attributes; or
229
- adding new DISK or NIC elements. The new attributes can be specified with the
230
- command options or the file argument.
231
-
232
- Example:
233
-
234
- - Instantiate a template and add a new NIC
235
- onetemplate instantiate 23 --nic private_net
236
-
237
- - Instantiate a template and replace CONTEXT with a new one
238
- onetemplate instantiate 23 --startscript /path/to/my/start_script
217
+ The source Template can be modified adding or replacing attributes with
218
+ the optional file argument, or with the options.
239
219
  EOT
240
220
 
241
221
  command :instantiate, instantiate_desc, :templateid, [:file, nil],
@@ -415,9 +395,9 @@ CommandParser::CmdParser.new(ARGV) do
415
395
  [Admin]: locks only Admin actions.
416
396
  EOT
417
397
 
418
- command :lock, lock_desc, [:range, :templateid_list],
398
+ command :lock, lock_desc, :templateid,
419
399
  :options => [USE, MANAGE, ADMIN, ALL] do
420
- helper.perform_actions(args[0], options, 'Template locked') do |t|
400
+ helper.perform_action(args[0], options, 'Template locked') do |t|
421
401
  if !options[:use].nil?
422
402
  level = 1
423
403
  elsif !options[:manage].nil?
@@ -438,8 +418,8 @@ CommandParser::CmdParser.new(ARGV) do
438
418
  Valid states are: All.
439
419
  EOT
440
420
 
441
- command :unlock, unlock_desc, [:range, :templateid_list] do
442
- helper.perform_actions(args[0], options, 'Template unlocked') do |t|
421
+ command :unlock, unlock_desc, :templateid do
422
+ helper.perform_action(args[0], options, 'Template unlocked') do |t|
443
423
  t.unlock
444
424
  end
445
425
  end
data/bin/oneuser CHANGED
@@ -26,25 +26,14 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
- # %%RUBYGEMS_SETUP_BEGIN%%
30
29
  if File.directory?(GEMS_LOCATION)
31
30
  real_gems_path = File.realpath(GEMS_LOCATION)
32
31
  if !defined?(Gem) || Gem.path != [real_gems_path]
33
32
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
34
-
35
- # Suppress warnings from Rubygems
36
- # https://github.com/OpenNebula/one/issues/5379
37
- begin
38
- verb = $VERBOSE
39
- $VERBOSE = nil
40
- require 'rubygems'
41
- Gem.use_paths(real_gems_path)
42
- ensure
43
- $VERBOSE = verb
44
- end
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
45
35
  end
46
36
  end
47
- # %%RUBYGEMS_SETUP_END%%
48
37
 
49
38
  $LOAD_PATH << RUBY_LIB_LOCATION
50
39
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
data/bin/onevcenter CHANGED
@@ -28,25 +28,14 @@ else
28
28
  REMOTES_LOCATION = ONE_LOCATION + '/var/remotes/'
29
29
  end
30
30
 
31
- # %%RUBYGEMS_SETUP_BEGIN%%
32
31
  if File.directory?(GEMS_LOCATION)
33
32
  real_gems_path = File.realpath(GEMS_LOCATION)
34
33
  if !defined?(Gem) || Gem.path != [real_gems_path]
35
34
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
36
-
37
- # Suppress warnings from Rubygems
38
- # https://github.com/OpenNebula/one/issues/5379
39
- begin
40
- verb = $VERBOSE
41
- $VERBOSE = nil
42
- require 'rubygems'
43
- Gem.use_paths(real_gems_path)
44
- ensure
45
- $VERBOSE = verb
46
- end
35
+ require 'rubygems'
36
+ Gem.use_paths(real_gems_path)
47
37
  end
48
38
  end
49
- # %%RUBYGEMS_SETUP_END%%
50
39
 
51
40
  $LOAD_PATH << RUBY_LIB_LOCATION
52
41
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
@@ -272,7 +261,7 @@ CommandParser::CmdParser.new(ARGV) do
272
261
  vi_client,
273
262
  options[:object])
274
263
 
275
- if options[:object] == 'networks' && !args.first.nil?
264
+ if options[:object] == "networks" && !args.first.nil?
276
265
  indexes = args.first
277
266
  else
278
267
  importer.retrieve_resources(helper.parse_opts(options))
data/bin/onevdc CHANGED
@@ -26,25 +26,14 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
- # %%RUBYGEMS_SETUP_BEGIN%%
30
29
  if File.directory?(GEMS_LOCATION)
31
30
  real_gems_path = File.realpath(GEMS_LOCATION)
32
31
  if !defined?(Gem) || Gem.path != [real_gems_path]
33
32
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
34
-
35
- # Suppress warnings from Rubygems
36
- # https://github.com/OpenNebula/one/issues/5379
37
- begin
38
- verb = $VERBOSE
39
- $VERBOSE = nil
40
- require 'rubygems'
41
- Gem.use_paths(real_gems_path)
42
- ensure
43
- $VERBOSE = verb
44
- end
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
45
35
  end
46
36
  end
47
- # %%RUBYGEMS_SETUP_END%%
48
37
 
49
38
  $LOAD_PATH << RUBY_LIB_LOCATION
50
39
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
data/bin/onevm CHANGED
@@ -26,25 +26,14 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
- # %%RUBYGEMS_SETUP_BEGIN%%
30
29
  if File.directory?(GEMS_LOCATION)
31
30
  real_gems_path = File.realpath(GEMS_LOCATION)
32
31
  if !defined?(Gem) || Gem.path != [real_gems_path]
33
32
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
34
-
35
- # Suppress warnings from Rubygems
36
- # https://github.com/OpenNebula/one/issues/5379
37
- begin
38
- verb = $VERBOSE
39
- $VERBOSE = nil
40
- require 'rubygems'
41
- Gem.use_paths(real_gems_path)
42
- ensure
43
- $VERBOSE = verb
44
- end
33
+ require 'rubygems'
34
+ Gem.use_paths(real_gems_path)
45
35
  end
46
36
  end
47
- # %%RUBYGEMS_SETUP_END%%
48
37
 
49
38
  $LOAD_PATH << RUBY_LIB_LOCATION
50
39
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
@@ -218,27 +207,6 @@ CommandParser::CmdParser.new(ARGV) do
218
207
  :description => 'Market to save oneshot'
219
208
  }
220
209
 
221
- NIC_ID = {
222
- :name => 'nic_id',
223
- :large => '--nic-id nic_id',
224
- :format => String,
225
- :description => 'NIC to use when SSH'
226
- }
227
-
228
- CMD = {
229
- :name => 'cmd',
230
- :large => '--cmd cmd',
231
- :format => String,
232
- :description => 'CMD to run when SSH'
233
- }
234
-
235
- SSH_OPTS = {
236
- :name => 'ssh_opts',
237
- :large => '--ssh-options options',
238
- :format => String,
239
- :description => 'SSH options to use'
240
- }
241
-
242
210
  ########################################################################
243
211
  # Global Options
244
212
  ########################################################################
@@ -1342,9 +1310,9 @@ CommandParser::CmdParser.new(ARGV) do
1342
1310
  Valid states are: All.
1343
1311
  EOT
1344
1312
 
1345
- command :lock, lock_desc, [:range, :vmid_list],
1313
+ command :lock, lock_desc, :vmid,
1346
1314
  :options => [USE, MANAGE, ADMIN, ALL] do
1347
- helper.perform_actions(args[0], options, 'VM locked') do |vm|
1315
+ helper.perform_action(args[0], options, 'VM locked') do |vm|
1348
1316
  if !options[:use].nil?
1349
1317
  level = 1
1350
1318
  elsif !options[:manage].nil?
@@ -1365,8 +1333,8 @@ CommandParser::CmdParser.new(ARGV) do
1365
1333
  Valid states are: All.
1366
1334
  EOT
1367
1335
 
1368
- command :unlock, unlock_desc, [:range, :vmid_list] do
1369
- helper.perform_actions(args[0], options, 'VM unlocked') do |vm|
1336
+ command :unlock, unlock_desc, :vmid do
1337
+ helper.perform_action(args[0], options, 'VM unlocked') do |vm|
1370
1338
  vm.unlock
1371
1339
  end
1372
1340
  end
@@ -1379,7 +1347,7 @@ CommandParser::CmdParser.new(ARGV) do
1379
1347
  You can configure the actions in /etc/one/cli/onevm.yaml
1380
1348
  EOT
1381
1349
 
1382
- command :'create-chart', create_chart_desc, :vmid do
1350
+ command :'create-chart', create_chart_desc, [:range, :vmid_list] do
1383
1351
  charters = helper.get_charters
1384
1352
 
1385
1353
  if charters.nil?
@@ -1393,7 +1361,7 @@ CommandParser::CmdParser.new(ARGV) do
1393
1361
  charters.each do |action, time|
1394
1362
  sched = "+#{time[:time].to_i + acc_t}"
1395
1363
 
1396
- helper.schedule_actions([args[0]].flatten,
1364
+ helper.schedule_actions(args[0],
1397
1365
  { :schedule => sched },
1398
1366
  action.to_s,
1399
1367
  time[:warning][:time] + acc_w)
@@ -1469,33 +1437,25 @@ CommandParser::CmdParser.new(ARGV) do
1469
1437
  helper.perform_action(args[0], options, 'Backup') do |vm|
1470
1438
  vm.extend(OpenNebula::VirtualMachineExt)
1471
1439
 
1472
- # Read user options
1473
- if options[:verbose]
1474
- log_to = STDOUT
1475
- elsif !options[:logger].nil?
1476
- log_to = options[:logger]
1477
- end
1478
-
1479
- keep = options.key?(:keep)
1440
+ # If logger is specified use it, if not use STDOUT
1441
+ options[:logger].nil? ? log_to = STDOUT : log_to = options[:logger]
1480
1442
 
1481
- if log_to
1482
- logger = Logger.new(log_to)
1483
- format = '%Y-%m-%d %H:%M:%S'
1443
+ # Read user options
1444
+ keep = options.key?(:keep)
1445
+ logger = Logger.new(log_to)
1446
+ format = '%Y-%m-%d %H:%M:%S'
1484
1447
 
1485
- logger.formatter = proc do |severity, datetime, _p, msg|
1486
- "#{datetime.strftime(format)} " \
1487
- "#{severity.ljust(5)} : #{msg}\n"
1488
- end
1448
+ logger.formatter = proc do |severity, datetime, _p, msg|
1449
+ "#{datetime.strftime(format)} #{severity.ljust(5)} : #{msg}\n"
1489
1450
  end
1490
1451
 
1491
- binfo = {}
1492
- binfo[:market] = options[:market]
1493
-
1494
1452
  if options.key?(:oneshot)
1453
+ binfo = {}
1495
1454
  binfo[:name] = "VM #{vm.id} BACKUP - " \
1496
1455
  "#{Time.now.strftime('%Y%m%d_%k%M')}"
1497
1456
  binfo[:freq] = 1
1498
1457
  binfo[:last] = Time.now.to_i - 100
1458
+ binfo[:market] = options[:market]
1499
1459
  end
1500
1460
 
1501
1461
  begin
@@ -1558,128 +1518,6 @@ CommandParser::CmdParser.new(ARGV) do
1558
1518
  end
1559
1519
  end
1560
1520
 
1561
- ssh_desc = <<-EOT.unindent
1562
- SSH into VM
1563
-
1564
- Options example:
1565
-
1566
- '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
1567
- EOT
1568
-
1569
- command :ssh,
1570
- ssh_desc,
1571
- :vmid,
1572
- [:login, nil],
1573
- :options => [NIC_ID, CMD, SSH_OPTS] do
1574
- helper.perform_action(args[0], options, 'SSH') do |vm|
1575
- rc = vm.info
1576
-
1577
- if OpenNebula.is_error?(rc)
1578
- STDERR.puts rc.message
1579
- exit(-1)
1580
- end
1581
-
1582
- # Get user to login
1583
- args[1].nil? ? login = 'root' : login = args[1]
1584
-
1585
- # Get CMD to run
1586
- options[:cmd].nil? ? cmd = '' : cmd = options[:cmd]
1587
-
1588
- # Get NIC to connect
1589
- if options[:nic_id]
1590
- nic = vm.retrieve_xmlelements(
1591
- "//TEMPLATE/NIC[NIC_ID=\"#{options[:nic_id]}\"]"
1592
- )[0]
1593
- else
1594
- nic = vm.retrieve_xmlelements('//TEMPLATE/NIC[SSH="YES"]')[0]
1595
- end
1596
-
1597
- nic = vm.retrieve_xmlelements('//TEMPLATE/NIC[1]')[0] if nic.nil?
1598
-
1599
- if nic.nil?
1600
- STDERR.puts 'No NIC found'
1601
- exit(-1)
1602
- end
1603
-
1604
- # If there is node port
1605
- if nic['EXTERNAL_PORT_RANGE']
1606
- ip = vm.to_hash['VM']['HISTORY_RECORDS']['HISTORY']
1607
- ip = [ip].flatten[-1]['HOSTNAME']
1608
- port = Integer(nic['EXTERNAL_PORT_RANGE'].split(':')[0]) + 21
1609
- else
1610
- ip = nic['IP']
1611
- port = 22
1612
- end
1613
-
1614
- options[:ssh_opts].nil? ? opts = '' : opts = options[:ssh_opts]
1615
-
1616
- system("ssh #{opts} #{login}@#{ip} -p #{port} #{cmd}")
1617
- end
1618
-
1619
- $?.exitstatus
1620
- end
1621
-
1622
- port_desc = <<-EOT.unindent
1623
- Get port forwarding from a NIC, e.g:
1624
-
1625
- 1.2.3.4@4000 -> 1, means that to connect to VM port 1, you need to
1626
- connect to IP 1.2.3.4 in port 4000
1627
- EOT
1628
-
1629
- command :'port-forward',
1630
- port_desc,
1631
- :vmid,
1632
- [:port, nil],
1633
- :options => NIC_ID do
1634
- helper.perform_action(args[0], options, 'Port Forward') do |vm|
1635
- rc = vm.info
1636
-
1637
- if OpenNebula.is_error?(rc)
1638
- STDERR.puts rc.message
1639
- exit(-1)
1640
- end
1641
-
1642
- if options[:nic_id]
1643
- nic = vm.retrieve_xmlelements(
1644
- "//TEMPLATE/NIC[NIC_ID=\"#{options[:nic_id]}\"]"
1645
- )[0]
1646
- else
1647
- nic = vm.retrieve_xmlelements('//TEMPLATE/NIC[SSH="YES"]')[0]
1648
- end
1649
-
1650
- nic = vm.retrieve_xmlelements('//TEMPLATE/NIC[1]')[0] if nic.nil?
1651
-
1652
- if nic.nil?
1653
- STDERR.puts 'No NIC found'
1654
- exit(-1)
1655
- end
1656
-
1657
- if nic['EXTERNAL_PORT_RANGE'].nil?
1658
- STDERR.puts 'No PORT_RANGE found'
1659
- exit(-1)
1660
- end
1661
-
1662
- ip = vm.to_hash['VM']['HISTORY_RECORDS']['HISTORY'][-1]['HOSTNAME']
1663
-
1664
- e_range = nic['EXTERNAL_PORT_RANGE'].split(':')
1665
- e_start_p = Integer(e_range[0])
1666
- e_end_p = Integer(e_range[1])
1667
-
1668
- i_range = nic['INTERNAL_PORT_RANGE'].split('-')
1669
- i_start_p = Integer(i_range[0])
1670
- i_end_p = Integer(i_range[1].split('/')[0])
1671
-
1672
- if args[1].nil?
1673
- [*e_start_p..e_end_p].zip([*i_start_p..i_end_p]) do |p1, p2|
1674
- puts "#{ip}@#{p1} -> #{p2}"
1675
- end
1676
- else
1677
- puts "#{ip}@#{e_start_p + Integer(args[1]) - 1} -> #{args[1]}"
1678
- end
1679
- end
1680
-
1681
- end
1682
-
1683
1521
  # Deprecated commands
1684
1522
 
1685
1523
  deprecated_command(:shutdown, 'terminate')