opennebula-cli 5.12.5 → 5.13.85.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/oneacct +9 -4
- data/bin/oneacl +8 -5
- data/bin/onecluster +10 -7
- data/bin/onedatastore +10 -7
- data/bin/oneflow +85 -13
- data/bin/oneflow-template +45 -8
- data/bin/onegroup +10 -7
- data/bin/onehook +10 -7
- data/bin/onehost +10 -7
- data/bin/oneimage +100 -9
- data/bin/onemarket +10 -7
- data/bin/onemarketapp +118 -11
- data/bin/onesecgroup +13 -7
- data/bin/oneshowback +23 -10
- data/bin/onetemplate +16 -9
- data/bin/oneuser +30 -7
- data/bin/onevcenter +7 -4
- data/bin/onevdc +10 -7
- data/bin/onevm +147 -12
- data/bin/onevmgroup +13 -7
- data/bin/onevnet +8 -5
- data/bin/onevntemplate +11 -7
- data/bin/onevrouter +10 -7
- data/bin/onezone +10 -7
- data/lib/cli_helper.rb +6 -8
- data/lib/command_parser.rb +1 -1
- data/lib/one_helper.rb +414 -46
- data/lib/one_helper/oneacct_helper.rb +8 -17
- data/lib/one_helper/oneacl_helper.rb +1 -1
- data/lib/one_helper/onecluster_helper.rb +1 -1
- data/lib/one_helper/onedatastore_helper.rb +11 -1
- data/lib/one_helper/oneflow_helper.rb +20 -5
- data/lib/one_helper/oneflowtemplate_helper.rb +28 -2
- data/lib/one_helper/onegroup_helper.rb +1 -1
- data/lib/one_helper/onehook_helper.rb +1 -1
- data/lib/one_helper/onehost_helper.rb +1 -5
- data/lib/one_helper/oneimage_helper.rb +7 -7
- data/lib/one_helper/onemarket_helper.rb +1 -1
- data/lib/one_helper/onemarketapp_helper.rb +500 -96
- data/lib/one_helper/onequota_helper.rb +1 -1
- data/lib/one_helper/onesecgroup_helper.rb +1 -1
- data/lib/one_helper/onetemplate_helper.rb +16 -4
- data/lib/one_helper/oneuser_helper.rb +11 -3
- data/lib/one_helper/onevcenter_helper.rb +176 -146
- data/lib/one_helper/onevdc_helper.rb +1 -1
- data/lib/one_helper/onevm_helper.rb +4 -3
- data/lib/one_helper/onevmgroup_helper.rb +1 -1
- data/lib/one_helper/onevnet_helper.rb +1 -1
- data/lib/one_helper/onevntemplate_helper.rb +1 -1
- data/lib/one_helper/onevrouter_helper.rb +1 -20
- data/lib/one_helper/onezone_helper.rb +13 -6
- data/share/schemas/xsd/acct.xsd +179 -0
- data/share/schemas/xsd/acl_pool.xsd +22 -0
- data/share/schemas/xsd/api_info.xsd +43 -0
- data/share/schemas/xsd/cluster.xsd +34 -0
- data/share/schemas/xsd/cluster_pool.xsd +12 -0
- data/share/schemas/xsd/datastore.xsd +67 -0
- data/share/schemas/xsd/datastore_pool.xsd +12 -0
- data/share/schemas/xsd/document.xsd +42 -0
- data/share/schemas/xsd/document_pool.xsd +12 -0
- data/share/schemas/xsd/group.xsd +179 -0
- data/share/schemas/xsd/group_pool.xsd +194 -0
- data/share/schemas/xsd/hook.xsd +59 -0
- data/share/schemas/xsd/hook_message_api.xsd +14 -0
- data/share/schemas/xsd/hook_message_retry.xsd +12 -0
- data/share/schemas/xsd/hook_message_state.xsd +25 -0
- data/share/schemas/xsd/hook_pool.xsd +12 -0
- data/share/schemas/xsd/host.xsd +164 -0
- data/share/schemas/xsd/host_pool.xsd +12 -0
- data/share/schemas/xsd/image.xsd +123 -0
- data/share/schemas/xsd/image_pool.xsd +12 -0
- data/share/schemas/xsd/index.xsd +49 -0
- data/share/schemas/xsd/marketplace.xsd +44 -0
- data/share/schemas/xsd/marketplace_pool.xsd +12 -0
- data/share/schemas/xsd/marketplaceapp.xsd +56 -0
- data/share/schemas/xsd/marketplaceapp_pool.xsd +12 -0
- data/share/schemas/xsd/opennebula_configuration.xsd +412 -0
- data/share/schemas/xsd/raftstatus.xsd +18 -0
- data/share/schemas/xsd/security_group.xsd +74 -0
- data/share/schemas/xsd/security_group_pool.xsd +12 -0
- data/share/schemas/xsd/showback.xsd +29 -0
- data/share/schemas/xsd/user.xsd +186 -0
- data/share/schemas/xsd/user_pool.xsd +201 -0
- data/share/schemas/xsd/vdc.xsd +76 -0
- data/share/schemas/xsd/vdc_pool.xsd +12 -0
- data/share/schemas/xsd/vm.xsd +251 -0
- data/share/schemas/xsd/vm_group.xsd +59 -0
- data/share/schemas/xsd/vm_group_pool.xsd +12 -0
- data/share/schemas/xsd/vm_pool.xsd +114 -0
- data/share/schemas/xsd/vmtemplate.xsd +52 -0
- data/share/schemas/xsd/vmtemplate_pool.xsd +12 -0
- data/share/schemas/xsd/vnet.xsd +137 -0
- data/share/schemas/xsd/vnet_pool.xsd +85 -0
- data/share/schemas/xsd/vntemplate.xsd +50 -0
- data/share/schemas/xsd/vntemplate_pool.xsd +12 -0
- data/share/schemas/xsd/vrouter.xsd +49 -0
- data/share/schemas/xsd/vrouter_pool.xsd +12 -0
- data/share/schemas/xsd/zone.xsd +40 -0
- data/share/schemas/xsd/zone_pool.xsd +36 -0
- metadata +79 -18
- data/lib/one_helper/oneprovision_helper.rb +0 -362
data/bin/onevmgroup
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -27,9 +27,12 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
real_gems_path = File.realpath(GEMS_LOCATION)
|
31
|
+
if !defined?(Gem) || Gem.path != [real_gems_path]
|
32
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
33
|
+
require 'rubygems'
|
34
|
+
Gem.use_paths(real_gems_path)
|
35
|
+
end
|
33
36
|
end
|
34
37
|
|
35
38
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
@@ -77,8 +80,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
77
80
|
########################################################################
|
78
81
|
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
79
82
|
|
80
|
-
list_options
|
81
|
-
list_options
|
83
|
+
list_options = CLIHelper::OPTIONS
|
84
|
+
list_options += OpenNebulaHelper::FORMAT
|
82
85
|
list_options << OpenNebulaHelper::NUMERIC
|
83
86
|
list_options << OpenNebulaHelper::DESCRIBE
|
84
87
|
|
@@ -148,7 +151,10 @@ CommandParser::CmdParser.new(ARGV) do
|
|
148
151
|
Shows information for the given VM Group
|
149
152
|
EOT
|
150
153
|
|
151
|
-
command :show,
|
154
|
+
command :show,
|
155
|
+
show_desc,
|
156
|
+
:vmgroupid,
|
157
|
+
:options => OpenNebulaHelper::FORMAT do
|
152
158
|
helper.show_resource(args[0], options)
|
153
159
|
end
|
154
160
|
|
data/bin/onevnet
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -27,9 +27,12 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
real_gems_path = File.realpath(GEMS_LOCATION)
|
31
|
+
if !defined?(Gem) || Gem.path != [real_gems_path]
|
32
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
33
|
+
require 'rubygems'
|
34
|
+
Gem.use_paths(real_gems_path)
|
35
|
+
end
|
33
36
|
end
|
34
37
|
|
35
38
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
@@ -320,7 +323,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
320
323
|
EOT
|
321
324
|
|
322
325
|
command :show, show_desc, :vnetid,
|
323
|
-
:options => [OpenNebulaHelper::
|
326
|
+
:options => [OpenNebulaHelper::FORMAT,
|
324
327
|
OpenNebulaHelper::DECRYPT,
|
325
328
|
OneVNetHelper::SHOW_AR] do
|
326
329
|
helper.show_resource(args[0], options)
|
data/bin/onevntemplate
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -27,9 +27,12 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
real_gems_path = File.realpath(GEMS_LOCATION)
|
31
|
+
if !defined?(Gem) || Gem.path != [real_gems_path]
|
32
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
33
|
+
require 'rubygems'
|
34
|
+
Gem.use_paths(real_gems_path)
|
35
|
+
end
|
33
36
|
end
|
34
37
|
|
35
38
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
@@ -78,8 +81,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
78
81
|
########################################################################
|
79
82
|
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
80
83
|
|
81
|
-
list_options
|
82
|
-
list_options
|
84
|
+
list_options = CLIHelper::OPTIONS
|
85
|
+
list_options += OpenNebulaHelper::FORMAT
|
83
86
|
list_options << OpenNebulaHelper::NUMERIC
|
84
87
|
list_options << OpenNebulaHelper::DESCRIBE
|
85
88
|
|
@@ -313,7 +316,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
313
316
|
EOT
|
314
317
|
|
315
318
|
command :show, show_desc, :templateid,
|
316
|
-
:options => [OpenNebulaHelper::
|
319
|
+
:options => [OpenNebulaHelper::FORMAT,
|
320
|
+
OneTemplateHelper::EXTENDED] do
|
317
321
|
helper.show_resource(args[0], options)
|
318
322
|
end
|
319
323
|
|
data/bin/onevrouter
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -27,9 +27,12 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
real_gems_path = File.realpath(GEMS_LOCATION)
|
31
|
+
if !defined?(Gem) || Gem.path != [real_gems_path]
|
32
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
33
|
+
require 'rubygems'
|
34
|
+
Gem.use_paths(real_gems_path)
|
35
|
+
end
|
33
36
|
end
|
34
37
|
|
35
38
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
@@ -79,8 +82,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
79
82
|
########################################################################
|
80
83
|
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
81
84
|
|
82
|
-
list_options
|
83
|
-
list_options
|
85
|
+
list_options = CLIHelper::OPTIONS
|
86
|
+
list_options += OpenNebulaHelper::FORMAT
|
84
87
|
list_options << OpenNebulaHelper::NUMERIC
|
85
88
|
list_options << OpenNebulaHelper::DESCRIBE
|
86
89
|
|
@@ -339,7 +342,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
339
342
|
EOT
|
340
343
|
|
341
344
|
command :show, show_desc, :vrouterid,
|
342
|
-
:options => [OpenNebulaHelper::
|
345
|
+
:options => [OpenNebulaHelper::FORMAT, OneVMHelper::ALL_TEMPLATE] do
|
343
346
|
helper.show_resource(args[0], options)
|
344
347
|
end
|
345
348
|
|
data/bin/onezone
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
4
|
+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
5
5
|
# #
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
7
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -27,9 +27,12 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
real_gems_path = File.realpath(GEMS_LOCATION)
|
31
|
+
if !defined?(Gem) || Gem.path != [real_gems_path]
|
32
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
33
|
+
require 'rubygems'
|
34
|
+
Gem.use_paths(real_gems_path)
|
35
|
+
end
|
33
36
|
end
|
34
37
|
|
35
38
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
@@ -68,8 +71,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
68
71
|
########################################################################
|
69
72
|
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
70
73
|
|
71
|
-
list_options
|
72
|
-
list_options
|
74
|
+
list_options = CLIHelper::OPTIONS
|
75
|
+
list_options += OpenNebulaHelper::FORMAT
|
73
76
|
list_options << OpenNebulaHelper::NUMERIC
|
74
77
|
list_options << OpenNebulaHelper::DESCRIBE
|
75
78
|
|
@@ -208,7 +211,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
208
211
|
Shows information for the given Zone
|
209
212
|
EOT
|
210
213
|
|
211
|
-
command :show, show_desc, :zoneid, :options => OpenNebulaHelper::
|
214
|
+
command :show, show_desc, :zoneid, :options => OpenNebulaHelper::FORMAT do
|
212
215
|
helper.show_resource(args[0], options)
|
213
216
|
end
|
214
217
|
|
data/lib/cli_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, 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 #
|
@@ -181,7 +181,7 @@ module CLIHelper
|
|
181
181
|
ANSI_YELLOW = "\33[33m"
|
182
182
|
|
183
183
|
# CLI states
|
184
|
-
OK_STATES = %w[runn rdy on
|
184
|
+
OK_STATES = %w[runn rdy on SUCCESS RUNNING]
|
185
185
|
BAD_STATES = %w[fail
|
186
186
|
err
|
187
187
|
error
|
@@ -189,7 +189,7 @@ module CLIHelper
|
|
189
189
|
FAILED_DEPLOYING
|
190
190
|
FAILED_UNDEPLOYING
|
191
191
|
FAILED_SCALING]
|
192
|
-
REGULAR_STATES = %w[
|
192
|
+
REGULAR_STATES = %w[PENDING DEPLOYING CONFIGURING WARNING]
|
193
193
|
|
194
194
|
# Set state color
|
195
195
|
#
|
@@ -357,14 +357,14 @@ module CLIHelper
|
|
357
357
|
# @param options [Hash] Object with CLI user options
|
358
358
|
# @param top [Boolean] True to not update columns again
|
359
359
|
def show(data, options = {}, top = false)
|
360
|
+
update_columns(options) unless top
|
361
|
+
|
360
362
|
if options[:list]
|
361
363
|
@cli_columns = options[:list].collect {|o| o.upcase.to_sym }
|
362
364
|
else
|
363
365
|
@cli_columns = @default_columns
|
364
366
|
end
|
365
367
|
|
366
|
-
update_columns(options) unless top
|
367
|
-
|
368
368
|
if data.is_a? Hash
|
369
369
|
@data = data
|
370
370
|
|
@@ -599,9 +599,7 @@ module CLIHelper
|
|
599
599
|
end
|
600
600
|
end
|
601
601
|
|
602
|
-
if options
|
603
|
-
filter_data!(res_data, options) if options[:filter]
|
604
|
-
end
|
602
|
+
filter_data!(res_data, options) if options && options[:filter]
|
605
603
|
|
606
604
|
res_data
|
607
605
|
end
|
data/lib/command_parser.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, 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 #
|
data/lib/one_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2021, 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 #
|
@@ -30,17 +30,19 @@ include OpenNebula
|
|
30
30
|
module OpenNebulaHelper
|
31
31
|
ONE_VERSION=<<-EOT
|
32
32
|
OpenNebula #{OpenNebula::VERSION}
|
33
|
-
Copyright 2002-
|
33
|
+
Copyright 2002-2021, OpenNebula Project, OpenNebula Systems
|
34
34
|
EOT
|
35
35
|
|
36
36
|
if ONE_LOCATION
|
37
|
-
TABLE_CONF_PATH=ONE_LOCATION+"/etc/cli"
|
38
|
-
VAR_LOCATION=ONE_LOCATION+"/var" if !defined?(VAR_LOCATION)
|
39
|
-
CLI_ADDONS_LOCATION=ONE_LOCATION+"/lib/ruby/cli/addons"
|
37
|
+
TABLE_CONF_PATH = ONE_LOCATION + "/etc/cli"
|
38
|
+
VAR_LOCATION = ONE_LOCATION + "/var" if !defined?(VAR_LOCATION)
|
39
|
+
CLI_ADDONS_LOCATION = ONE_LOCATION + "/lib/ruby/cli/addons"
|
40
|
+
XSD_PATH = ONE_LOCATION + '/share/schemas/xsd'
|
40
41
|
else
|
41
|
-
TABLE_CONF_PATH="/etc/one/cli"
|
42
|
-
VAR_LOCATION="/var/lib/one" if !defined?(VAR_LOCATION)
|
43
|
-
CLI_ADDONS_LOCATION="/usr/lib/one/ruby/cli/addons"
|
42
|
+
TABLE_CONF_PATH = "/etc/one/cli"
|
43
|
+
VAR_LOCATION = "/var/lib/one" if !defined?(VAR_LOCATION)
|
44
|
+
CLI_ADDONS_LOCATION = "/usr/lib/one/ruby/cli/addons"
|
45
|
+
XSD_PATH = '/usr/share/one/schemas/xsd'
|
44
46
|
end
|
45
47
|
|
46
48
|
EDITOR_PATH='/usr/bin/vi'
|
@@ -55,6 +57,23 @@ EOT
|
|
55
57
|
:description => "Show the resource in xml format"
|
56
58
|
}
|
57
59
|
|
60
|
+
JSON = {
|
61
|
+
:name => 'json',
|
62
|
+
:short => '-j',
|
63
|
+
:large => '--json',
|
64
|
+
:description => 'Show the resource in JSON format',
|
65
|
+
:proc => lambda do |_, _|
|
66
|
+
require 'json'
|
67
|
+
end
|
68
|
+
}
|
69
|
+
|
70
|
+
YAML = {
|
71
|
+
:name => 'yaml',
|
72
|
+
:short => '-y',
|
73
|
+
:large => '--yaml',
|
74
|
+
:description => 'Show the resource in YAML format'
|
75
|
+
}
|
76
|
+
|
58
77
|
NUMERIC={
|
59
78
|
:name => "numeric",
|
60
79
|
:short => "-n",
|
@@ -383,9 +402,15 @@ EOT
|
|
383
402
|
:format => Array,
|
384
403
|
:description => 'Specify the user inputs values when instantiating',
|
385
404
|
:proc => lambda do |o, options|
|
405
|
+
# Store user inputs that has been already processed
|
406
|
+
options[:user_inputs_keys] = []
|
407
|
+
|
386
408
|
# escape values
|
387
409
|
options[:user_inputs].map! do |user_input|
|
388
410
|
user_input_split = user_input.split('=')
|
411
|
+
|
412
|
+
options[:user_inputs_keys] << user_input_split[0]
|
413
|
+
|
389
414
|
"#{user_input_split[0]}=\"#{user_input_split[1]}\""
|
390
415
|
end
|
391
416
|
|
@@ -422,7 +447,9 @@ EOT
|
|
422
447
|
UPDATECONF_OPTIONS_VM = TEMPLATE_OPTIONS[6..15] + [TEMPLATE_OPTIONS[2],
|
423
448
|
TEMPLATE_OPTIONS[17], TEMPLATE_OPTIONS[18]]
|
424
449
|
|
425
|
-
|
450
|
+
FORMAT = [XML, JSON, YAML]
|
451
|
+
|
452
|
+
OPTIONS = FORMAT, EXTENDED, NUMERIC, KILOBYTES
|
426
453
|
|
427
454
|
class OneHelper
|
428
455
|
attr_accessor :client
|
@@ -519,8 +546,12 @@ EOT
|
|
519
546
|
@translation_hash = nil
|
520
547
|
end
|
521
548
|
|
522
|
-
def set_client(options)
|
523
|
-
|
549
|
+
def set_client(options, client=nil)
|
550
|
+
if client.nil?
|
551
|
+
@client=OpenNebulaHelper::OneHelper.get_client(options, true)
|
552
|
+
else
|
553
|
+
@client = client
|
554
|
+
end
|
524
555
|
end
|
525
556
|
|
526
557
|
def create_resource(options, &block)
|
@@ -580,12 +611,10 @@ EOT
|
|
580
611
|
end
|
581
612
|
|
582
613
|
def print_page(pool, options)
|
583
|
-
|
614
|
+
elements = 0
|
615
|
+
page = ""
|
584
616
|
|
585
617
|
if options[:xml]
|
586
|
-
elements = 0
|
587
|
-
page = ""
|
588
|
-
|
589
618
|
pool.each {|e|
|
590
619
|
elements += 1
|
591
620
|
page << e.to_xml(true) << "\n"
|
@@ -594,8 +623,15 @@ EOT
|
|
594
623
|
pname = pool.pool_name
|
595
624
|
ename = pool.element_name
|
596
625
|
|
597
|
-
|
598
|
-
|
626
|
+
if options[:decrypt]
|
627
|
+
page = pool.map do |element|
|
628
|
+
element.info(true)
|
629
|
+
element.to_hash[ename]
|
630
|
+
end
|
631
|
+
else
|
632
|
+
page = pool.to_hash
|
633
|
+
elems = page[pname][ename]
|
634
|
+
end
|
599
635
|
|
600
636
|
if elems.class == Array
|
601
637
|
elements = elems.length
|
@@ -616,7 +652,7 @@ EOT
|
|
616
652
|
size = $stdout.winsize[0] - 1
|
617
653
|
|
618
654
|
# ----------- First page, check if pager is needed -------------
|
619
|
-
rc = pool.get_page(size, 0, false)
|
655
|
+
rc = pool.get_page(size, 0, false, options[:state])
|
620
656
|
ps = ""
|
621
657
|
|
622
658
|
return -1, rc.message if OpenNebula.is_error?(rc)
|
@@ -644,7 +680,7 @@ EOT
|
|
644
680
|
options[:no_header] = true
|
645
681
|
|
646
682
|
loop do
|
647
|
-
rc = pool.get_page(size, current, false)
|
683
|
+
rc = pool.get_page(size, current, false, options[:state])
|
648
684
|
|
649
685
|
return -1, rc.message if OpenNebula.is_error?(rc)
|
650
686
|
|
@@ -667,19 +703,19 @@ EOT
|
|
667
703
|
|
668
704
|
stop_pager(ppid)
|
669
705
|
else
|
670
|
-
|
671
|
-
|
706
|
+
rc = pool.info
|
707
|
+
|
708
|
+
return -1, rc.message if OpenNebula.is_error?(rc)
|
672
709
|
|
673
|
-
|
674
|
-
elements = array["#{rname}_POOL"][rname]
|
710
|
+
_, hash = print_page(pool, options)
|
675
711
|
|
676
712
|
if options[:ids] && elements
|
677
|
-
|
713
|
+
hash.reject! do |element|
|
678
714
|
!options[:ids].include?(element['ID'].to_i)
|
679
715
|
end
|
680
716
|
end
|
681
717
|
|
682
|
-
table.show(
|
718
|
+
table.show(hash, options)
|
683
719
|
end
|
684
720
|
|
685
721
|
return 0
|
@@ -695,7 +731,7 @@ EOT
|
|
695
731
|
size = $stdout.winsize[0] - 1
|
696
732
|
|
697
733
|
# ----------- First page, check if pager is needed -------------
|
698
|
-
rc = pool.get_page(size, 0, extended)
|
734
|
+
rc = pool.get_page(size, 0, extended, options[:state])
|
699
735
|
ps = ""
|
700
736
|
|
701
737
|
return -1, rc.message if OpenNebula.is_error?(rc)
|
@@ -730,7 +766,7 @@ EOT
|
|
730
766
|
current = size
|
731
767
|
|
732
768
|
loop do
|
733
|
-
rc = pool.get_page(size, current, extended)
|
769
|
+
rc = pool.get_page(size, current, extended, options[:state])
|
734
770
|
|
735
771
|
return -1, rc.message if OpenNebula.is_error?(rc)
|
736
772
|
|
@@ -769,6 +805,82 @@ EOT
|
|
769
805
|
return 0
|
770
806
|
end
|
771
807
|
|
808
|
+
#-----------------------------------------------------------------------
|
809
|
+
# List pool in JSON format, pagination is used in interactive output
|
810
|
+
#-----------------------------------------------------------------------
|
811
|
+
def list_pool_format(pool, options, filter_flag)
|
812
|
+
extended = options.include?(:extended) && options[:extended]
|
813
|
+
|
814
|
+
if $stdout.isatty and (!options.key?:no_pager)
|
815
|
+
size = $stdout.winsize[0] - 1
|
816
|
+
|
817
|
+
# ----------- First page, check if pager is needed -------------
|
818
|
+
rc = pool.get_page(size, 0, extended, options[:state])
|
819
|
+
ps = ""
|
820
|
+
|
821
|
+
return -1, rc.message if OpenNebula.is_error?(rc)
|
822
|
+
|
823
|
+
elements = get_format_size(pool, options)
|
824
|
+
ppid = -1
|
825
|
+
|
826
|
+
if elements >= size
|
827
|
+
ppid = start_pager
|
828
|
+
end
|
829
|
+
|
830
|
+
yield(pool) if block_given?
|
831
|
+
|
832
|
+
if elements < size
|
833
|
+
return 0
|
834
|
+
end
|
835
|
+
|
836
|
+
if elements < size
|
837
|
+
return 0
|
838
|
+
elsif !pool.is_paginated?
|
839
|
+
stop_pager(ppid)
|
840
|
+
return 0
|
841
|
+
end
|
842
|
+
|
843
|
+
# ------- Rest of the pages in the pool, piped to pager --------
|
844
|
+
current = size
|
845
|
+
|
846
|
+
loop do
|
847
|
+
rc = pool.get_page(size, current, extended, options[:state])
|
848
|
+
|
849
|
+
return -1, rc.message if OpenNebula.is_error?(rc)
|
850
|
+
|
851
|
+
current += size
|
852
|
+
|
853
|
+
begin
|
854
|
+
Process.waitpid(ppid, Process::WNOHANG)
|
855
|
+
rescue Errno::ECHILD
|
856
|
+
break
|
857
|
+
end
|
858
|
+
|
859
|
+
elements = get_format_size(pool, options)
|
860
|
+
|
861
|
+
break if elements < size
|
862
|
+
|
863
|
+
yield(pool) if block_given?
|
864
|
+
|
865
|
+
$stdout.flush
|
866
|
+
end
|
867
|
+
|
868
|
+
stop_pager(ppid)
|
869
|
+
else
|
870
|
+
if pool.pool_name == "VM_POOL" && extended
|
871
|
+
rc = pool.info_all_extended
|
872
|
+
else
|
873
|
+
rc = pool.info
|
874
|
+
end
|
875
|
+
|
876
|
+
return -1, rc.message if OpenNebula.is_error?(rc)
|
877
|
+
|
878
|
+
yield(pool) if block_given?
|
879
|
+
end
|
880
|
+
|
881
|
+
return 0
|
882
|
+
end
|
883
|
+
|
772
884
|
#-----------------------------------------------------------------------
|
773
885
|
# List pool table in top-like form
|
774
886
|
#-----------------------------------------------------------------------
|
@@ -797,11 +909,27 @@ EOT
|
|
797
909
|
filter_flag ||= OpenNebula::Pool::INFO_ALL
|
798
910
|
|
799
911
|
pool = factory_pool(filter_flag)
|
912
|
+
pname = pool.pool_name
|
913
|
+
ename = pool.element_name
|
800
914
|
|
801
915
|
if top
|
802
916
|
return list_pool_top(table, pool, options)
|
803
917
|
elsif options[:xml]
|
804
918
|
return list_pool_xml(pool, options, filter_flag)
|
919
|
+
elsif options[:json]
|
920
|
+
list_pool_format(pool, options, filter_flag) do |pool|
|
921
|
+
hash = check_resource_xsd(pool, pname)
|
922
|
+
hash[pname] = check_resource_xsd(hash[pname], ename)
|
923
|
+
|
924
|
+
puts ::JSON.pretty_generate(hash)
|
925
|
+
end
|
926
|
+
elsif options[:yaml]
|
927
|
+
list_pool_format(pool, options, filter_flag) do |pool|
|
928
|
+
hash = check_resource_xsd(pool, pname)
|
929
|
+
hash[pname] = check_resource_xsd(hash[pname], ename)
|
930
|
+
|
931
|
+
puts hash.to_yaml(:indent => 4)
|
932
|
+
end
|
805
933
|
else
|
806
934
|
return list_pool_table(table, pool, options, filter_flag)
|
807
935
|
end
|
@@ -845,6 +973,17 @@ EOT
|
|
845
973
|
|
846
974
|
if options[:xml]
|
847
975
|
return 0, resource.to_xml(true)
|
976
|
+
elsif options[:json]
|
977
|
+
# If body is set, the resource contains a JSON inside
|
978
|
+
if options[:body]
|
979
|
+
return 0, check_resource_xsd(resource)
|
980
|
+
else
|
981
|
+
return 0, ::JSON.pretty_generate(
|
982
|
+
check_resource_xsd(resource)
|
983
|
+
)
|
984
|
+
end
|
985
|
+
elsif options[:yaml]
|
986
|
+
return 0, check_resource_xsd(resource).to_yaml(:indent => 4)
|
848
987
|
else
|
849
988
|
format_resource(resource, options)
|
850
989
|
return 0
|
@@ -1054,6 +1193,199 @@ EOT
|
|
1054
1193
|
|
1055
1194
|
return 0, pool
|
1056
1195
|
end
|
1196
|
+
|
1197
|
+
def get_format_size(pool, options)
|
1198
|
+
if options[:json]
|
1199
|
+
::JSON.pretty_generate(pool.to_hash).split("\n").size
|
1200
|
+
elsif options[:yaml]
|
1201
|
+
pool.to_hash.to_yaml.split("\n").size
|
1202
|
+
else
|
1203
|
+
STDERR.puts 'ERROR: Format not found'
|
1204
|
+
exit(-1)
|
1205
|
+
end
|
1206
|
+
end
|
1207
|
+
|
1208
|
+
########################################################################
|
1209
|
+
# XSD check and fix
|
1210
|
+
########################################################################
|
1211
|
+
|
1212
|
+
# Check XSD values for a single resource
|
1213
|
+
#
|
1214
|
+
# @param resource [OpenNebula::Object] Resource to check
|
1215
|
+
# @param ename [String] Resource name
|
1216
|
+
#
|
1217
|
+
# @return [Object] Hash with correct values
|
1218
|
+
def check_resource_xsd(resource, ename = nil)
|
1219
|
+
hash = resource.to_hash
|
1220
|
+
ename = hash.keys.first unless ename
|
1221
|
+
xsd = read_xsd(ename)
|
1222
|
+
|
1223
|
+
return hash unless xsd
|
1224
|
+
|
1225
|
+
hash[ename] = check_xsd(hash[ename], nil, ename, xsd)
|
1226
|
+
|
1227
|
+
hash
|
1228
|
+
end
|
1229
|
+
|
1230
|
+
# Read XSD file and parse to XML
|
1231
|
+
#
|
1232
|
+
# @param ename [String] Element name to read XSD
|
1233
|
+
#
|
1234
|
+
# @return [Hash] XSD in hash format, nil if not found
|
1235
|
+
def read_xsd(ename)
|
1236
|
+
require 'active_support/core_ext/hash/conversions'
|
1237
|
+
|
1238
|
+
# Try GEM directory
|
1239
|
+
file = File.expand_path(
|
1240
|
+
"../share/schemas/xsd/#{ename.downcase}.xsd",
|
1241
|
+
File.dirname(__FILE__)
|
1242
|
+
)
|
1243
|
+
|
1244
|
+
file = "#{XSD_PATH}/#{ename.downcase}.xsd" unless File.exist?(file)
|
1245
|
+
|
1246
|
+
unless File.exist?(file)
|
1247
|
+
STDERR.puts "WARNING: XSD for #{ename} not found, skipping check"
|
1248
|
+
return nil
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
hash = Hash.from_xml(Nokogiri::XML(File.read(file)).to_s)
|
1252
|
+
hash = hash['schema']['element']
|
1253
|
+
|
1254
|
+
if hash.keys.include?('complexType')
|
1255
|
+
hash['complexType']['sequence']['element']
|
1256
|
+
else
|
1257
|
+
hash['element']
|
1258
|
+
end
|
1259
|
+
end
|
1260
|
+
|
1261
|
+
# Check values XSD
|
1262
|
+
#
|
1263
|
+
# @param hash [Object] Resource information in hash format
|
1264
|
+
# @param elements [Array] Keys to check
|
1265
|
+
# @param ename [String] Element name to take XSD
|
1266
|
+
# @param xsd [Hash] XSD file content
|
1267
|
+
# @param parents [Array] Parent keys of current hash
|
1268
|
+
def check_xsd(hash, elements, ename, xsd, parents = [])
|
1269
|
+
return unless hash
|
1270
|
+
|
1271
|
+
if (hash.is_a? Hash) && !hash.empty?
|
1272
|
+
hash.map do |ki, vi|
|
1273
|
+
vi = [vi].flatten if is_array?(xsd, [ki])
|
1274
|
+
|
1275
|
+
if (vi.is_a? Hash) && !vi.empty?
|
1276
|
+
parents << ki
|
1277
|
+
|
1278
|
+
vi.map do |kj, vj|
|
1279
|
+
parents << kj
|
1280
|
+
|
1281
|
+
path = (parents + [ki, kj]).uniq
|
1282
|
+
vj = [vj].flatten if is_array?(xsd, path)
|
1283
|
+
|
1284
|
+
hash[ki][kj] = check_xsd(vj,
|
1285
|
+
[ki, kj],
|
1286
|
+
ename,
|
1287
|
+
xsd,
|
1288
|
+
parents)
|
1289
|
+
end
|
1290
|
+
|
1291
|
+
parents.clear
|
1292
|
+
elsif vi.is_a? Array
|
1293
|
+
hash[ki] = check_xsd(vi, [ki], ename, xsd, parents)
|
1294
|
+
else
|
1295
|
+
hash[ki] = check_xsd(vi, [ki], ename, xsd, parents)
|
1296
|
+
end
|
1297
|
+
end
|
1298
|
+
|
1299
|
+
hash
|
1300
|
+
elsif hash.is_a? Array
|
1301
|
+
ret = []
|
1302
|
+
|
1303
|
+
hash.each do |v|
|
1304
|
+
ret << check_xsd(v, elements, ename, xsd, parents)
|
1305
|
+
end
|
1306
|
+
|
1307
|
+
ret
|
1308
|
+
else
|
1309
|
+
check_type(hash) do
|
1310
|
+
type = get_xsd_path(xsd, elements)
|
1311
|
+
type['type'] unless type.nil?
|
1312
|
+
end
|
1313
|
+
end
|
1314
|
+
end
|
1315
|
+
|
1316
|
+
# Get xsd path value
|
1317
|
+
#
|
1318
|
+
# @param xsd [Hash] XSD information
|
1319
|
+
# @param elements [Array] Path to get
|
1320
|
+
#
|
1321
|
+
# @return [Hash] Path information
|
1322
|
+
def get_xsd_path(xsd, elements)
|
1323
|
+
return unless elements
|
1324
|
+
|
1325
|
+
element = elements.shift
|
1326
|
+
|
1327
|
+
# Return nil, because is an empty complexType
|
1328
|
+
return unless element
|
1329
|
+
|
1330
|
+
element = [xsd].flatten.find do |v|
|
1331
|
+
v['name'] == element || v['ref'] == element
|
1332
|
+
end
|
1333
|
+
|
1334
|
+
# Return nil, because element was not find in XSD
|
1335
|
+
return unless element
|
1336
|
+
|
1337
|
+
if element.keys.include?('complexType') && !elements.empty?
|
1338
|
+
if element['complexType']['all']
|
1339
|
+
element = element['complexType']['all']['element']
|
1340
|
+
else
|
1341
|
+
element = element['complexType']['sequence']['element']
|
1342
|
+
end
|
1343
|
+
|
1344
|
+
get_xsd_path(element, elements)
|
1345
|
+
else
|
1346
|
+
element
|
1347
|
+
end
|
1348
|
+
end
|
1349
|
+
|
1350
|
+
# CHeck if current element is an array
|
1351
|
+
#
|
1352
|
+
# @param xsd [Hash] XSD information
|
1353
|
+
# @param elements [Array] Path to check
|
1354
|
+
#
|
1355
|
+
# @return [Boolean] True if it's an array, false otherwise
|
1356
|
+
def is_array?(xsd, elements)
|
1357
|
+
max = get_xsd_path(xsd, elements)
|
1358
|
+
max = max['maxOccurs'] if max
|
1359
|
+
|
1360
|
+
max == 'unbounded' || max.to_i > 1
|
1361
|
+
end
|
1362
|
+
|
1363
|
+
# Check XSD type for especific value
|
1364
|
+
#
|
1365
|
+
# @param value [Object] Value to check
|
1366
|
+
#
|
1367
|
+
# @return [Object] nil if the type is not correct, value otherwise
|
1368
|
+
def check_type(value)
|
1369
|
+
type = yield if block_given?
|
1370
|
+
|
1371
|
+
# If there is no type, return current value
|
1372
|
+
return value unless type
|
1373
|
+
|
1374
|
+
types = %w[string decimal integer boolean date time]
|
1375
|
+
type = type.split(':')[1]
|
1376
|
+
|
1377
|
+
if types.include?(type)
|
1378
|
+
# If the current type is different, return string
|
1379
|
+
# because this value doesn't respect the type
|
1380
|
+
if (value.is_a? Hash) || (value.is_a? Array)
|
1381
|
+
''
|
1382
|
+
else
|
1383
|
+
value
|
1384
|
+
end
|
1385
|
+
else
|
1386
|
+
value
|
1387
|
+
end
|
1388
|
+
end
|
1057
1389
|
end
|
1058
1390
|
|
1059
1391
|
def OpenNebulaHelper.rname_to_id(name, poolname)
|
@@ -1062,18 +1394,20 @@ EOT
|
|
1062
1394
|
client=OneHelper.client
|
1063
1395
|
|
1064
1396
|
pool = case poolname
|
1065
|
-
when "HOST"
|
1066
|
-
when "HOOK"
|
1067
|
-
when "GROUP"
|
1068
|
-
when "USER"
|
1069
|
-
when "DATASTORE"
|
1070
|
-
when "CLUSTER"
|
1071
|
-
when "VNET"
|
1072
|
-
when "IMAGE"
|
1073
|
-
when "VMTEMPLATE"
|
1074
|
-
when "
|
1075
|
-
when "
|
1076
|
-
when "
|
1397
|
+
when "HOST" then OpenNebula::HostPool.new(client)
|
1398
|
+
when "HOOK" then OpenNebula::HookPool.new(client)
|
1399
|
+
when "GROUP" then OpenNebula::GroupPool.new(client)
|
1400
|
+
when "USER" then OpenNebula::UserPool.new(client)
|
1401
|
+
when "DATASTORE" then OpenNebula::DatastorePool.new(client)
|
1402
|
+
when "CLUSTER" then OpenNebula::ClusterPool.new(client)
|
1403
|
+
when "VNET" then OpenNebula::VirtualNetworkPool.new(client)
|
1404
|
+
when "IMAGE" then OpenNebula::ImagePool.new(client)
|
1405
|
+
when "VMTEMPLATE" then OpenNebula::TemplatePool.new(client)
|
1406
|
+
when "VNTEMPLATES" then OpenNebula::VNTemplatePool.new(client)
|
1407
|
+
when "VM" then OpenNebula::VirtualMachinePool.new(client)
|
1408
|
+
when "ZONE" then OpenNebula::ZonePool.new(client)
|
1409
|
+
when "MARKETPLACE" then OpenNebula::MarketPlacePool.new(client)
|
1410
|
+
when "FLOWTEMPLATES" then OpenNebula::ServiceTemplatePool.new(client)
|
1077
1411
|
end
|
1078
1412
|
|
1079
1413
|
rc = pool.info
|
@@ -1259,6 +1593,43 @@ EOT
|
|
1259
1593
|
end
|
1260
1594
|
end
|
1261
1595
|
|
1596
|
+
def OpenNebulaHelper.update_obj(obj, file, plain = false)
|
1597
|
+
rc = obj.info(true)
|
1598
|
+
|
1599
|
+
return rc if OpenNebula.is_error?(rc)
|
1600
|
+
|
1601
|
+
if file
|
1602
|
+
path = file
|
1603
|
+
else
|
1604
|
+
tmp = Tempfile.new(obj['ID'])
|
1605
|
+
path = tmp.path
|
1606
|
+
|
1607
|
+
tmp.write(yield(obj)) if block_given?
|
1608
|
+
tmp.flush
|
1609
|
+
|
1610
|
+
if ENV['EDITOR']
|
1611
|
+
editor_path = ENV['EDITOR']
|
1612
|
+
else
|
1613
|
+
editor_path = EDITOR_PATH
|
1614
|
+
end
|
1615
|
+
|
1616
|
+
system("#{editor_path} #{path}")
|
1617
|
+
|
1618
|
+
unless $CHILD_STATUS.exitstatus.zero?
|
1619
|
+
STDERR.puts 'Editor not defined'
|
1620
|
+
exit(-1)
|
1621
|
+
end
|
1622
|
+
|
1623
|
+
tmp.close
|
1624
|
+
end
|
1625
|
+
|
1626
|
+
if plain
|
1627
|
+
obj.update(File.read(path), plain)
|
1628
|
+
else
|
1629
|
+
obj.update(File.read(path))
|
1630
|
+
end
|
1631
|
+
end
|
1632
|
+
|
1262
1633
|
def OpenNebulaHelper.editor_input(contents=nil)
|
1263
1634
|
require 'tempfile'
|
1264
1635
|
|
@@ -1705,8 +2076,8 @@ EOT
|
|
1705
2076
|
end
|
1706
2077
|
end
|
1707
2078
|
|
1708
|
-
def OpenNebulaHelper.parse_user_inputs(inputs,
|
1709
|
-
unless
|
2079
|
+
def OpenNebulaHelper.parse_user_inputs(inputs, keys = [])
|
2080
|
+
unless inputs.keys == keys
|
1710
2081
|
puts 'There are some parameters that require user input. ' \
|
1711
2082
|
'Use the string <<EDITOR>> to launch an editor ' \
|
1712
2083
|
'(e.g. for multi-line inputs)'
|
@@ -1715,6 +2086,8 @@ EOT
|
|
1715
2086
|
answers = {}
|
1716
2087
|
|
1717
2088
|
inputs.each do |key, val|
|
2089
|
+
next if keys.include? key
|
2090
|
+
|
1718
2091
|
input_cfg = val.split('|', -1)
|
1719
2092
|
|
1720
2093
|
if input_cfg.length < 3
|
@@ -1741,11 +2114,6 @@ EOT
|
|
1741
2114
|
initial.strip!
|
1742
2115
|
end
|
1743
2116
|
|
1744
|
-
if get_defaults
|
1745
|
-
answers[key]= initial unless mandatory == 'M'
|
1746
|
-
next
|
1747
|
-
end
|
1748
|
-
|
1749
2117
|
puts " * (#{key}) #{description}"
|
1750
2118
|
|
1751
2119
|
header = ' '
|