opennebula-cli 7.0.2 → 7.2.0

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/bin/oneacct +1 -1
  3. data/bin/oneacl +1 -1
  4. data/bin/onebackupjob +1 -1
  5. data/bin/onecluster +1 -1
  6. data/bin/onedatastore +1 -1
  7. data/bin/oneflow +1 -1
  8. data/bin/oneflow-template +1 -1
  9. data/bin/oneform +150 -0
  10. data/bin/onegroup +1 -1
  11. data/bin/onehook +1 -1
  12. data/bin/onehost +1 -1
  13. data/bin/oneimage +1 -1
  14. data/bin/oneirb +1 -1
  15. data/bin/onelog +1 -1
  16. data/bin/onemarket +1 -1
  17. data/bin/onemarketapp +4 -1
  18. data/bin/onesecgroup +1 -1
  19. data/bin/oneshowback +1 -1
  20. data/bin/onetemplate +16 -5
  21. data/bin/oneuser +3 -2
  22. data/bin/onevdc +1 -1
  23. data/bin/onevm +51 -6
  24. data/bin/onevmgroup +1 -1
  25. data/bin/onevnet +1 -1
  26. data/bin/onevntemplate +3 -2
  27. data/bin/onevrouter +1 -1
  28. data/bin/onezone +12 -6
  29. data/lib/cli_helper.rb +153 -1
  30. data/lib/command_parser.rb +1 -1
  31. data/lib/one_helper/oneacct_helper.rb +3 -1
  32. data/lib/one_helper/oneacl_helper.rb +3 -1
  33. data/lib/one_helper/onebackupjob_helper.rb +3 -1
  34. data/lib/one_helper/onecluster_helper.rb +4 -1
  35. data/lib/one_helper/onedatastore_helper.rb +4 -1
  36. data/lib/one_helper/oneflow_helper.rb +1 -1
  37. data/lib/one_helper/oneflowtemplate_helper.rb +1 -1
  38. data/lib/one_helper/oneform_helper.rb +255 -0
  39. data/lib/one_helper/onegroup_helper.rb +133 -98
  40. data/lib/one_helper/onehook_helper.rb +5 -2
  41. data/lib/one_helper/onehost_helper.rb +6 -3
  42. data/lib/one_helper/oneimage_helper.rb +3 -1
  43. data/lib/one_helper/onemarket_helper.rb +3 -1
  44. data/lib/one_helper/onemarketapp_helper.rb +4 -1
  45. data/lib/one_helper/onequota_helper.rb +105 -22
  46. data/lib/one_helper/onesecgroup_helper.rb +3 -1
  47. data/lib/one_helper/onetemplate_helper.rb +3 -2
  48. data/lib/one_helper/oneuser_helper.rb +165 -156
  49. data/lib/one_helper/onevdc_helper.rb +3 -1
  50. data/lib/one_helper/onevm_helper.rb +6 -2
  51. data/lib/one_helper/onevmgroup_helper.rb +3 -1
  52. data/lib/one_helper/onevnet_helper.rb +16 -5
  53. data/lib/one_helper/onevntemplate_helper.rb +3 -2
  54. data/lib/one_helper/onevrouter_helper.rb +3 -1
  55. data/lib/one_helper/onezone_helper.rb +16 -5
  56. data/lib/one_helper.rb +53 -18
  57. data/share/schemas/xsd/group.xsd +8 -0
  58. data/share/schemas/xsd/group_pool.xsd +8 -0
  59. data/share/schemas/xsd/opennebula_configuration.xsd +6 -10
  60. data/share/schemas/xsd/shared.xsd +8 -0
  61. data/share/schemas/xsd/user.xsd +8 -0
  62. data/share/schemas/xsd/user_pool.xsd +8 -0
  63. data/share/schemas/xsd/vm.xsd +20 -0
  64. data/share/schemas/xsd/vnet.xsd +2 -1
  65. data/share/schemas/xsd/vnet_pool.xsd +1 -0
  66. metadata +7 -4
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2025, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2026, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -16,44 +16,51 @@
16
16
 
