opennebula-cli 6.0.0.1 → 6.0.0.2

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,14 +26,25 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
+ # %%RUBYGEMS_SETUP_BEGIN%%
29
30
  if File.directory?(GEMS_LOCATION)
30
31
  real_gems_path = File.realpath(GEMS_LOCATION)
31
32
  if !defined?(Gem) || Gem.path != [real_gems_path]
32
33
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
- require 'rubygems'
34
- Gem.use_paths(real_gems_path)
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
35
45
  end
36
46
  end
47
+ # %%RUBYGEMS_SETUP_END%%
37
48
 
38
49
  $LOAD_PATH << RUBY_LIB_LOCATION
39
50
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
data/bin/onetemplate CHANGED
@@ -26,14 +26,25 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
+ # %%RUBYGEMS_SETUP_BEGIN%%
29
30
  if File.directory?(GEMS_LOCATION)
30
31
  real_gems_path = File.realpath(GEMS_LOCATION)
31
32
  if !defined?(Gem) || Gem.path != [real_gems_path]
32
33
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
- require 'rubygems'
34
- Gem.use_paths(real_gems_path)
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
35
45
  end
36
46
  end
47
+ # %%RUBYGEMS_SETUP_END%%
37
48
 
38
49
  $LOAD_PATH << RUBY_LIB_LOCATION
39
50
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
@@ -214,8 +225,17 @@ CommandParser::CmdParser.new(ARGV) do
214
225
  Creates a new VM instance from the given Template. This VM can be
215
226
  managed with the 'onevm' command.
216
227
 
217
- The source Template can be modified adding or replacing attributes with
218
- the optional file argument, or with the options.
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
219
239
  EOT
220
240
 
221
241
  command :instantiate, instantiate_desc, :templateid, [:file, nil],
@@ -395,9 +415,9 @@ CommandParser::CmdParser.new(ARGV) do
395
415
  [Admin]: locks only Admin actions.
396
416
  EOT
397
417
 
398
- command :lock, lock_desc, :templateid,
418
+ command :lock, lock_desc, [:range, :templateid_list],
399
419
  :options => [USE, MANAGE, ADMIN, ALL] do
400
- helper.perform_action(args[0], options, 'Template locked') do |t|
420
+ helper.perform_actions(args[0], options, 'Template locked') do |t|
401
421
  if !options[:use].nil?
402
422
  level = 1
403
423
  elsif !options[:manage].nil?
@@ -418,8 +438,8 @@ CommandParser::CmdParser.new(ARGV) do
418
438
  Valid states are: All.
419
439
  EOT
420
440
 
421
- command :unlock, unlock_desc, :templateid do
422
- helper.perform_action(args[0], options, 'Template unlocked') do |t|
441
+ command :unlock, unlock_desc, [:range, :templateid_list] do
442
+ helper.perform_actions(args[0], options, 'Template unlocked') do |t|
423
443
  t.unlock
424
444
  end
425
445
  end
data/bin/oneuser CHANGED
@@ -26,14 +26,25 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
+ # %%RUBYGEMS_SETUP_BEGIN%%
29
30
  if File.directory?(GEMS_LOCATION)
30
31
  real_gems_path = File.realpath(GEMS_LOCATION)
31
32
  if !defined?(Gem) || Gem.path != [real_gems_path]
32
33
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
- require 'rubygems'
34
- Gem.use_paths(real_gems_path)
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
35
45
  end
36
46
  end
47
+ # %%RUBYGEMS_SETUP_END%%
37
48
 
38
49
  $LOAD_PATH << RUBY_LIB_LOCATION
39
50
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
data/bin/onevcenter CHANGED
@@ -28,14 +28,25 @@ else
28
28
  REMOTES_LOCATION = ONE_LOCATION + '/var/remotes/'
29
29
  end
30
30
 
31
+ # %%RUBYGEMS_SETUP_BEGIN%%
31
32
  if File.directory?(GEMS_LOCATION)
32
33
  real_gems_path = File.realpath(GEMS_LOCATION)
33
34
  if !defined?(Gem) || Gem.path != [real_gems_path]
34
35
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
35
- require 'rubygems'
36
- Gem.use_paths(real_gems_path)
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
37
47
  end
38
48
  end
49
+ # %%RUBYGEMS_SETUP_END%%
39
50
 
40
51
  $LOAD_PATH << RUBY_LIB_LOCATION
41
52
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
@@ -261,7 +272,7 @@ CommandParser::CmdParser.new(ARGV) do
261
272
  vi_client,
262
273
  options[:object])
263
274
 
264
- if options[:object] == "networks" && !args.first.nil?
275
+ if options[:object] == 'networks' && !args.first.nil?
265
276
  indexes = args.first
266
277
  else
267
278
  importer.retrieve_resources(helper.parse_opts(options))
data/bin/onevdc CHANGED
@@ -26,14 +26,25 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
+ # %%RUBYGEMS_SETUP_BEGIN%%
29
30
  if File.directory?(GEMS_LOCATION)
30
31
  real_gems_path = File.realpath(GEMS_LOCATION)
31
32
  if !defined?(Gem) || Gem.path != [real_gems_path]
32
33
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
- require 'rubygems'
34
- Gem.use_paths(real_gems_path)
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
35
45
  end
36
46
  end
47
+ # %%RUBYGEMS_SETUP_END%%
37
48
 
38
49
  $LOAD_PATH << RUBY_LIB_LOCATION
39
50
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
data/bin/onevm CHANGED
@@ -26,14 +26,25 @@ else
26
26
  GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
