opennebula-cli 6.3.85.pre → 6.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1588a85307a1dab565154022eae9690ad0efd89273e8c44868a2f3fce1fda6a0
4
- data.tar.gz: 55ab9853a214fa409a77b545eea811014ad859cc96514d42d8eba2306d2b7b7c
3
+ metadata.gz: 003723be19ffff60bc9f577b306af83be5168c39be3be02913e3536c4b3abec8
4
+ data.tar.gz: 2c45d3c203e8efb33e3a446a8b36dc17d538ad528d79f4abe08e17cccf72374b
5
5
  SHA512:
6
- metadata.gz: 8fea30466ca26840e77109f214a74004cf667b2e83e69f27d60cabc4e33762332beef29a9b46655d85a9acf998fff0e61580fab817cee9a1dcf1a0d668bc41db
7
- data.tar.gz: b9fecc5cbf600983b623ce99dd8bc424d991c7597eec98b5392b0a9980d10d057ebb73163cfa218d4788315005e4be5e0119389d4f8d15755b60e4e13007a079
6
+ metadata.gz: db8fce550c33714a7752f157bf8fb4ee75fb8c5ab30f4d195d3ed248f75e770f6ce96b9f87f4efd086cd051a5f92b711619dc0fd4909c8ee4494a3e67da364e6
7
+ data.tar.gz: da31372a0c1b47c0d6d85d27bb840c9a20ae3424306ed1d4580fb7aab1f1b4acbb1d8123dd45d15d9a9f4a65429c7dc66a841d8dfe0bc76dfdaac4f99f1a8244
data/bin/onedatastore CHANGED
@@ -158,7 +158,7 @@ CommandParser::CmdParser.new(ARGV) do
158
158
 
159
159
  command :chmod, chmod_desc, [:range, :datastoreid_list], :octet do
160
160
  helper.perform_actions(args[0], options, 'Permissions changed') do |obj|
161
- obj.chmod_octet(args[1])
161
+ obj.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
162
162
  end
163
163
  end
164
164
 
data/bin/oneflow CHANGED
@@ -285,7 +285,7 @@ CommandParser::CmdParser.new(ARGV) do
285
285
 
286
286
  Service.perform_actions(args[0]) do |service_id|
287
287
  params = {}
288
- params['octet'] = args[1]
288
+ params['octet'] = OpenNebulaHelper.to_octet(args[1])
289
289
 
290
290
  json = Service.build_json_action('chmod', params)
291
291
 
@@ -521,4 +521,27 @@ CommandParser::CmdParser.new(ARGV) do
521
521
  0
522
522
  end
523
523
  end
524
+
525
+ ###
526
+
527
+ release_desc = <<-EOT.unindent
528
+ Release roles of a service on hold
529
+ EOT
530
+
531
+ command :release, release_desc, :service_id do
532
+ service_id = args[0]
533
+ client = helper.client(options)
534
+
535
+ params = {}
536
+ json = Service.build_json_action('release', params)
537
+
538
+ response = client.post("#{RESOURCE_PATH}/#{service_id}/action",
539
+ json)
540
+
541
+ if CloudClient.is_error?(response)
542
+ [response.code.to_i, response.to_s]
543
+ else
544
+ 0
545
+ end
546
+ end
524
547
  end
data/bin/oneflow-template CHANGED
@@ -59,7 +59,6 @@ require 'tempfile'
59
59
 
60
60
  require 'command_parser'
61
61
  require 'opennebula/oneflow_client'
62
- require 'models'
63
62
  require 'cli_helper'
64
63
  require 'one_helper/oneflowtemplate_helper'
65
64
 
@@ -346,7 +345,7 @@ CommandParser::CmdParser.new(ARGV) do
346
345
 
347
346
  Service.perform_actions(args[0]) do |service_id|
348
347
  params = {}
349
- params['octet'] = args[1]
348
+ params['octet'] = OpenNebulaHelper.to_octet(args[1])
350
349
 
351
350
  json = Service.build_json_action('chmod', params)
352
351
 
data/bin/oneimage CHANGED
@@ -363,7 +363,7 @@ CommandParser::CmdParser.new(ARGV) do
363
363
  command :chmod, chmod_desc, [:range, :imageid_list], :octet do
364
364
  helper.perform_actions(args[0], options,
365
365
  'Permissions changed') do |image|
366
- image.chmod_octet(args[1])
366
+ image.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
367
367
  end
368
368
  end
369
369
 