17
17
  require 'one_helper'
18
18
  require 'one_helper/onequota_helper'
19
+ require 'opennebula/user'
20
+ require 'opennebula/user_pool'
19
21
 
22
+ require 'fileutils'
20
23
  require 'digest/md5'
21
24
 
22
25
  # Interface for OpenNebula generated tokens.
23
26
  class TokenAuth
24
- def login_token(username, expire)
27
+
28
+ def login_token(_username, _expire)
25
29
  return OpenNebulaHelper::OneHelper.get_password
26
30
  end
31
+
27
32
  end
28
33
 
34
+ # CLI helper for oneuser command
29
35
  class OneUserHelper < OpenNebulaHelper::OneHelper
36
+
30
37
  if ENV['ONE_AUTH']
31
38
  ONE_AUTH = ENV['ONE_AUTH']
32
39
  else
33
- if ENV['HOME']
34
- ONE_AUTH = ENV['HOME']+'/.one/one_auth'
40
+ if Dir.home
41
+ ONE_AUTH = Dir.home + '/.one/one_auth'
35
42
  else
36
- ONE_AUTH = "/var/lib/one/.one/one_auth"
43
+ ONE_AUTH = '/var/lib/one/.one/one_auth'
37
44
  end
38
45
  end
39
46
 
40
47
  def self.rname
41
- "USER"
48
+ 'USER'
42
49
  end
43
50
 
44
51
  def self.conf_file
45
- "oneuser.yaml"
52
+ 'oneuser.yaml'
46
53
  end
47
54
 
48
55
  def self.password_to_str_desc
49
- "User password"
56
+ 'User password'
50
57
  end
51
58
 
52
59
  def self.password_to_str(arg, options)
53
60
  if options[:read_file]
54
61
  begin
55
62
  password = File.read(arg).split("\n").first
56
- rescue
63
+ rescue StandardError
57
64
  return -1, "Cannot read file: #{arg}"
58
65
  end
59
66
  else
@@ -77,21 +84,21 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
77
84
  case options[:driver]
78
85
  when OpenNebula::User::SSH_AUTH
79
86
  if !options[:key]
80
- return -1, "You have to specify the --key option"
87
+ return -1, 'You have to specify the --key option'
81
88
  end
82
89
 
83
90
  require 'opennebula/ssh_auth'
84
91
 
85
92
  begin
86
93
  auth = OpenNebula::SshAuth.new(:private_key=>options[:key])
87
- rescue Exception => e
94
+ rescue StandardError => e
88
95
  return -1, e.message
89
96
  end
90
97
  when OpenNebula::User::X509_AUTH
91
98
  options[:cert] ||= ENV['X509_USER_CERT']
92
99
 
93
100
  if !options[:cert]
94
- return -1, "You have to specify the --cert option"
101
+ return -1, 'You have to specify the --cert option'
95
102
  end
96
103
 
97
104
  require 'opennebula/x509_auth'
@@ -99,7 +106,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
99
106
  begin
100
107
  cert = [File.read(options[:cert])]
101
108
  auth = OpenNebula::X509Auth.new(:certs_pem=>cert)
102
- rescue Exception => e
109
+ rescue StandardError => e
103
110
  return -1, e.message
104
111
  end
105
112
  else
@@ -111,7 +118,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
111
118
 
112
119
  def auth_file(auth_string)
113
120
  auth_filename = Digest::MD5.hexdigest(auth_string)
114
- ENV['HOME'] + "/.one/#{auth_filename}.token"
121
+ Dir.home + "/.one/#{auth_filename}.token"
115
122
  end
116
123
 
117
124
  def get_login_client(username, options)
@@ -122,11 +129,11 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
122
129
  when OpenNebula::User::SSH_AUTH
123
130
  require 'opennebula/ssh_auth'
124
131
 
