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/onevmgroup 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'
@@ -231,9 +242,9 @@ CommandParser::CmdParser.new(ARGV) do
231
242
  [Admin]: locks only Admin actions.
232
243
  EOT
233
244
 
234
- command :lock, lock_desc, :vmgroupid,
245
+ command :lock, lock_desc, [:range, :vmgroupid_list],
235
246
  :options => [USE, MANAGE, ADMIN, ALL] do
236
- helper.perform_action(args[0], options, 'VMGroup locked') do |vmg|
247
+ helper.perform_actions(args[0], options, 'VMGroup locked') do |vmg|
237
248
  if !options[:use].nil?
238
249
  level = 1
239
250
  elsif !options[:manage].nil?
@@ -254,8 +265,8 @@ CommandParser::CmdParser.new(ARGV) do
254
265
  Valid states are: All.
255
266
  EOT
256
267
 
257
- command :unlock, unlock_desc, :vmgroupid do
258
- helper.perform_action(args[0], options, 'VMGroup unlocked') do |vmg|
268
+ command :unlock, unlock_desc, [:range, :vmgroupid_list] do
269
+ helper.perform_actions(args[0], options, 'VMGroup unlocked') do |vmg|
259
270
  vmg.unlock
260
271
  end
261
272
  end
data/bin/onevnet 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'
@@ -379,9 +390,9 @@ CommandParser::CmdParser.new(ARGV) do
379
390
  [Admin]: locks only Admin actions.
380
391
  EOT
381
392
 
382
- command :lock, lock_desc, :vnetid,
393
+ command :lock, lock_desc, [:range, :vnetid_list],
383
394
  :options => [USE, MANAGE, ADMIN, ALL] do
384
- helper.perform_action(args[0], options, 'VNet locked') do |vnet|
395
+ helper.perform_actions(args[0], options, 'VNet locked') do |vnet|
385
396
  if !options[:use].nil?
386
397
  level = 1
387
398
  elsif !options[:manage].nil?
@@ -402,8 +413,8 @@ CommandParser::CmdParser.new(ARGV) do
402
413
  Valid states are: All.
403
414
  EOT
404
415
 
405
- command :unlock, unlock_desc, :vnetid do
406
- helper.perform_action(args[0], options, 'VNet unlocked') do |vnet|
416
+ command :unlock, unlock_desc, [:range, :vnetid_list] do
417
+ helper.perform_actions(args[0], options, 'VNet unlocked') do |vnet|
407
418
  vnet.unlock
408
419
  end
409
420
  end
data/bin/onevntemplate 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'
@@ -339,9 +350,9 @@ CommandParser::CmdParser.new(ARGV) do
339
350
  [Admin]: locks only Admin actions.
340
351
  EOT
341
352
 
342
- command :lock, lock_desc, :templateid,
353
+ command :lock, lock_desc, [:range, :templateid_list],
343
354
  :options => [USE, MANAGE, ADMIN, ALL] do
344
- helper.perform_action(args[0], options, 'VN Template locked') do |t|
355
+ helper.perform_actions(args[0], options, 'VN Template locked') do |t|
345
356
  if !options[:use].nil?
346
357
  level = 1
347
358
  elsif !options[:manage].nil?
@@ -362,8 +373,8 @@ CommandParser::CmdParser.new(ARGV) do
362
373
  Valid states are: All.
363
374
  EOT
364
375
 
365
- command :unlock, unlock_desc, :templateid do
366
- helper.perform_action(args[0], options, 'VN Template unlocked') do |t|
376
+ command :unlock, unlock_desc, [:range, :templateid_list] do
377
+ helper.perform_actions(args[0], options, 'VN Template unlocked') do |t|
367
378
  t.unlock
368
379
  end
369
380
  end
data/bin/onevrouter 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'
@@ -364,9 +375,9 @@ CommandParser::CmdParser.new(ARGV) do
364
375
  [Admin]: locks only Admin actions.
365
376
  EOT
366
377
 
367
- command :lock, lock_desc, :vrouterid,
378
+ command :lock, lock_desc, [:range, :vrouterid_list],
368
379
  :options => [USE, MANAGE, ADMIN, ALL] do
369
- helper.perform_action(args[0], options, 'VRouter locked') do |vr|
380
+ helper.perform_actions(args[0], options, 'VRouter locked') do |vr|
370
381
  if !options[:use].nil?
371
382
  level = 1
372
383
  elsif !options[:manage].nil?
@@ -387,8 +398,8 @@ CommandParser::CmdParser.new(ARGV) do
387
398
  valid states are: All.
388
399
  EOT
389
400
 
390
- command :unlock, unlock_desc, :vrouterid do
391
- helper.perform_action(args[0], options, 'VRouter unlocked') do |vr|
401
+ command :unlock, unlock_desc, [:range, :vrouterid_list] do
402
+ helper.perform_actions(args[0], options, 'VRouter unlocked') do |vr|
392
403
  vr.unlock
393
404
  end