data/bin/oneirb ADDED
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -------------------------------------------------------------------------- #
4
+ # Copyright 2002-2022, OpenNebula Project, OpenNebula Systems #
5
+ # #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
7
+ # not use this file except in compliance with the License. You may obtain #
8
+ # a copy of the License at #
9
+ # #
10
+ # http://www.apache.org/licenses/LICENSE-2.0 #
11
+ # #
12
+ # Unless required by applicable law or agreed to in writing, software #
13
+ # distributed under the License is distributed on an "AS IS" BASIS, #
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15
+ # See the License for the specific language governing permissions and #
16
+ # limitations under the License. #
17
+ #--------------------------------------------------------------------------- #
18
+
19
+ ONE_LOCATION = ENV['ONE_LOCATION']
20
+
21
+ if !ONE_LOCATION
22
+ RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
23
+ GEMS_LOCATION = '/usr/share/one/gems'
24
+ else
25
+ RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
26
+ GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
+ end
28
+
29
+ # %%RUBYGEMS_SETUP_BEGIN%%
30
+ if File.directory?(GEMS_LOCATION)
31
+ real_gems_path = File.realpath(GEMS_LOCATION)
32
+ if !defined?(Gem) || Gem.path != [real_gems_path]
33
+ $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
45
+ end
46
+ end
47
+ # %%RUBYGEMS_SETUP_END%%
48
+
49
+ $LOAD_PATH << RUBY_LIB_LOCATION
50
+ $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
51
+ $LOAD_PATH << RUBY_LIB_LOCATION + '/oneflow/lib'
52
+
53
+ ################################################################################
54
+ # Required libraries
55
+ ################################################################################
56
+
57
+ require 'base64'
58
+ require 'csv'
59
+ require 'date'
60
+ require 'digest/md5'
61
+ require 'erb'
62
+ require 'json'
63
+ require 'nokogiri'
64
+ require 'openssl'
65
+ require 'ox'
66
+ require 'pp'
67
+ require 'set'
68
+ require 'socket'
69
+ require 'sqlite3'
70
+ require 'tempfile'
71
+ require 'time'
72
+ require 'uri'
73
+ require 'yaml'
74
+
75
+ require 'opennebula'
76
+ require 'vcenter_driver'
77
+
78
+ # Include OpenNebula to avoid having to use OpenNebula:: namespace
79
+ include OpenNebula
80
+
81
+ ################################################################################
82
+ # vCenter helper functions
83
+ ################################################################################
84
+
85
+ # Get VIClient object from host
86
+ #
87
+ # @param id [Integer] Host ID
88
+ def vi_client_host(id)
89
+ VCenterDriver::VIClient.new_from_host(id)
90
+ end
91
+
92
+ # Get VM vCenter object
93
+ #
94
+ # @param id [Integer] VM ID
95
+ def vm(id)
96
+ one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, id)
97
+
98
+ did = one_vm['DEPLOY_ID']
99
+ hid = one_vm.retrieve_xmlelements(
100
+ 'HISTORY_RECORDS/HISTORY/HID'
101
+ ).last.text.to_i
102
+
103
+ VCenterDriver::VirtualMachine.new_one(vi_client_host(hid), did, one_vm)
104
+ end
105
+
106
+ # Get host vCenter object
107
+ #
108
+ # @param id [Integer] Host ID
109
+ def host(id)
110
+ vi_client = vi_client_host(id)
111
+ one_h = VCenterDriver::VIHelper.one_item(OpenNebula::Host, hid)
112
+
113
+ VCenterDriver::ClusterComputeResource.new_from_ref(
114
+ one_h['TEMPLATE/VCENTER_CCR_REF'],
115
+ vi_client
116
+ )
117
+ end
118
+
119
+ ################################################################################
120
+ # Open irb session
121
+ ################################################################################
122
+
123
+ puts '* You can use the function vi_client_host(id) to get vCenter client'
124
+ puts '* You can use the function vm(id) to get vCenter VM'
125
+ puts '* You can use the function host(id) to get vCenter host'
126
+
127
+ @client = Client.new
128
+ version = '>= 0'
129
+
130
+ gem 'pry', version
131
+ load Gem.bin_path('pry', 'pry', version)
data/bin/onelog ADDED
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -------------------------------------------------------------------------- #
4
+ # Copyright 2002-2022, OpenNebula Project, OpenNebula Systems #
5
+ # #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
7
+ # not use this file except in compliance with the License. You may obtain #
8
+ # a copy of the License at #
9
+ # #
10
+ # http://www.apache.org/licenses/LICENSE-2.0 #
11
+ # #
12
+ # Unless required by applicable law or agreed to in writing, software #
13
+ # distributed under the License is distributed on an "AS IS" BASIS, #
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15
+ # See the License for the specific language governing permissions and #
16
+ # limitations under the License. #
17
+ #--------------------------------------------------------------------------- #
18
+
19
+ ONE_LOCATION = ENV['ONE_LOCATION']
20
+
21
+ if !ONE_LOCATION
22
+ RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
23
+ GEMS_LOCATION = '/usr/share/one/gems'
24
+ else
25
+ RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
26
+ GEMS_LOCATION = ONE_LOCATION + '/share/gems'
27
+ end
28
+
29
+ # %%RUBYGEMS_SETUP_BEGIN%%
30
+ if File.directory?(GEMS_LOCATION)
31
+ real_gems_path = File.realpath(GEMS_LOCATION)
32
+ if !defined?(Gem) || Gem.path != [real_gems_path]
33
+ $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
45
+ end
46
+ end
47
+ # %%RUBYGEMS_SETUP_END%%
48
+
49
+ $LOAD_PATH << RUBY_LIB_LOCATION
50
+ $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
51
+
52
+ # Default pager to check logs
53
+ DEFAULT_PAGER = 'less'
54
+
55
+ # List of OpenNebula services and the logs files
56
+ SERVICES = {
57
+ 'fireedge' => { :log => 'fireedge.log', :error => 'fireedge.error' },
58
+ 'monitor' => { :log => 'monitor.log' },
59
+ 'novnc' => { :log => 'novnc.log' },
60
+ 'oned' => { :log => 'oned.log' },
61
+ 'onehem' => { :log => 'onehem.log', :error => 'onehem.error' },
62
+ 'sched' => { :log => 'sched.log' },
63
+ 'sunstone' => { :log => 'sunstone.log', :error => 'sunstone.error' },
64
+ 'vcenter' => { :log => 'vcenter_monitor.log' }
65
+ }
66
+
67
+ require 'command_parser'
68
+ require 'one_helper'
69
+
70
+ CommandParser::CmdParser.new(ARGV) do
71
+ usage '`onelog` <command> [<args>] [<options>]'
72
+ version OpenNebulaHelper::ONE_VERSION
73
+
74
+ TYPE = {
75
+ :name => 'type',
76
+ :short => '-t type',
77
+ :large => '--type type',
78
+ :format => String,
79
+ :description => 'Log type (log/error) [default: log]'
80
+ }
81
+
82
+ PAGER = {
83
+ :name => 'pager',
84
+ :short => '-p pager',
85
+ :large => '--pager pager',
86
+ :format => String,
87
+ :description => 'Pager to use to read logs [defaul: less]'
88
+ }
89
+
90
+ PAGER_OPTS = {
91
+ :name => 'pager_opts',
92
+ :large => '--pager-opts pager_opts',
93
+ :format => String,
94
+ :description => 'Pager options'
95
+ }
96
+
97
+ get_desc = <<-EOT.unindent
98
+ Gets log from an specific OpenNebula service
99
+ EOT
100
+
101
+ command :get, get_desc, :service, :options => [TYPE, PAGER, PAGER_OPTS] do
102
+ logs = SERVICES[args[0]]
103
+ pager = options[:pager] || DEFAULT_PAGER
104
+
105
+ unless logs
106
+ STDERR.puts "Service '#{args[0]}' not found"
107
+ exit 1
108
+ end
109
+
110
+ if options[:type] && !logs[options[:type].to_sym]
111
+ STDERR.puts "Log file type '#{options[:type]}' not found"
112
+ exit 1
113
+ end
114
+
115
+ options[:type].nil? ? f = logs[:log] : f = logs[options[:type].to_sym]
116
+
117
+ system("#{pager} #{options[:pager_opts]} /var/log/one/#{f}")
118
+ end
119
+
120
+ vm_desc = <<-EOT.unindent
121
+ Gets VM log
122
+ EOT
123
+
124
+ command :'get-vm', vm_desc, :id, :options => [PAGER, PAGER_OPTS] do
125
+ pager = options[:pager] || DEFAULT_PAGER
126
+
127
+ begin
128
+ Integer(args[0])
129
+
130
+ file = "/var/log/one/#{args[0]}.log"
131
+
132
+ unless File.exist?(file)
133
+ STDERR.puts "No LOG file found for '#{args[0]}' VM"
134
+ exit 1
135
+ end
136
+
137
+ system("#{pager} #{options[:pager_opts]} #{file}")
138
+ rescue StandardError
139
+ STDERR.puts 'Only ID is supported'
140
+ exit 1
141
+ end
142
+ end
143
+
144
+ service_desc = <<-EOT.unindent
145
+ Gets Service log
146
+ EOT
147
+
148
+ command :'get-service',
149
+ service_desc,
150
+ :id,
151
+ :options => [PAGER, PAGER_OPTS] do
152
+ pager = options[:pager] || DEFAULT_PAGER
153
+
154
+ begin
155
+ Integer(args[0])
156
+
157
+ file = "/var/log/one/oneflow/#{args[0]}.log"
158
+
159
+ unless File.exist?(file)
160
+ STDERR.puts "No LOG file found for '#{args[0]}' service"
161
+ exit 1
162
+ end
163
+
164
+ system("#{pager} #{options[:pager_opts]} #{file}")
165
+ rescue StandardError
166
+ STDERR.puts 'Only ID is supported'
167
+ exit 1
168
+ end
169
+ end
170
+ end
data/bin/onemarket CHANGED
@@ -151,7 +151,7 @@ CommandParser::CmdParser.new(ARGV) do
151
151
 