125
- options[:key] ||= ENV['HOME']+'/.ssh/id_rsa'
132
+ options[:key] ||= Dir.home + '/.ssh/id_rsa'
126
133
 
127
134
  begin
128
135
  auth = OpenNebula::SshAuth.new(:private_key=>options[:key])
129
- rescue Exception => e
136
+ rescue StandardError => e
130
137
  return -1, e.message
131
138
  end
132
139
 
@@ -141,7 +148,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
141
148
  key = File.read(options[:key])
142
149
 
143
150
  auth = OpenNebula::X509Auth.new(:certs_pem=>certs, :key_pem=>key)
144
- rescue Exception => e
151
+ rescue StandardError => e
145
152
  return -1, e.message
146
153
  end
147
154
 
@@ -160,12 +167,12 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
160
167
  key= rc[1]
161
168
 
162
169
  auth = OpenNebula::X509Auth.new(:certs_pem=>certs, :key_pem=>key)
163
- rescue => e
170
+ rescue StandardError => e
164
171
  return -1, e.message
165
172
  end
166
173
 
167
174
  else
168
- auth = TokenAuth.new() #oned generated token
175
+ auth = TokenAuth.new # oned generated token
169
176
  end
170
177
 
171
178
  #-----------------------------------------------------------------------
@@ -194,11 +201,11 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
194
201
  ############################################################################
195
202
  # Generates a token and stores it in ONE_AUTH path as defined in this class
196
203
  ############################################################################
197
- def login(username, options, use_client=false)
204
+ def login(username, options, use_client = false)
198
205
  if use_client
199
206
  login_client = OpenNebulaHelper::OneHelper.get_client
200
207
  else
201
- login_client = self.get_login_client(username, options)
208
+ login_client = get_login_client(username, options)
202
209
  end
203
210
 
204
211
  if (login_client.is_a? Array) && login_client[0] == -1
@@ -209,7 +216,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
209
216
 
210
217
  egid = options[:group] || -1
211
218
 
212
- token_oned = user.login(username, "", options[:time], egid)
219
+ token_oned = user.login(username, '', options[:time], egid)
213
220
 
214
221
  return -1, token_oned.message if OpenNebula.is_error?(token_oned)
215
222
 
@@ -230,7 +237,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
230
237
  return 0, "File #{ONE_AUTH} exists, use --force to overwrite."\
231
238
  "\n#{token_info}"
232
239
  else
233
- puts "Not valid option."
240
+ puts 'Not valid option.'
234
241
  return -1
235
242
  end
236
243
  end
@@ -243,11 +250,11 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
243
250
  rescue Errno::EEXIST
244
251
  end
245
252
 
246
- file = File.open(ONE_AUTH, "w")
253
+ file = File.open(ONE_AUTH, 'w')
247
254
  file.write("#{username}:#{token_oned}")
248
255
  file.close
249
256
 
250
- File.chmod(0600, ONE_AUTH)
257
+ File.chmod(0o0600, ONE_AUTH)
251
258
 
252
259
  return 0, token_info
253
260
  end
@@ -255,20 +262,29 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
255
262
  def format_pool(options)
256
263
  config_file = self.class.table_conf
257
264
 
258
- table = CLIHelper::ShowTable.new(config_file, self) do
259
- def pool_default_quotas(path)
260
- @data.dsearch('/USER_POOL/DEFAULT_USER_QUOTAS/'+path)
265
+ # rubocop:disable Style/FormatStringToken
266
+ CLIHelper::ShowTable.new(config_file, self) do
267
+ pool_default_quotas = lambda do |path|
268
+ limit = @data.dsearch('/USER_POOL/DEFAULT_USER_QUOTAS/'+path)
269
+ limit = OneQuotaHelper::LIMIT_UNLIMITED if limit.nil? || limit.empty?
270
+ limit
261
271
  end
262
272
 
263
- def quotas
273
+ quotas_proc = lambda do
264
274
  if !defined?(@quotas)
265
275
  quotas = @data.dsearch('USER_POOL/QUOTAS')