27
  end
28
28
 
29
+ # %%RUBYGEMS_SETUP_BEGIN%%
29
30
  if File.directory?(GEMS_LOCATION)
30
31
  real_gems_path = File.realpath(GEMS_LOCATION)
31
32
  if !defined?(Gem) || Gem.path != [real_gems_path]
32
33
  $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
33
- require 'rubygems'
34
- Gem.use_paths(real_gems_path)
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
35
45
  end
36
46
  end
47
+ # %%RUBYGEMS_SETUP_END%%
37
48
 
38
49
  $LOAD_PATH << RUBY_LIB_LOCATION
39
50
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
@@ -207,6 +218,27 @@ CommandParser::CmdParser.new(ARGV) do
207
218
  :description => 'Market to save oneshot'
208
219
  }
209
220
 
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
+
210
242
  ########################################################################
211
243
  # Global Options
212
244
  ########################################################################
@@ -1310,9 +1342,9 @@ CommandParser::CmdParser.new(ARGV) do
1310
1342
  Valid states are: All.
1311
1343
  EOT
1312
1344
 
1313
- command :lock, lock_desc, :vmid,
1345
+ command :lock, lock_desc, [:range, :vmid_list],
1314
1346
  :options => [USE, MANAGE, ADMIN, ALL] do
1315
- helper.perform_action(args[0], options, 'VM locked') do |vm|
1347
+ helper.perform_actions(args[0], options, 'VM locked') do |vm|
1316
1348
  if !options[:use].nil?
1317
1349
  level = 1
1318
1350
  elsif !options[:manage].nil?
@@ -1333,8 +1365,8 @@ CommandParser::CmdParser.new(ARGV) do
1333
1365
  Valid states are: All.
1334
1366
  EOT
1335
1367
 
1336
- command :unlock, unlock_desc, :vmid do
1337
- helper.perform_action(args[0], options, 'VM unlocked') do |vm|
1368
+ command :unlock, unlock_desc, [:range, :vmid_list] do
1369
+ helper.perform_actions(args[0], options, 'VM unlocked') do |vm|
1338
1370
  vm.unlock
1339
1371
  end
1340
1372
  end
@@ -1347,7 +1379,7 @@ CommandParser::CmdParser.new(ARGV) do
1347
1379
  You can configure the actions in /etc/one/cli/onevm.yaml
1348
1380
  EOT
1349
1381
 
1350
- command :'create-chart', create_chart_desc, [:range, :vmid_list] do
1382
+ command :'create-chart', create_chart_desc, :vmid do
1351
1383
  charters = helper.get_charters
1352
1384
 
1353
1385
  if charters.nil?
@@ -1361,7 +1393,7 @@ CommandParser::CmdParser.new(ARGV) do
1361
1393
  charters.each do |action, time|
1362
1394
  sched = "+#{time[:time].to_i + acc_t}"
1363
1395
 
1364
- helper.schedule_actions(args[0],
1396
+ helper.schedule_actions([args[0]].flatten,
1365
1397
  { :schedule => sched },
1366
1398
  action.to_s,
1367
1399
  time[:warning][:time] + acc_w)
@@ -1437,25 +1469,33 @@ CommandParser::CmdParser.new(ARGV) do
1437
1469
  helper.perform_action(args[0], options, 'Backup') do |vm|
1438
1470
  vm.extend(OpenNebula::VirtualMachineExt)
1439
1471
 
1440
- # If logger is specified use it, if not use STDOUT
1441
- options[:logger].nil? ? log_to = STDOUT : log_to = options[:logger]
1442
-
1443
1472
  # Read user options
1444
- keep = options.key?(:keep)
1445
- logger = Logger.new(log_to)
1446
- format = '%Y-%m-%d %H:%M:%S'
1473
+ if options[:verbose]
1474
+ log_to = STDOUT
1475
+ elsif !options[:logger].nil?
1476
+ log_to = options[:logger]
1477
+ end
1447
1478
 
1448
- logger.formatter = proc do |severity, datetime, _p, msg|
1449
- "#{datetime.strftime(format)} #{severity.ljust(5)} : #{msg}\n"
1479
+ keep = options.key?(:keep)
1480
+
1481
+ if log_to
1482
+ logger = Logger.new(log_to)
1483
+ format = '%Y-%m-%d %H:%M:%S'
1484
+
1485
+ logger.formatter = proc do |severity, datetime, _p, msg|
1486
+ "#{datetime.strftime(format)} " \
1487
+ "#{severity.ljust(5)} : #{msg}\n"
1488
+ end
1450
1489
  end
1451
1490
 
1491
+ binfo = {}
1492
+ binfo[:market] = options[:market]
1493
+
1452
1494
  if options.key?(:oneshot)
1453
- binfo = {}
1454
1495
  binfo[:name] = "VM #{vm.id} BACKUP - " \
1455
1496
  "#{Time.now.strftime('%Y%m%d_%k%M')}"
1456
1497
  binfo[:freq] = 1
1457
1498
  binfo[:last] = Time.now.to_i - 100
1458
- binfo[:market] = options[:market]
1459
1499
  end
1460
1500
 
1461
1501
  begin
@@ -1518,6 +1558,128 @@ CommandParser::CmdParser.new(ARGV) do
1518
1558
  end
1519
1559
  end
1520
1560
 
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
+
1521
1683
  # Deprecated commands
1522
1684
 
1523
1685
  deprecated_command(:shutdown, 'terminate')