152
152
  command :chmod, chmod_desc, [:range, :marketplaceid_list], :octet do
153
153
  helper.perform_actions(args[0], options, 'Permissions changed') do |obj|
154
- obj.chmod_octet(args[1])
154
+ obj.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
155
155
  end
156
156
  end
157
157
 
data/bin/onemarketapp CHANGED
@@ -388,7 +388,7 @@ CommandParser::CmdParser.new(ARGV) do
388
388
 
389
389
  command :chmod, chmod_desc, [:range, :appid_list], :octet do
390
390
  helper.perform_actions(args[0], options, 'Permissions changed') do |app|
391
- app.chmod_octet(args[1])
391
+ app.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
392
392
  end
393
393
  end
394
394
 
data/bin/onesecgroup CHANGED
@@ -174,7 +174,7 @@ CommandParser::CmdParser.new(ARGV) do
174
174
 
175
175
  command :chmod, chmod_desc, [:range, :secgroupid_list], :octet do
176
176
  helper.perform_actions(args[0], options, 'Permissions changed') do |t|
177
- t.chmod_octet(args[1])
177
+ t.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
178
178
  end
179
179
  end
180
180
 
data/bin/onetemplate CHANGED
@@ -87,6 +87,14 @@ CommandParser::CmdParser.new(ARGV) do
87
87
  :description => 'lock all actions'