266
- @quotas = Hash.new
276
+ @quotas = {}
267
277
 
268
- if (!quotas.nil?)
278
+ if !quotas.nil?
269
279
  quotas = [quotas].flatten
270
280
 
271
281
  quotas.each do |q|
282
+ # Fix rare bug, when there are multiple VM_QUOTA values
283
+ vm_quota = q['VM_QUOTA']
284
+ if vm_quota.is_a?(Array)
285
+ q['VM_QUOTA'] = vm_quota.max_by {|h| h.size }
286
+ end
287
+
272
288
  @quotas[q['ID']] = q
273
289
  end
274
290
  end
@@ -276,175 +292,174 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
276
292
  @quotas
277
293
  end
278
294
 
279
- column :ID, "ONE identifier for the User", :size=>4 do |d|
280
- d["ID"]
295
+ column :ID, 'ONE identifier for the User', :size=>4 do |d|
296
+ d['ID']
281
297
  end
282
298
 
283
- column :NAME, "Name of the User", :left, :size=>5 do |d|
284
- d["NAME"]
299
+ column :NAME, 'Name of the User', :left, :size=>5 do |d|
300
+ d['NAME']
285
301
  end
286
302
 
287
- column :ENABLED, "User is enabled", :left, :size=>4 do |d|
288
- if d["ENABLED"] == "1"
289
- "yes"
303
+ column :ENABLED, 'User is enabled', :left, :size=>4 do |d|
304
+ if d['ENABLED'] == '1'
305
+ 'yes'
290
306
  else
291
- "no"
307
+ 'no'
292
308
  end
293
309
  end
294
310
 
295
- column :GROUP, "Group of the User", :left, :size=>10 do |d|
311
+ column :GROUP, 'Group of the User', :left, :size=>10 do |d|
296
312
  helper.group_name(d, options)
297
313
  end
298
314
 
299
- column :AUTH, "Auth driver of the User", :left, :size=>8 do |d|
300
- d["AUTH_DRIVER"]
315
+ column :AUTH, 'Auth driver of the User', :left, :size=>8 do |d|
316
+ d['AUTH_DRIVER']
301
317
  end
302
318
 
303
- column :VMS , "Number of VMS", :size=>9 do |d|
319
+ column :VMS, 'Number of VMS', :size=>9 do |d|
304
320
  begin
305
- q = quotas[d['ID']]['VM_QUOTA']['VM']
321
+ q = quotas_proc.call[d['ID']]['VM_QUOTA']['VM']
306
322
 
307
- if q.nil? && d["ID"].to_i != 0
323
+ if q.nil? && d['ID'].to_i != 0
308
324
  q = OneQuotaHelper::DEFAULT_VM_QUOTA
309
325
  end
310
326
 
311
327
  # In case of multiple quotas, use the global quota or the first
312
328
  if q.is_a?(Array)
313
- global_quota = q.find{|hash| hash['CLUSTER_IDS'].nil? || hash['CLUSTER_IDS'].empty? }
314
- q = global_quota || q[0]
329
+ global_q = q.find {|h| h['CLUSTER_IDS'].nil? || h['CLUSTER_IDS'].empty? }
330
+ q = global_q || q[0]
315
331
  end
316
332
 
317
- limit = q["VMS"]
318
-
319
- if limit == OneQuotaHelper::LIMIT_DEFAULT
320
- limit = pool_default_quotas("VM_QUOTA/VM/VMS")
321
- if limit.nil? || limit == ""
322
- limit = OneQuotaHelper::LIMIT_UNLIMITED
323
- end
324
- end
333
+ limit = q['VMS']
334
+ limit = pool_default_quotas.call('VM_QUOTA/VM/VMS') if limit == OneQuotaHelper::LIMIT_DEFAULT
325
335
 
326
336
  if limit == OneQuotaHelper::LIMIT_UNLIMITED
327
- "%3d / -" % [q["VMS_USED"]]
337
+ format('%3d / -', q['VMS_USED'])
328
338
  else