394
405
  end
data/bin/onezone 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'
@@ -254,7 +265,7 @@ CommandParser::CmdParser.new(ARGV) do
254
265
  end
255
266
 
256
267
  server = Replicator.new('/var/lib/one/.ssh/id_rsa', args[0])
257
- server.process_files(options.key?(:database))
268
+ server.process_files(options[:db])
258
269
 
259
270
  0
260
271
  end
data/lib/one_helper.rb CHANGED
@@ -710,8 +710,8 @@ EOT
710
710
  elements, hash = print_page(pool, options)
711
711
 
712
712
  if options[:ids] && elements
713
- arr = [hash[pool.pool_name][pool.element_name]].flatten
714
- arr.reject! do |element|
713
+ hash = [hash[pool.pool_name][pool.element_name]].flatten
714
+ hash.reject! do |element|
715
715
  !options[:ids].include?(element['ID'].to_i)
716
716
  end
717
717
  end
@@ -16,73 +16,71 @@
16
16
 
17
17
  require 'one_helper'
18
18
 
19
+ # OneCluster CLI command helper
19
20
  class OneClusterHelper < OpenNebulaHelper::OneHelper
20
21
 
21
22
  CLUSTER = {
22
- :name => "cluster",
23
- :short => "-c id|name",
24
- :large => "--cluster id|name" ,
25
- :description => "Selects the cluster",
23
+ :name => 'cluster',
24
+ :short => '-c id|name',
25
+ :large => '--cluster id|name',
26
+ :description => 'Selects the cluster',
26
27
  :format => String,
27
- :proc => lambda { |o, options|
28
- OpenNebulaHelper.rname_to_id(o, "CLUSTER")
28
+ :proc => lambda {|o, _options|
29
+ OpenNebulaHelper.rname_to_id(o, 'CLUSTER')
29
30
  }
30
31
  }
31
32
 
32
33
  def self.rname
33
- "CLUSTER"
34
+ 'CLUSTER'
34
35
  end
35
36
 
36
37
  def self.conf_file
37
- "onecluster.yaml"
38
+ 'onecluster.yaml'
38
39
  end
39
40
 
40
41
  def element_size(ehash, ename)
41
- ids = ehash[ename]["ID"]
42
+ ids = ehash[ename]['ID']
42
43
 
43
44
  if ids.nil?
44
- return 0
45
+ 0
45
46
  elsif ids.class == String
46
- return 1
47
+ 1
47
48
  else
48
- return ids.size
49
+ ids.size
49
50
  end
50
51
  end
51
52
 
52
-
53
- def format_pool(options)
53
+ def format_pool(_options)
54
54
  config_file = self.class.table_conf
55
55
 
56
- table = CLIHelper::ShowTable.new(config_file, self) do
57
- column :ID, "ONE identifier for the Cluster", :size=>5 do |d|
58
- d["ID"]
56
+ CLIHelper::ShowTable.new(config_file, self) do
57
+ column :ID, 'ONE identifier for the Cluster', :size=>5 do |d|
58
+ d['ID']
59
59
  end
60
60
 
61
- column :NAME, "Name of the Cluster", :left, :size=>25 do |d|
62
- d["NAME"]
61
+ column :NAME, 'Name of the Cluster', :left, :size=>25 do |d|
62
+ d['NAME']
63
63
  end
64
64
 
65
- column :HOSTS, "Number of Hosts", :size=>5 do |d|
66
- @ext.element_size(d,"HOSTS") rescue 0
65
+ column :HOSTS, 'Number of Hosts', :size=>5 do |d|
66
+ @ext.element_size(d, 'HOSTS') rescue 0
67
67
  end
68
68
 
69
- column :VNETS, "Number of Networks", :size=>5 do |d|
70
- @ext.element_size(d,"VNETS") rescue 0
69
+ column :VNETS, 'Number of Networks', :size=>5 do |d|
70
+ @ext.element_size(d, 'VNETS') rescue 0
71
71
  end
72
72
 
73
- column :DATASTORES, "Number of Datastores", :size=>10 do |d|
74
- @ext.element_size(d,"DATASTORES") rescue 0
73
+ column :DATASTORES, 'Number of Datastores', :size=>10 do |d|
74
+ @ext.element_size(d, 'DATASTORES') rescue 0
75
75
  end
76
76
 
77
77
  default :ID, :NAME, :HOSTS, :VNETS, :DATASTORES
78
78
  end
79
-
80
- table
81
79
  end
82
80
 
83
81
  private
84
82
 
85
- def factory(id=nil)
83
+ def factory(id = nil)
86
84
  if id
87
85
  OpenNebula::Cluster.new_with_id(id, @client)
88
86
  else
@@ -91,39 +89,74 @@ class OneClusterHelper < OpenNebulaHelper::OneHelper
91
89
  end
92
90
  end
93
91
 
94
- def factory_pool(user_flag=-2)
92
+ def factory_pool(_user_flag = -2)
95
93
  OpenNebula::ClusterPool.new(@client)
96
94
  end
97
95
 
98
- def format_resource(cluster, options = {})
99
- str="%-18s: %-20s"
100
- str_h1="%-80s"
96
+ def format_resource(cluster, _options = {})
97
+ str='%-18s: %-20s'
98
+ str_h1='%-80s'
101
99
 
102
100
  CLIHelper.print_header(str_h1 % "CLUSTER #{cluster['ID']} INFORMATION")
103
- puts str % ["ID", cluster.id.to_s]
104
- puts str % ["NAME", cluster.name]
101
+ puts format(str, 'ID', cluster.id.to_s)
102
+ puts format(str, 'NAME', cluster.name)
103
+
105
104
  puts
105
+ CLIHelper.print_header(str_h1 % 'CLUSTER RESOURCES', false)
106
+ cluster.info!
106
107
 
107
- CLIHelper.print_header(str_h1 % "CLUSTER TEMPLATE", false)
108
- puts cluster.template_str
108
+ hosts = cluster.to_hash['CLUSTER']['HOSTS']['ID']
109
+
110
+ if hosts
111
+ total_cpu = 0
112
+ used_cpu = 0
113
+ total_ram = 0
114
+ used_ram = 0
115
+
116
+ [hosts].flatten.each do |h|
117
+ h = OpenNebula::Host.new_with_id(h, @client)
118
+
119
+ h.info!
120
+
121
+ h = h.to_hash
122
+ h = h['HOST']['HOST_SHARE']
123
+
124
+ total_cpu += h['TOTAL_CPU'].to_i / 100
125
+ used_cpu += h['CPU_USAGE'].to_i / 100
126
+ total_ram += h['TOTAL_MEM'].to_i / 1024 / 1024
127
+ used_ram += h['MEM_USAGE'].to_i / 1024 / 1024
128
+ end
129
+
130
+ puts "TOTAL CPUs: #{total_cpu}"
131
+ puts "OCCUPIED CPUs: #{used_cpu}"
132
+ puts "AVAILABLE CPUs: #{total_cpu - used_cpu}"
133
+ puts
134
+ puts "TOTAL RAM: #{total_ram}"
135
+ puts "OCCUPIED RAM: #{used_ram}"
136
+ puts "AVAILABLE RAM: #{total_ram - used_ram}"
137
+ end
109
138
 
110
139
  puts
140
+ CLIHelper.print_header(str_h1 % 'CLUSTER TEMPLATE', false)
141
+ puts cluster.template_str
111
142
 
112
- CLIHelper.print_header("%-15s" % ["HOSTS"])
143
+ puts
144
+ CLIHelper.print_header(format('%-15s', 'HOSTS'))
113
145
  cluster.host_ids.each do |id|
114
- puts "%-15s" % [id]
146
+ puts format('%-15s', id)
115
147
  end
116
148
 
117
149
  puts
118
- CLIHelper.print_header("%-15s" % ["VNETS"])
150
+ CLIHelper.print_header(format('%-15s', 'VNETS'))
119
151
  cluster.vnet_ids.each do |id|
120
- puts "%-15s" % [id]
152
+ puts format('%-15s', id)
121
153
  end
122
154
 
123
155
  puts
124
- CLIHelper.print_header("%-15s" % ["DATASTORES"])
156
+ CLIHelper.print_header(format('%-15s', 'DATASTORES'))
125
157
  cluster.datastore_ids.each do |id|
126
- puts "%-15s" % [id]
158
+ puts format('%-15s', id)
127
159
  end
128
160
  end
161
+
129
162
  end
@@ -1086,6 +1086,26 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
1086
1086
  end
1087
1087
  end
1088
1088
 
1089
+ if vm_hash['VM']['TEMPLATE']['NIC']
1090
+ nic = [vm_hash['VM']['TEMPLATE']['NIC']]
1091
+ nic = nic.flatten
1092
+ nic = nic.select {|v| !v['EXTERNAL_PORT_RANGE'].nil? }[0]
1093
+
1094
+ if nic
1095
+ ip = vm_hash['VM']['HISTORY_RECORDS']['HISTORY']
1096
+ ip = [ip].flatten[-1]['HOSTNAME']
1097
+ port = Integer(nic['EXTERNAL_PORT_RANGE'].split(':')[0]) + 21
1098
+
1099
+ puts
1100
+ CLIHelper.print_header(str_h1 % 'PORT FORWARD', false)
1101
+
1102
+ puts "[#{nic['EXTERNAL_PORT_RANGE']}]:" \
1103
+ "[#{nic['INTERNAL_PORT_RANGE'].split('/')[0]}]"
1104
+
1105
+ puts "SSH on #{ip} at port #{port}"
1106
+ end
1107
+ end
1108
+
1089
1109
  if !options[:all]
1090
1110
  while vm.has_elements?('/VM/TEMPLATE/NIC')
1091
1111
  vm.delete_element('/VM/TEMPLATE/NIC')