88
88
  }
89
89
 
90
+ PREFIX = {
91
+ :name => 'prefix',
92
+ :large => '--prefix prefix',
93
+ :description => 'Prefix to autogenerate name, e.g: 001, 01',
94
+ :format => String
95
+
96
+ }
97
+
90
98
  ########################################################################
91
99
  # Global Options
92
100
  ########################################################################
@@ -102,7 +110,8 @@ CommandParser::CmdParser.new(ARGV) do
102
110
  OneTemplateHelper::MULTIPLE,
103
111
  OneTemplateHelper::USERDATA,
104
112
  OneVMHelper::HOLD,
105
- OneTemplateHelper::PERSISTENT
113
+ OneTemplateHelper::PERSISTENT,
114
+ PREFIX
106
115
  ]
107
116
 
108
117
  ########################################################################
@@ -252,16 +261,37 @@ CommandParser::CmdParser.new(ARGV) do
252
261
  number = options[:multiple] || 1
253
262
  user_inputs = options[:user_inputs]
254
263
 
255
- number.times do |i|
256
- exit_code = helper.perform_action(args[0], options,
257
- 'instantiated') do |t|
258
- name = options[:name]
259
- name = name.gsub('%i', i.to_s) if name
260
-
261
- on_hold = !options[:hold].nil?
264
+ number.times.each_with_index do |i, index|
265
+ exit_code = helper.perform_action(
266
+ args[0],
267
+ options,
268
+ 'instantiated'
269
+ ) do |t|
270
+ name = options[:name]
271
+ prefix = options[:prefix]
272
+ c_i = nil
273
+ p = nil
274
+
275
+ if prefix && name
276
+ # Get leading zeros
277
+ p = prefix.scan(/^0+/)[0]
278
+
279
+ # Get current index
280
+ c_i = prefix.gsub(p, '') if p
281
+
282
+ # Convert it to Integer to check if we can use it
283
+ begin
284
+ c_i = Integer(c_i)
285
+ name = name.gsub('%i', "#{p}#{c_i + index}")
286
+ rescue StandardError
287
+ end
288
+ elsif name
289
+ name = name.gsub('%i', i.to_s)
290
+ end
262
291
 
292
+ on_hold = !options[:hold].nil?
263
293
  extra_template = ''
264
- rc = t.info
294
+ rc = t.info
265
295
 
266
296
  if OpenNebula.is_error?(rc)
267
297
  STDERR.puts rc.message
@@ -281,6 +311,10 @@ CommandParser::CmdParser.new(ARGV) do
281
311
  extra_template = res.last
282
312
  end
283
313
 
314
+ if c_i
315
+ extra_template.gsub!('%i', "#{p}#{c_i + index}")
316
+ end
317
+
284
318
  if !user_inputs
285
319
  user_inputs = OneTemplateHelper.get_user_inputs(t.to_hash)
286
320
  else
@@ -344,7 +378,7 @@ CommandParser::CmdParser.new(ARGV) do
344
378
  recursive = (options[:recursive] == true)
345
379
 
346
380
  helper.perform_actions(args[0], options, 'Permissions changed') do |t|
347
- t.chmod_octet(args[1], recursive)
381
+ t.chmod_octet(OpenNebulaHelper.to_octet(args[1]), recursive)
348
382
  end
349
383
  end
350
384
 
data/bin/oneuser CHANGED
@@ -443,7 +443,7 @@ CommandParser::CmdParser.new(ARGV) do
443
443
  command :key, key_desc, :options => [KEY] do
444
444
  require 'opennebula/ssh_auth'
445
445
 
446
- options[:key] ||= ENV['HOME'] + '/.ssh/id_rsa'
446
+ options[:key] ||= Dir.home + '/.ssh/id_rsa'
447
447
 
448
448
  begin
449
449
  sshauth = SshAuth.new(:private_key => options[:key])
data/bin/onevcenter CHANGED
@@ -409,7 +409,42 @@ CommandParser::CmdParser.new(ARGV) do
409
409
 
410
410
  begin
411
411
  print '.'