329
- "%3d / %3d" % [q["VMS_USED"], limit]
339
+ format('%3d / %3d', q['VMS_USED'], limit)
330
340
  end
331
-
332
341
  rescue NoMethodError
333
- "-"
342
+ '-'
334
343
  end
335
344
  end
336
345
 
337
- column :MEMORY, "Total memory allocated to user VMs", :size=>17 do |d|
346
+ column :MEMORY, 'Total memory allocated to user VMs', :size=>15 do |d|
338
347
  begin
339
- q = quotas[d['ID']]['VM_QUOTA']['VM']
348
+ q = quotas_proc.call[d['ID']]['VM_QUOTA']['VM']
340
349
 
341
- if q.nil? && d["ID"].to_i != 0
350
+ if q.nil? && d['ID'].to_i != 0
342
351
  q = OneQuotaHelper::DEFAULT_VM_QUOTA
343
352
  end
344
353
 
345
354
  # In case of multiple quotas, use the global quota or the first
346
355
  if q.is_a?(Array)
347
- global_quota = q.find{|hash| hash['CLUSTER_IDS'].nil? || hash['CLUSTER_IDS'].empty? }
348
- q = global_quota || q[0]
356
+ global_q = q.find {|h| h['CLUSTER_IDS'].nil? || h['CLUSTER_IDS'].empty? }
357
+ q = global_q || q[0]
349
358
  end
350
359
 
351
- limit = q["MEMORY"]
352
-
353
- if limit == OneQuotaHelper::LIMIT_DEFAULT
354
- limit = pool_default_quotas("VM_QUOTA/VM/MEMORY")
355
- if limit.nil? || limit == ""
356
- limit = OneQuotaHelper::LIMIT_UNLIMITED
357
- end
358
- end
360
+ limit = q['MEMORY']
361
+ limit = pool_default_quotas.call('VM_QUOTA/VM/MEMORY') if limit == OneQuotaHelper::LIMIT_DEFAULT
359
362
 
360
363
  if limit == OneQuotaHelper::LIMIT_UNLIMITED
361
- "%7s / -" % [
362
- OpenNebulaHelper.unit_to_str(q["MEMORY_USED"].to_i,{},"M")]
364
+ format('%6s / -',
365
+ OpenNebulaHelper.unit_to_str(q['MEMORY_USED'].to_i, {}, 'M'))
363
366
  else