412
- vm, keys = helper.clear_tags(vmid)
412
+
413
+ client = Client.new
414
+
415
+ vm_pool = VirtualMachinePool.new(client, -1)
416
+ host_pool = HostPool.new(client)
417
+ deploy_id = -1
418
+ host_id = -1
419
+ hostname = ''
420
+
421
+ rc = vm_pool.info
422
+ raise rc.message if OpenNebula.is_error?(rc)
423
+
424
+ rc = host_pool.info
425
+ raise rc.message if OpenNebula.is_error?(rc)
426
+
427
+ vm_pool.each do |vm|
428
+ next if vm.id.to_s != vmid
429
+
430
+ deploy_id = vm.deploy_id
431
+ vm_history = vm.to_hash['VM']['HISTORY_RECORDS']['HISTORY']
432
+ hostname = vm_history['HOSTNAME']
433
+ break
434
+ end
435
+
436
+ host_pool.each do |host|
437
+ if host.name == hostname
438
+ host_id = host.id
439
+ end
440
+ end
441
+
442
+ vi_client = VCenterDriver::VIClient.new_from_host(host_id)
443
+ vm = VCenterDriver::VirtualMachine
444
+ .new(vi_client, deploy_id, vmid)
445
+
446
+ keys = vm.extra_config_keys
447
+
413
448
  print '.'
414
449
 
415
450
  if keys.empty?
@@ -422,7 +457,7 @@ CommandParser::CmdParser.new(ARGV) do
422
457
  puts 'The following keys will be removed:'
423
458
  keys.each {|key| puts "\t- #{key}" }
424
459
 
425
- helper.remove_keys(vm, keys)
460
+ vm.clear_tags
426
461
  rescue StandardError => e
427
462
  STDERR.puts "Couldn't clear VM tags. Reason: #{e.message}"
428
463
  exit 1
data/bin/onevm CHANGED
@@ -49,6 +49,9 @@ end
49
49
  $LOAD_PATH << RUBY_LIB_LOCATION
50
50
  $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
51
51
 
52
+ # Default VNC viewer
53
+ DEFAULT_VNC = 'vinagre'
54
+
52
55
  require 'command_parser'
53
56
  require 'one_helper/onevm_helper'
54
57
  require 'one_helper/onedatastore_helper'
@@ -239,6 +242,13 @@ CommandParser::CmdParser.new(ARGV) do
239
242
  :description => 'SSH options to use'
240
243
  }
241
244
 
245
+ VNC = {
246
+ :name => 'vnc',
247
+ :large => '--vnc vnc',
248
+ :format => String,
249
+ :description => 'VNC client to use'
250
+ }
251
+
242
252
  OpenNebulaHelper::TEMPLATE_OPTIONS_VM.delete_if do |v|
243
253
  %w[as_gid as_uid].include?(v[:name])
244
254
  end
@@ -462,7 +472,13 @@ CommandParser::CmdParser.new(ARGV) do
462
472
  verbose = "disk #{disk_id} prepared to be saved in " \
463
473
  "the image #{image_name}"
464
474
  else
465
- snapshot_id = snapshot_id.to_i
475
+ err, snapshot_id = helper.retrieve_disk_snapshot_id(args[0],
476
+ snapshot_id)
477
+
478
+ if err == -1
479
+ STDERR.puts snapshot_id
480
+ exit(-1)
481
+ end
466
482
 
467
483
  verbose = "disk #{disk_id} snapshot #{snapshot_id} prepared to " \
468
484
  "be saved in the image #{image_name}"
@@ -971,7 +987,7 @@ CommandParser::CmdParser.new(ARGV) do
971
987
 
972
988
  command :chmod, chmod_desc, [:range, :vmid_list], :octet do
973
989
  helper.perform_actions(args[0], options, 'Permissions changed') do |vm|
974
- vm.chmod_octet(args[1])
990
+ vm.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
975
991
  end
976
992
  end
977
993
 
@@ -1666,6 +1682,30 @@ CommandParser::CmdParser.new(ARGV) do
1666
1682
  end
1667
1683
  end
1668
1684
 
1685
+ connect_desc = <<-EOT.unindent
1686
+ Opens a VNC session to the VM
1687
+ EOT
1688
+
1689
+ command :vnc, connect_desc, :vmid, :options => [VNC] do
1690
+ helper.perform_action(args[0], options, 'VNC') do |vm|
1691
+ rc = vm.info
1692
+
1693
+ if OpenNebula.is_error?(rc)
1694
+ STDERR.puts rc.message
1695
+ exit(1)
1696
+ end
1697
+
1698
+ host = vm['HISTORY_RECORDS/HISTORY[last()]/HOSTNAME']
1699
+ port = vm['TEMPLATE/GRAPHICS/PORT']
1700
+
1701
+ vncviewer = options['vnc'] || DEFAULT_VNC
1702
+
1703
+ cmd = [vncviewer, "#{host}::#{port}"]
1704
+
1705
+ exec(*cmd)
1706
+ end
1707
+ end
1708
+
1669
1709
  # Deprecated commands
1670
1710
 
1671
1711
  deprecated_command(:shutdown, 'terminate')
data/bin/onevmgroup CHANGED
@@ -197,7 +197,7 @@ CommandParser::CmdParser.new(ARGV) do
197
197
 
198
198
  command :chmod, chmod_desc, [:range, :vmgroupid_list], :octet do
199
199
  helper.perform_actions(args[0], options, 'Permissions changed') do |t|
200
- t.chmod_octet(args[1])
200
+ t.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
201
201
  end
202
202
  end
203
203
 
data/bin/onevnet CHANGED
@@ -335,7 +335,7 @@ CommandParser::CmdParser.new(ARGV) do
335
335
 
336
336
  command :chmod, chmod_desc, [:range, :vnetid_list], :octet do
337
337
  helper.perform_actions(args[0], options, 'Permissions changed') do |vn|
338
- vn.chmod_octet(args[1])
338
+ vn.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
339
339
  end
340
340
  end
341
341
 
data/bin/onevntemplate CHANGED
@@ -87,6 +87,14 @@ CommandParser::CmdParser.new(ARGV) do
87
87
  :description => 'lock all actions'
88
88
  }
89
89
 
90
+ PREFIX = {
91
+ :name => 'prefix',
92
+ :large => '--prefix prefix',
93
+ :description => 'Prefix to autogenerate name, e.g: 001, 01',
94
+ :format => String
95
+
96
+ }
97
+
90
98
  ########################################################################
91
99
  # Global Options
92
100
  ########################################################################
@@ -102,7 +110,8 @@ CommandParser::CmdParser.new(ARGV) do
102
110
  OneVNTemplateHelper::MULTIPLE,
103
111
  OneVNTemplateHelper::EXTENDED,
104
112
  OpenNebulaHelper::AS_USER,
105
- OpenNebulaHelper::AS_GROUP
113
+ OpenNebulaHelper::AS_GROUP,
114
+ PREFIX
106
115
  ]
107
116
 
108
117
  ########################################################################
@@ -204,10 +213,32 @@ CommandParser::CmdParser.new(ARGV) do
204
213
  number = options[:multiple] || 1
205
214
 
206
215
  number.times do |i|
207
- exit_code = helper.perform_action(args[0], options,
208
- 'instantiated') do |t|
209
- name = options[:name]
210
- name = name.gsub('%i', i.to_s) if name
216
+ exit_code = helper.perform_action(
217
+ args[0],
218
+ options,
219
+ 'instantiated'
220
+ ) do |t|
221
+ name = options[:name]
222
+ prefix = options[:prefix]
223
+ c_i = nil
224
+ p = nil
225
+
226
+ if prefix && name
227
+ # Get leading zeros
228
+ p = prefix.scan(/^0+/)[0]
229
+
230
+ # Get current index
231
+ c_i = prefix.gsub(p, '') if p
232
+
233
+ # Convert it to Integer to check if we can use it
234
+ begin
235
+ c_i = Integer(c_i)
236
+ name = name.gsub('%i', "#{p}#{c_i + index}")
237
+ rescue StandardError
238
+ end
239
+ elsif name
240
+ name = name.gsub('%i', i.to_s)
241
+ end
211
242
 
212
243
  extra_template = ''
213
244
  rc = t.info
@@ -234,6 +265,10 @@ CommandParser::CmdParser.new(ARGV) do
234
265
  end
235
266
  end
236
267
 
268
+ if c_i
269
+ extra_template.gsub!('%i', "#{p}#{c_i + index}")
270
+ end
271
+
237
272
  res = t.instantiate(name, extra_template)
238
273
 
239
274
  if !OpenNebula.is_error?(res)
@@ -279,7 +314,7 @@ CommandParser::CmdParser.new(ARGV) do
279
314
  recursive = (options[:recursive] == true)
280
315
 
281
316
  helper.perform_actions(args[0], options, 'Permissions changed') do |t|
282
- t.chmod_octet(args[1], recursive)
317
+ t.chmod_octet(OpenNebulaHelper.to_octet(args[1]), recursive)
283
318
  end
284
319
  end
285
320
 
data/bin/onevrouter CHANGED
@@ -251,7 +251,7 @@ CommandParser::CmdParser.new(ARGV) do
251
251
 
252
252
  command :chmod, chmod_desc, [:range, :vrouterid_list], :octet do
253
253
  helper.perform_actions(args[0], options, 'Permissions changed') do |obj|
254
- obj.chmod_octet(args[1])
254
+ obj.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
255
255
  end
256
256
  end
257
257
 
@@ -221,16 +221,14 @@ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper
221
221
  exit(-1)
222
222
  end
223
223
 
224
- mandatory, _type, description, _params, initial = input_cfg
225
-
226
- vnet = {}
224
+ vnet = {}
225
+ mandatory, _, description, _, initial = input_cfg
227
226
 
228
227
  if initial && !initial.empty?
229
228
  type, resource_id, extra = initial.split(':', -1)
230
229
  end
231
230
 
232
- if (type.nil? || resource_id.nil?) &&
233
- (initial && !initial.empty?)
231
+ if (!type || !resource_id) && (initial && !initial.empty?)
234
232
  STDERR.puts 'Wrong type for user input default value:'