364
- "%7s / %7s" % [
365
- OpenNebulaHelper.unit_to_str(q["MEMORY_USED"].to_i,{},"M"),
366
- OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")]
367
+ format('%6s / %6s',
368
+ OpenNebulaHelper.unit_to_str(q['MEMORY_USED'].to_i, {}, 'M'),
369
+ OpenNebulaHelper.unit_to_str(limit.to_i, {}, 'M'))
367
370
  end
368
-
369
371
  rescue NoMethodError
370
- "-"
372
+ '-'
371
373
  end
372
374
  end
373
375
 
374
- column :CPU, "Total CPU allocated to user VMs", :size=>11 do |d|
376
+ column :CPU, 'Total CPU allocated to user VMs', :size=>11 do |d|
375
377
  begin
376
- q = quotas[d['ID']]['VM_QUOTA']['VM']
378
+ q = quotas_proc.call[d['ID']]['VM_QUOTA']['VM']
377
379
 
378
- if q.nil? && d["ID"].to_i != 0
380
+ if q.nil? && d['ID'].to_i != 0
379
381
  q = OneQuotaHelper::DEFAULT_VM_QUOTA
380
382
  end
381
383
 
382
384
  # In case of multiple quotas, use the global quota or the first
383
385
  if q.is_a?(Array)
384
- global_quota = q.find{|hash| hash['CLUSTER_IDS'].nil? || hash['CLUSTER_IDS'].empty? }
385
- q = global_quota || q[0]
386
+ global_q = q.find {|h| h['CLUSTER_IDS'].nil? || h['CLUSTER_IDS'].empty? }
387
+ q = global_q || q[0]
386
388
  end
387
389
 
388
- limit = q["CPU"]
390
+ limit = q['CPU']
391
+ limit = pool_default_quotas.call('VM_QUOTA/VM/CPU') if limit == OneQuotaHelper::LIMIT_DEFAULT
389
392
 
390
- if limit == OneQuotaHelper::LIMIT_DEFAULT
391
- limit = pool_default_quotas("VM_QUOTA/VM/CPU")
392
- if limit.nil? || limit == ""
393
- limit = OneQuotaHelper::LIMIT_UNLIMITED
394
- end
393
+ if limit == OneQuotaHelper::LIMIT_UNLIMITED
394
+ format('%3.1f / -', q['CPU_USED'])
395
+ else
396
+ format('%3.1f / %3.1f', q['CPU_USED'], limit)
395
397
  end
398
+ rescue NoMethodError
399
+ '-'
400
+ end
401
+ end
402
+
403
+ column :PCI, 'Total PCIs allocated to user VMs', :size=>9 do |d|
404
+ begin
405
+ q = quotas_proc.call[d['ID']]['VM_QUOTA']['VM']
406
+
407
+ if q.nil? && d['ID'].to_i != 0
408
+ q = OneQuotaHelper::DEFAULT_VM_QUOTA
409
+ end
410
+
411
+ # In case of multiple quotas, use the global quota or the first
412
+ if q.is_a?(Array)
413
+ global_q = q.find {|h| h['CLUSTER_IDS'].nil? || h['CLUSTER_IDS'].empty? }
414
+ q = global_q || q[0]
415
+ end
416
+
417
+ limit = q['PCI_DEV']
418
+ limit = pool_default_quotas.call('VM_QUOTA/VM/PCI_DEV') if limit == OneQuotaHelper::LIMIT_DEFAULT
396
419
 
397
420
  if limit == OneQuotaHelper::LIMIT_UNLIMITED
398
- "%3.1f / -" % [q["CPU_USED"]]
421
+ format('%3s / -', q['PCI_DEV_USED'])
399
422
  else
400
- "%3.1f / %3.1f" % [q["CPU_USED"], limit]
423
+ format('%3s / %3s', q['PCI_DEV_USED'], limit)
401
424
  end
402
-
403
425
  rescue NoMethodError
404
- "-"
426
+ '-'
405
427
  end
406
428
  end
407
429
 
408
- column :PASSWORD, "Password of the User", :size=>50 do |d|
430
+ column :PASSWORD, 'Password of the User', :size=>50 do |d|
409
431
  d['PASSWORD']
410
432
  end
411
433
 
412
- default :ID, :NAME, :ENABLED, :GROUP, :AUTH, :VMS, :MEMORY, :CPU
434
+ default :ID, :NAME, :ENABLED, :GROUP, :AUTH, :VMS, :MEMORY, :CPU, :PCI
413
435
  end
414
-
415
- table
436
+ # rubocop:enable Style/FormatStringToken
416
437
  end
417
438
 
418
- def find_token(user, token, group=nil, show_expired=false)
439
+ def find_token(user, token, group = nil, show_expired = false)
419
440
  user_hash = user.to_hash
420
441
 
421
- valid_tokens = [user_hash["USER"]["LOGIN_TOKEN"]].flatten.compact
442
+ valid_tokens = [user_hash['USER']['LOGIN_TOKEN']].flatten.compact
422
443
 
423
444
  return [] if valid_tokens.empty?
424
445
 
425
446
  valid_tokens.map! do |e|
426
- if token
427
- next if !e["TOKEN"].start_with?(token)
428
- end
447
+ next if token && !e['TOKEN'].start_with?(token)
429
448
 
430
- exp_time = e["EXPIRATION_TIME"].to_i
431
- if group
432
- next if e["EGID"].to_i != group.to_i
433
- end
449
+ next if group && e['EGID'].to_i != group.to_i
434
450
 
435
- if !show_expired
436
- next if exp_time != -1 && Time.now > Time.at(exp_time)
437
- end
451
+ exp_time = e['EXPIRATION_TIME'].to_i
452
+ next if !show_expired && exp_time != -1 && Time.now > Time.at(exp_time)
438
453
 
439
454
  e
440
455
  end.compact!
441
456
 
442
457
  # Sort the tokens so it returns first the one that will expire the
443
- # latest.
458
+ # latest .
444
459
 
445
- valid_tokens.sort! do |a,b|
446
- a_exp = a["EXPIRATION_TIME"].to_i
447
- b_exp = b["EXPIRATION_TIME"].to_i
460
+ valid_tokens.sort! do |a, b|
461
+ a_exp = a['EXPIRATION_TIME'].to_i
462
+ b_exp = b['EXPIRATION_TIME'].to_i
448
463
 
449
464
  if a_exp == -1 || b_exp == -1
450
465
  a_exp <=> b_exp
@@ -456,8 +471,8 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
456
471
  valid_tokens
457
472
  end
458
473
 
459
- def get_client_user
460
- user = self.retrieve_resource(OpenNebula::User::SELF)
474
+ def read_user
475
+ user = retrieve_resource(OpenNebula::User::SELF)
461
476
  rc = user.info
462
477
  if OpenNebula.is_error?(rc)
463
478
  puts rc.message
@@ -474,20 +489,20 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
474
489
  use_client = false
475
490
  else
476
491
  if !defined?(@@client)
477
- return -1, "No username in the argument or valid ONE_AUTH found."
492
+ return -1, 'No username in the argument or valid ONE_AUTH found.'
478
493
  end
479
494
 
480
- user = self.get_client_user
495
+ user = read_user
481
496
  username = user['NAME']
482
497
  use_client = true
483
498
  end
484
499
 
485
- self.login(username, options, use_client)
500
+ login(username, options, use_client)
486
501
  end
487
502
 
488
503
  private
489
504
 
490
- def factory(id=nil)
505
+ def factory(id = nil)
491
506
  if id
492
507
  OpenNebula::User.new_with_id(id, @client)
493
508
  else
@@ -496,28 +511,23 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
496
511
  end
497
512
  end
498
513
 
499
- def factory_pool(user_flag=-2)
500
- #TBD OpenNebula::UserPool.new(@client, user_flag)
514
+ def factory_pool(_user_flag = -2)
501
515
  @user_pool = OpenNebula::UserPool.new(@client)
502
- return @user_pool
503
516
  end
504
517
 
505
- def format_resource(user, options = {})
506
- system = System.new(@client)
507
-
508
- str="%-16s: %-20s"
509
- str_h1="%-80s"
518
+ def format_resource(user, _options = {})
519
+ str='%-16s: %-20s'
520
+ str_h1='%-80s'
510
521
 
511
522
  CLIHelper.print_header(str_h1 % "USER #{user['ID']} INFORMATION")
512
- puts str % ["ID", user.id.to_s]
513
- puts str % ["NAME", user.name]
514
- puts str % ["GROUP", user['GNAME']]
515
- groups = user.retrieve_elements("GROUPS/ID")
516
- puts str % ["SECONDARY GROUPS", groups.join(',') ] if groups.size > 1
517
- puts str % ["PASSWORD", user['PASSWORD']]
518
- puts str % ["AUTH_DRIVER", user['AUTH_DRIVER']]
519
- puts str % ["ENABLED",
520
- OpenNebulaHelper.boolean_to_str(user['ENABLED'])]
523
+ puts format(str, 'ID', user.id.to_s)
524
+ puts format(str, 'NAME', user.name)
525
+ puts format(str, 'GROUP', user['GNAME'])
526
+ groups = user.retrieve_elements('GROUPS/ID')
527
+ puts format(str, 'SECONDARY GROUPS', groups.join(',')) if groups.size > 1
528
+ puts format(str, 'PASSWORD', user['PASSWORD'])
529
+ puts format(str, 'AUTH_DRIVER', user['AUTH_DRIVER'])
530
+ puts format(str, 'ENABLED', OpenNebulaHelper.boolean_to_str(user['ENABLED']))
521
531
  puts
522
532
 
523
533
  user_hash = user.to_hash
@@ -526,61 +536,60 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
526
536
  gid = user['GID']
527
537
  tokens = [user_hash['USER']['LOGIN_TOKEN']].flatten.compact
528
538
 
529
- CLIHelper.print_header(str_h1 % "TOKENS",false)
539
+ CLIHelper.print_header(str_h1 % 'TOKENS', false)
530
540
  if tokens && !tokens.empty?
531
541
  CLIHelper::ShowTable.new(nil, self) do
532
- column :ID, "", :size=>7 do |d|
533
- d["TOKEN"]
542
+ column :ID, '', :size=>7 do |d|
543
+ d['TOKEN']
534
544
  end
535
545
 
536
- column :EGID, "", :left, :size=>5 do |d|
537
- d["EGID"].to_i == -1 ? "*" + gid : d["EGID"]
546
+ column :EGID, '', :left, :size=>5 do |d|
547
+ d['EGID'].to_i == -1 ? '*' + gid : d['EGID']
538
548
  end
539
549
 
540
- column :EGROUP, "", :left, :size=>10 do |d|
550
+ column :EGROUP, '', :left, :size=>10 do |d|
541
551
  client = OpenNebulaHelper::OneHelper.get_client
542
552
 
543
- egid = d["EGID"].to_i == -1 ? gid : d["EGID"]
553
+ egid = d['EGID'].to_i == -1 ? gid : d['EGID']
544
554
 
545
555
  group = Group.new_with_id(egid, client)
546
556
  rc = group.info
547
557
 
548
558
  if OpenNebula.is_error?(rc)
549
- "-"
559
+ '-'
550
560
  else
551
561
  group['NAME']
552
562
  end
553
563
  end
554
564
 
555
- column :EXPIRATION, "", :left, :size=>20 do |d|
556
- etime = d["EXPIRATION_TIME"]
557
- expired = Time.now >= Time.at(d["EXPIRATION_TIME"].to_i)
565
+ column :EXPIRATION, '', :left, :size=>20 do |d|
566
+ etime = d['EXPIRATION_TIME']
567
+ expired = Time.now >= Time.at(d['EXPIRATION_TIME'].to_i)
558
568
  case etime
559
- when nil then ""
560
- when "-1" then "forever"
569
+ when nil then ''
570
+ when '-1' then 'forever'
561
571
  else
562
572
  if expired
563
- "expired"
573
+ 'expired'
564
574
  else
565
575
  Time.at(etime.to_i).to_s
566
576
  end
567
577
  end
568
578
  end
569
- end.show(tokens,{})
579
+ end.show(tokens, {})
570
580
  end
571
581
 
572
582
  puts
573
583
 
574
- CLIHelper.print_header(str_h1 % "USER TEMPLATE",false)
584
+ CLIHelper.print_header(str_h1 % 'USER TEMPLATE', false)
575
585
  puts user.template_str
576
586
 
577
587
  default_quotas = nil
578
588
 
579
- user.each('/USER/DEFAULT_USER_QUOTAS') { |elem|
580
- default_quotas = elem
581
- }
589
+ user.each('/USER/DEFAULT_USER_QUOTAS') {|elem| default_quotas = elem }
582
590
 
583
591
  helper = OneQuotaHelper.new(@client)
584
592
  helper.format_quota(user_hash['USER'], default_quotas, user.id)
585
593
  end
594
+
586
595
  end
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2025, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2026, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -15,6 +15,8 @@
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
17
  require 'one_helper'
18
+ require 'opennebula/vdc'
19
+ require 'opennebula/vdc_pool'
18
20
 
19
21
  class OneVdcHelper < OpenNebulaHelper::OneHelper
20
22