235
233
  STDERR.puts " #{key}: #{val}"
236
234
  exit(-1)
@@ -239,7 +237,7 @@ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper
239
237
  vnet[key] = {}
240
238
 
241
239
  if get_defaults
242
- vnet[key][type] = resource_id
240
+ vnet[key][type] = resource_id
243
241
  vnet[key]['extra'] = extra
244
242
 
245
243
  answers << vnet unless mandatory == 'M'
@@ -248,22 +246,25 @@ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper
248
246
 
249
247
  puts " * (#{key}) #{description}"
250
248
 
251
- #######################################
252
- # Asks for type
253
- #######################################
254
-
255
- header = ' '
249
+ ####################################################################
250
+ # Ask for type
251
+ ####################################################################
252
+ header = ' '
256
253
  header += 'TYPE Existing(1), Create(2), Reserve(3). '
257
-
258
- if !type.nil? && type != ''
259
- header += 'Press enter for default. '
260
- end
254
+ header += 'Press enter for default. ' if type && !type.empty?
261
255
 
262
256
  print header
263
257
 
264
258
  answer = STDIN.readline.chop
265
259
 
266
- type_a = type
260
+ if type && !type.empty? && ![1, 2, 3].include?(answer.to_i)
261
+ type_a = type
262
+ else
263
+ until [1, 2, 3].include?(answer.to_i)
264
+ print header
265
+ answer = STDIN.readline.chop
266
+ end
267
+ end
267
268
 
268
269
  case answer.to_i
269
270
  when 1
@@ -274,18 +275,18 @@ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper
274
275
  type_a = 'reserve_from'
275
276
  end
276
277
 
277
- #######################################
278
- # Asks for resource id
279
- #######################################
280
-
278
+ ####################################################################
279
+ # Ask for resource id
280
+ ####################################################################
281
281
  header = ' '
282
+
282
283
  if type_a == 'template_id'
283
284
  header += 'VN Template ID. '
284
285
  else
285
286
  header += 'VN ID. '
286
287
  end
287
288
 
288
- if !resource_id.nil? && resource_id != ''
289
+ if resource_id && !resource_id.empty?
289
290
  header += "Press enter for default (#{resource_id}). "
290
291
  end
291
292
 
@@ -293,17 +294,23 @@ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper
293
294
 
294
295
  resource_id_a = STDIN.readline.chop
295
296
 
296
- resource_id_a = resource_id if resource_id_a.empty?
297
+ if resource_id && !resource_id.empty?
298
+ resource_id_a = resource_id
299
+ else
300
+ while resource_id_a.empty?
301
+ print header
302
+ resource_id_a = STDIN.readline.chop
303
+ end
304
+ end
297
305
 
298
- #######################################
306
+ ####################################################################
299
307
  # Asks for extra
300
- #######################################
301
-
308
+ ####################################################################
302
309
  if type_a != 'id'
303
- header = ' '
310
+ header = ' '
304
311
  header += 'EXTRA (Type EMPTY for leaving empty). '
305
312
 
306
- if !extra.nil? && extra != ''
313
+ if extra && !extra.empty?
307
314
  header += " Press enter for default (#{extra}). "
308
315
  end
309
316
 
@@ -520,59 +520,4 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
520
520
  opts
521
521
  end
522
522
 
523
- def clear_tags(vmid)
524
- client = Client.new
525
-
526
- vm_pool = VirtualMachinePool.new(client, -1)
527
- host_pool = HostPool.new(client)
528
- deploy_id = -1
529
- host_id = -1
530
- hostname = ''
531
-
532
- rc = vm_pool.info
533
- raise rc.message if OpenNebula.is_error?(rc)
534
-
535
- rc = host_pool.info
536
- raise rc.message if OpenNebula.is_error?(rc)
537
-
538
- vm_pool.each do |vm|
539
- next if vm.id.to_s != vmid
540
-
541
- deploy_id = vm.deploy_id
542
- vm_history = vm.to_hash['VM']['HISTORY_RECORDS']['HISTORY']
543
- hostname = vm_history['HOSTNAME']
544
- break
545
- end
546
-
547
- host_pool.each do |host|
548
- if host.name == hostname
549
- host_id = host.id
550
- end
551
- end
552
-
553
- vi_client = VCenterDriver::VIClient.new_from_host(host_id)
554
- vm = VCenterDriver::VirtualMachine
555
- .new(vi_client, deploy_id, vmid)
556
-
557
- keys_to_remove = []
558
- vm['config.extraConfig'].each do |extraconfig|
559
- next unless extraconfig.key.include?('opennebula.disk') ||
560
- extraconfig.key.include?('opennebula.vm') ||
561
- extraconfig.key.downcase.include?('remotedisplay')
562
-
563
- keys_to_remove << extraconfig.key
564
- end
565
-
566
- [vm, keys_to_remove]
567
- end
568
-
569
- def remove_keys(vm, keys_to_remove)
570
- spec_hash = keys_to_remove.map {|key| { :key => key, :value => '' } }
571
-
572
- spec = RbVmomi::VIM.VirtualMachineConfigSpec(
573
- :extraConfig => spec_hash
574
- )
575
- vm.item.ReconfigVM_Task(:spec => spec).wait_for_completion
576
- end
577
-
578
523
  end
@@ -297,7 +297,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
297
297
  vm.info
298
298
  ids = vm.retrieve_elements("/VM/SNAPSHOTS/SNAPSHOT[NAME='#{id}']/ID")
299
299
 
300
- return [-1, "#{id} not found or duplicated"] \
300
+ return [-1, "Snapshot #{id} not found or duplicated"] \
301
301
  if ids.nil? || ids.size > 1
302
302
 
303
303
  [0, ids[0].to_i]
data/lib/one_helper.rb CHANGED
@@ -747,12 +747,9 @@ EOT
747
747
  ppid = start_pager
748
748
  end
749
749
 
750
- puts "<#{pname}>"
751
-
752
750
  puts page
753
751
 
754
752
  if elements < size
755
- puts "</#{pname}>"
756
753
  return 0
757
754
  end
758
755
 
@@ -2305,4 +2302,55 @@ EOT
2305
2302
  end
2306
2303
  end
2307
2304
 
2305
+ # Convert u=rwx,g=rx,o=r to octet
2306
+ #
2307
+ # @param perm [String] Permissions in human readbale format
2308
+ #
2309
+ # @return [String] Permissions in octet format
2310
+ def OpenNebulaHelper.to_octet(perm)
2311
+ begin
2312
+ Integer(perm)
2313
+ perm
2314
+ rescue StandardError
2315
+ perm = perm.split(',')
2316
+ ret = 0
2317
+
2318
+ perm.each do |p|
2319
+ p = p.split('=')
2320
+
2321
+ next unless p.size == 2
2322
+
2323
+ r = p[1].count('r')
2324
+ w = p[1].count('w')
2325
+ x = p[1].count('x')
2326
+
2327
+ rwx = (2 ** 0) * x + (2 ** 1) * w + (2 ** 2) * r
2328
+
2329
+ case p[0]
2330
+ when 'u'
2331
+ ret += rwx * 100
2332
+ when 'g'
2333
+ ret += rwx * 10
2334
+ else
2335
+ ret += rwx * 1
2336
+ end
2337
+ end
2338
+
2339
+ if ret == 0
2340
+ STDERR.puts 'Error in permissions format'
2341
+ exit(-1)
2342
+ else
2343
+ ret = ret.to_s
2344
+
2345
+ if ret.size == 1
2346
+ "00#{ret}"
2347
+ elsif ret.size == 2
2348
+ "0#{ret}"
2349
+ else
2350
+ ret
2351
+ end
2352
+ end
2353
+ end
2354
+ end
2355
+
2308
2356
  end
@@ -65,9 +65,11 @@
65
65
  <xs:element name="DOMAIN" type="xs:string"/>
66
66
  <xs:element name="FUNCTION" type="xs:string"/>
67
67
  <xs:element name="NUMA_NODE" type="xs:string"/>
68
+ <xs:element name="PROFILES" type="xs:string" minOccurs="0"/>
68
69
  <xs:element name="SHORT_ADDRESS" type="xs:string"/>
69
70
  <xs:element name="SLOT" type="xs:string"/>
70
71
  <xs:element name="TYPE" type="xs:string"/>
72
+ <xs:element name="UUID" type="xs:string" minOccurs="0"/>
71
73
  <xs:element name="VENDOR" type="xs:string"/>
72
74
  <xs:element name="VENDOR_NAME" type="xs:string"/>
73
75
  <xs:element name="VMID" type="xs:integer"/>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opennebula-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.85.pre
4
+ version: 6.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenNebula
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-18 00:00:00.000000000 Z
11
+ date: 2022-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opennebula
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 6.3.85.pre
19
+ version: 6.4.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 6.3.85.pre
26
+ version: 6.4.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,6 +50,7 @@ executables:
50
50
  - onehook
51
51
  - onevdc
52
52
  - oneacl
53
+ - oneirb
53
54
  - oneflow-template
54
55
  - onevrouter
55
56
  - oneshowback
@@ -57,6 +58,7 @@ executables:
57
58
  - oneacct
58
59
  - onesecgroup
59
60
  - onecluster
61
+ - onelog
60
62
  - onemarketapp
61
63
  - onetemplate
62
64
  - onemarket
@@ -80,6 +82,8 @@ files:
80
82
  - bin/onehook
81
83
  - bin/onehost
82
84
  - bin/oneimage
85
+ - bin/oneirb
86
+ - bin/onelog
83
87
  - bin/onemarket
84
88
  - bin/onemarketapp
85
89
  - bin/onesecgroup
@@ -185,9 +189,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
189
  version: '0'
186
190
  required_rubygems_version: !ruby/object:Gem::Requirement
187
191
  requirements:
188
- - - ">"
192
+ - - ">="
189
193
  - !ruby/object:Gem::Version
190
- version: 1.3.1
194
+ version: '0'
191
195
  requirements: []
192
196
  rubygems_version: 3.1.2
193
197
  signing_key: