1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-08 21:17:43 +03:00

F #4950: add JSON and YAML outputs (#63)

This commit is contained in:
Alejandro Huertas Herrero 2020-07-14 17:42:30 +02:00 committed by GitHub
parent c2ab2e12d2
commit 472ee2bccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 467 additions and 90 deletions

View File

@ -255,6 +255,7 @@ SHARE_DIRS="$SHARE_LOCATION/examples \
$SHARE_LOCATION/oneprovision \
$SHARE_LOCATION/schemas \
$SHARE_LOCATION/schemas/libvirt \
$SHARE_LOCATION/schemas/xsd \
$SHARE_LOCATION/ssh \
$SHARE_LOCATION/start-scripts \
$SHARE_LOCATION/conf \
@ -688,6 +689,7 @@ INSTALL_FILES=(
VENDOR_DIRS:$LIB_LOCATION/ruby/vendors
START_SCRIPT_SHARE_FILES:$SHARE_LOCATION/start-scripts
LIBVIRT_RNG_SHARE_MODULE_FILES:$SHARE_LOCATION/schemas/libvirt
XSD_FILES:$SHARE_LOCATION/schemas/xsd
SSH_SH_LIB_FILES:$LIB_LOCATION/sh
SSH_SH_OVERRIDE_LIB_FILES:$LIB_LOCATION/sh/override
SSH_SHARE_FILES:$SHARE_LOCATION/ssh
@ -2729,6 +2731,58 @@ LIBVIRT_RNG_SHARE_MODULE_FILES="share/schemas/libvirt/basictypes.rng \
share/schemas/libvirt/nwfilter_params.rng \
share/schemas/libvirt/storagecommon.rng"
#-------------------------------------------------------------------------------
# XSD
#-------------------------------------------------------------------------------
XSD_FILES="share/doc/xsd/acct.xsd \
share/doc/xsd/acl_pool.xsd
share/doc/xsd/api_info.xsd
share/doc/xsd/cluster.xsd
share/doc/xsd/cluster_pool.xsd
share/doc/xsd/datastore.xsd
share/doc/xsd/datastore_pool.xsd
share/doc/xsd/document.xsd
share/doc/xsd/document_pool.xsd
share/doc/xsd/group.xsd
share/doc/xsd/group_pool.xsd
share/doc/xsd/hook.xsd
share/doc/xsd/hook_message_api.xsd
share/doc/xsd/hook_message_retry.xsd
share/doc/xsd/hook_message_state.xsd
share/doc/xsd/hook_pool.xsd
share/doc/xsd/host.xsd
share/doc/xsd/host_pool.xsd
share/doc/xsd/image.xsd
share/doc/xsd/image_pool.xsd
share/doc/xsd/index.xsd
share/doc/xsd/marketplace.xsd
share/doc/xsd/marketplace_pool.xsd
share/doc/xsd/marketplaceapp.xsd
share/doc/xsd/marketplaceapp_pool.xsd
share/doc/xsd/raftstatus.xsd
share/doc/xsd/security_group.xsd
share/doc/xsd/security_group_pool.xsd
share/doc/xsd/showback.xsd
share/doc/xsd/user.xsd
share/doc/xsd/user_pool.xsd
share/doc/xsd/vdc.xsd
share/doc/xsd/vdc_pool.xsd
share/doc/xsd/vm.xsd
share/doc/xsd/vm_group.xsd
share/doc/xsd/vm_group_pool.xsd
share/doc/xsd/vm_pool.xsd
share/doc/xsd/vmtemplate.xsd
share/doc/xsd/vmtemplate_pool.xsd
share/doc/xsd/vnet.xsd
share/doc/xsd/vnet_pool.xsd
share/doc/xsd/vntemplate.xsd
share/doc/xsd/vntemplate_pool.xsd
share/doc/xsd/vrouter.xsd
share/doc/xsd/vrouter_pool.xsd
share/doc/xsd/zone.xsd
share/doc/xsd/zone_pool.xsd"
CONTEXT_SHARE=$(find share/context/ -type f \( ! -iname "*.sh" ! -iname "SConstruct" \))
#-----------------------------------------------------------------------------

View File

@ -95,6 +95,9 @@ GEM_DESCRIPTION={
:cli => {
:name => 'opennebula-cli',
:files => [
# Needed for JSON and YAML outputs
['share/doc/xsd/*.xsd', '/share/schemas/xsd'],
['src/cli/one[a-z]*', '/bin', 'oneprovision'],
['src/cli/*.rb', '/lib'],
['src/cli/one_helper/*.rb', '/lib/one_helper'],
@ -104,7 +107,8 @@ GEM_DESCRIPTION={
:summary => 'OpenNebula Command Line Interface',
:description => 'Commands used to talk to OpenNebula',
:dependencies => [
['opennebula', "= #{DEFAULTS[:version]}"]
['opennebula', "= #{DEFAULTS[:version]}"],
'activesupport'
]
}
}

View File

@ -37,10 +37,12 @@ EOT
TABLE_CONF_PATH = ONE_LOCATION + "/etc/cli"
VAR_LOCATION = ONE_LOCATION + "/var" if !defined?(VAR_LOCATION)
CLI_ADDONS_LOCATION = ONE_LOCATION + "/lib/ruby/cli/addons"
XSD_PATH = ONE_LOCATION + '/share/schemas/xsd'
else
TABLE_CONF_PATH = "/etc/one/cli"
VAR_LOCATION = "/var/lib/one" if !defined?(VAR_LOCATION)
CLI_ADDONS_LOCATION = "/usr/lib/one/ruby/cli/addons"
XSD_PATH = '/usr/share/one/schemas/xsd'
end
EDITOR_PATH='/usr/bin/vi'
@ -55,6 +57,23 @@ EOT
:description => "Show the resource in xml format"
}
JSON = {
:name => 'json',
:short => '-j',
:large => '--json',
:description => 'Show the resource in JSON format',
:proc => lambda do |_, _|
require 'json'
end
}
YAML = {
:name => 'yaml',
:short => '-y',
:large => '--yaml',
:description => 'Show the resource in YAML format'
}
NUMERIC={
:name => "numeric",
:short => "-n",
@ -422,7 +441,9 @@ EOT
UPDATECONF_OPTIONS_VM = TEMPLATE_OPTIONS[6..15] + [TEMPLATE_OPTIONS[2],
TEMPLATE_OPTIONS[17], TEMPLATE_OPTIONS[18]]
OPTIONS = XML, EXTENDED, NUMERIC, KILOBYTES
FORMAT = [XML, JSON, YAML]
OPTIONS = FORMAT, EXTENDED, NUMERIC, KILOBYTES
class OneHelper
attr_accessor :client
@ -580,12 +601,10 @@ EOT
end
def print_page(pool, options)
page = nil
if options[:xml]
elements = 0
page = ""
if options[:xml]
pool.each {|e|
elements += 1
page << e.to_xml(true) << "\n"
@ -769,6 +788,82 @@ EOT
return 0
end
#-----------------------------------------------------------------------
# List pool in JSON format, pagination is used in interactive output
#-----------------------------------------------------------------------
def list_pool_format(pool, options, filter_flag)
extended = options.include?(:extended) && options[:extended]
if $stdout.isatty and (!options.key?:no_pager)
size = $stdout.winsize[0] - 1
# ----------- First page, check if pager is needed -------------
rc = pool.get_page(size, 0, extended)
ps = ""
return -1, rc.message if OpenNebula.is_error?(rc)
elements = get_format_size(pool, options)
ppid = -1
if elements >= size
ppid = start_pager
end
yield(pool) if block_given?
if elements < size
return 0
end
if elements < size
return 0
elsif !pool.is_paginated?
stop_pager(ppid)
return 0
end
# ------- Rest of the pages in the pool, piped to pager --------
current = size
loop do
rc = pool.get_page(size, current, extended)
return -1, rc.message if OpenNebula.is_error?(rc)
current += size
begin
Process.waitpid(ppid, Process::WNOHANG)
rescue Errno::ECHILD
break
end
elements = get_format_size(pool, options)
break if elements < size
yield(pool) if block_given?
$stdout.flush
end
stop_pager(ppid)
else
if pool.pool_name == "VM_POOL" && extended
rc = pool.info_all_extended
else
rc = pool.info
end
return -1, rc.message if OpenNebula.is_error?(rc)
yield(pool) if block_given?
end
return 0
end
#-----------------------------------------------------------------------
# List pool table in top-like form
#-----------------------------------------------------------------------
@ -797,11 +892,27 @@ EOT
filter_flag ||= OpenNebula::Pool::INFO_ALL
pool = factory_pool(filter_flag)
pname = pool.pool_name
ename = pool.element_name
if top
return list_pool_top(table, pool, options)
elsif options[:xml]
return list_pool_xml(pool, options, filter_flag)
elsif options[:json]
list_pool_format(pool, options, filter_flag) do |pool|
hash = check_resource_xsd(pool, pname)
hash[pname] = check_resource_xsd(hash[pname], ename)
puts ::JSON.pretty_generate(hash)
end
elsif options[:yaml]
list_pool_format(pool, options, filter_flag) do |pool|
hash = check_resource_xsd(pool, pname)
hash[pname] = check_resource_xsd(hash[pname], ename)
puts hash.to_yaml(:indent => 4)
end
else
return list_pool_table(table, pool, options, filter_flag)
end
@ -845,6 +956,10 @@ EOT
if options[:xml]
return 0, resource.to_xml(true)
elsif options[:json]
return 0, ::JSON.pretty_generate(check_resource_xsd(resource))
elsif options[:yaml]
return 0, check_resource_xsd(resource).to_yaml(:indent => 4)
else
format_resource(resource, options)
return 0
@ -1054,6 +1169,185 @@ EOT
return 0, pool
end
def get_format_size(pool, options)
if options[:json]
::JSON.pretty_generate(pool.to_hash).split("\n").size
elsif options[:yaml]
pool.to_hash.to_yaml.split("\n").size
else
STDERR.puts 'ERROR: Format not found'
exit(-1)
end
end
########################################################################
# XSD check and fix
########################################################################
# Check XSD values for a single resource
#
# @param resource [OpenNebula::Object] Resource to check
# @param ename [String] Resource name
#
# @return [Object] Hash with correct values
def check_resource_xsd(resource, ename = nil)
hash = resource.to_hash
ename = hash.keys.first unless ename
xsd = read_xsd(ename)
return hash unless xsd
hash[ename] = check_xsd(hash[ename], nil, ename, xsd)
hash
end
# Read XSD file and parse to XML
#
# @param ename [String] Element name to read XSD
#
# @return [Hash] XSD in hash format, nil if not found
def read_xsd(ename)
require 'active_support/core_ext/hash/conversions'
# Try GEM directory
file = File.expand_path(
"../share/schemas/xsd/#{ename.downcase}.xsd",
File.dirname(__FILE__)
)
file = "#{XSD_PATH}/#{ename.downcase}.xsd" unless File.exist?(file)
unless File.exist?(file)
STDERR.puts "WARNING: XSD for #{ename} not found, skipping check"
return nil
end
hash = Hash.from_xml(Nokogiri::XML(File.read(file)).to_s)
hash = hash['schema']['element']
if hash.keys.include?('complexType')
hash['complexType']['sequence']['element']
else
hash['element']
end
end
# Check values XSD
#
# @param hash [Object] Resource information in hash format
# @param elements [Array] Keys to check
# @param ename [String] Element name to take XSD
# @param xsd [Hash] XSD file content
def check_xsd(hash, elements, ename, xsd)
return unless hash
if (hash.is_a? Hash) && !hash.empty?
hash.map do |ki, vi|
vi = [vi].flatten if is_array?(xsd, [ki])
if (vi.is_a? Hash) && !vi.empty?
vi.map do |kj, vj|
vj = [vj].flatten if is_array?(xsd, [ki, kj])
hash[ki][kj] = check_xsd(vj, [ki, kj], ename, xsd)
end
elsif vi.is_a? Array
hash[ki] = check_xsd(vi, [ki], ename, xsd)
else
hash[ki] = check_xsd(vi, [ki], ename, xsd)
end
end
hash
elsif hash.is_a? Array
ret = []
hash.each {|v| ret << check_xsd(v, elements, ename, xsd) }
ret
else
check_type(hash) do
type = get_xsd_path(xsd, elements)
type['type'] unless type.nil?
end
end
end
# Get xsd path value
#
# @param xsd [Hash] XSD information
# @param elements [Array] Path to get
#
# @return [Hash] Path information
def get_xsd_path(xsd, elements)
return unless elements
element = elements.shift
# Return nil, because is an empty complexType
return unless element
element = [xsd].flatten.find do |v|
v['name'] == element || v['ref'] == element
end
# Return nil, because element was not find in XSD
return unless element
if element.keys.include?('complexType') && !elements.empty?
if element['complexType']['all']
element = element['complexType']['all']['element']
else
element = element['complexType']['sequence']['element']
end
get_xsd_path(element, elements)
else
element
end
end
# CHeck if current element is an array
#
# @param xsd [Hash] XSD information
# @param elements [Array] Path to check
#
# @return [Boolean] True if it's an array, false otherwise
def is_array?(xsd, elements)
max = get_xsd_path(xsd, elements)
max = max['maxOccurs'] if max
max == 'unbounded' || max.to_i > 1
end
# Check XSD type for especific value
#
# @param value [Object] Value to check
#
# @return [Object] nil if the type is not correct, value otherwise
def check_type(value)
type = yield if block_given?
# If there is no type, return current value
return value unless type
types = %w[string decimal integer boolean date time]
type = type.split(':')[1]
if types.include?(type)
# If the current type is different, return string
# because this value doesn't respect the type
if (value.is_a? Hash) || (value.is_a? Array)
''
else
value
end
else
value
end
end
end
def OpenNebulaHelper.rname_to_id(name, poolname)

View File

@ -91,28 +91,19 @@ class AcctHelper < OpenNebulaHelper::OneHelper
:format => String
}
XML = {
:name => "xml",
:short => "-x",
:large => "--xml",
:description => "Show the resource in xml format"
}
JSON = {
:name => "json",
:short => "-j",
:large => "--json",
:description => "Show the resource in json format"
}
SPLIT={
:name => "split",
:large => "--split",
:description => "Split the output in a table for each VM"
}
ACCT_OPTIONS = [START_TIME_ACCT, END_TIME_ACCT, USERFILTER, GROUP, HOST, XPATH, XML, JSON, SPLIT]
SHOWBACK_OPTIONS = [START_TIME_SHOWBACK, END_TIME_SHOWBACK, USERFILTER, GROUP, XML, JSON]
ACCT_OPTIONS = [START_TIME_ACCT, END_TIME_ACCT, USERFILTER, GROUP, HOST, XPATH, SPLIT]
SHOWBACK_OPTIONS = [START_TIME_SHOWBACK, END_TIME_SHOWBACK, USERFILTER, GROUP]
ACCT_OPTIONS << OpenNebulaHelper::XML
ACCT_OPTIONS << OpenNebulaHelper::JSON
SHOWBACK_OPTIONS += OpenNebulaHelper::FORMAT
ACCT_TABLE = CLIHelper::ShowTable.new(self.table_conf("oneacct.yaml"), nil) do
column :UID, "User ID", :size=>4 do |d|

View File

@ -74,6 +74,8 @@ class OneFlowHelper < OpenNebulaHelper::OneHelper
if CloudClient.is_error?(response)
[response.code.to_i, response.to_s]
elsif options[:yaml]
[0, JSON.parse(response.body).to_yaml(:indent => 4)]
else
array_list = JSON.parse(response.body)
array_list = array_list['DOCUMENT_POOL']['DOCUMENT']
@ -93,6 +95,8 @@ class OneFlowHelper < OpenNebulaHelper::OneHelper
else
[0, JSON.pretty_generate(array_list)]
end
elsif options[:yaml]
[0, array_list.to_yaml(:indent => 4)]
else
format_service_pool.show(array_list)
@ -139,6 +143,8 @@ class OneFlowHelper < OpenNebulaHelper::OneHelper
else
if options[:json]
[0, response.body]
elsif options[:yaml]
[0, JSON.parse(response.body).to_yaml(:indent => 4)]
else
str_h1 = '%-80s'
document = JSON.parse(response.body)['DOCUMENT']

View File

@ -73,6 +73,8 @@ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper
else
if options[:json]
[0, response.body]
elsif options[:yaml]
[0, JSON.parse(response.body).to_yaml(:indent => 4)]
else
documents = JSON.parse(response.body)['DOCUMENT_POOL']
format_service_template_pool.show(documents['DOCUMENT'])
@ -120,6 +122,8 @@ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper
else
if options[:json]
[0, response.body]
elsif options[:yaml]
[0, JSON.parse(response.body).to_yaml(:indent => 4)]
else
str = '%-20s: %-20s'
str_h1 = '%-80s'

View File

@ -274,6 +274,10 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
if options.key? :xml
list.map {|e| to_xml(e) }
elsif options.key? :json
puts JSON.pretty_generate(list)
elsif options.key? :yaml
puts list.to_yaml(:indent => 4)
else
format_pool.show(list, options)
end
@ -281,7 +285,7 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
0
end
def show(provision_id, xml)
def show(provision_id, options)
provision = OneProvision::Provision.new(provision_id)
provision.refresh
@ -305,8 +309,12 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
ret[r] = obj_ids
end
if xml
if options.key? :xml
to_xml(ret)
elsif options.key? :json
puts JSON.pretty_generate(ret)
elsif options.key? :yaml
puts ret.to_yaml(:indent => 4)
else
format_resource(ret)
end

View File

@ -103,7 +103,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :list, list_desc, :options => [CLIHelper::OPTIONS,
OpenNebulaHelper::XML,
OpenNebulaHelper::FORMAT,
OpenNebulaHelper::DESCRIBE] do
helper.list_pool(options)
end

View File

@ -54,7 +54,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -119,7 +119,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, :clusterid,
:options => [OpenNebulaHelper::XML, OpenNebulaHelper::DECRYPT] do
:options => [OpenNebulaHelper::FORMAT, OpenNebulaHelper::DECRYPT] do
helper.show_resource(args[0], options)
end

View File

@ -55,7 +55,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -161,7 +161,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, :datastoreid,
:options => [OpenNebulaHelper::XML, OpenNebulaHelper::DECRYPT] do
:options => [OpenNebulaHelper::FORMAT, OpenNebulaHelper::DECRYPT] do
helper.show_resource(args[0], options)
end

View File

@ -113,7 +113,7 @@ CommandParser::CmdParser.new(ARGV) do
List the available services
EOT
command :list, list_desc, :options => [Service::JSON_FORMAT, DONE] do
command :list, list_desc, :options => OpenNebulaHelper::FORMAT + [DONE] do
helper.list_service_pool(helper.client(options), options)
end
@ -137,7 +137,10 @@ CommandParser::CmdParser.new(ARGV) do
Show detailed information of a given service
EOT
command :show, show_desc, :service_id, :options => Service::JSON_FORMAT do
command :show,
show_desc,
:service_id,
:options => OpenNebulaHelper::FORMAT do
helper.format_resource(helper.client(options), args[0], options)
end

View File

@ -113,7 +113,7 @@ CommandParser::CmdParser.new(ARGV) do
List the available Service Templates
EOT
command :list, list_desc, :options => Service::JSON_FORMAT do
command :list, list_desc, :options => OpenNebulaHelper::FORMAT do
helper.list_service_template_pool(helper.client(options), options)
end
@ -141,7 +141,10 @@ CommandParser::CmdParser.new(ARGV) do
Show detailed information of a given Service Template
EOT
command :show, show_desc, :templateid, :options => Service::JSON_FORMAT do
command :show,
show_desc,
:templateid,
:options => OpenNebulaHelper::FORMAT do
helper.format_resource(helper.client(options), args[0], options)
end

View File

@ -54,7 +54,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -166,7 +166,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, [:groupid, nil],
:options => OpenNebulaHelper::XML do
:options => OpenNebulaHelper::FORMAT do
group = args[0] || OpenNebula::Group::SELF
helper.show_resource(group, options)
end

View File

@ -134,7 +134,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -228,7 +228,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, :hookid,
:options => [OpenNebulaHelper::XML, OpenNebulaHelper::EXTENDED,
:options => [OpenNebulaHelper::FORMAT, OpenNebulaHelper::EXTENDED,
EXECUTION] do
helper.show_resource(args[0], options)
end

View File

@ -283,7 +283,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, :hostid,
:options => [OpenNebulaHelper::XML, OpenNebulaHelper::DECRYPT] do
:options => [OpenNebulaHelper::FORMAT, OpenNebulaHelper::DECRYPT] do
helper.show_resource(args[0], options)
end

View File

@ -79,7 +79,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -390,7 +390,7 @@ CommandParser::CmdParser.new(ARGV) do
Shows information for the given Image
EOT
command :show, show_desc, :imageid, :options => OpenNebulaHelper::XML do
command :show, show_desc, :imageid, :options => OpenNebulaHelper::FORMAT do
helper.show_resource(args[0], options)
end

View File

@ -54,7 +54,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -154,7 +154,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc,
:marketplaceid, :options => OpenNebulaHelper::XML do
:marketplaceid, :options => OpenNebulaHelper::FORMAT do
helper.show_resource(args[0], options)
end

View File

@ -89,7 +89,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -300,7 +300,7 @@ CommandParser::CmdParser.new(ARGV) do
Shows information for the given marketplace app
EOT
command :show, show_desc, :appid, :options => OpenNebulaHelper::XML do
command :show, show_desc, :appid, :options => OpenNebulaHelper::FORMAT do
helper.show_resource(args[0], options)
end

View File

@ -327,7 +327,7 @@ CommandParser::CmdParser.new(ARGV) do
provision_list_desc,
:options => CommandParser::OPTIONS +
CLIHelper::OPTIONS +
[OpenNebulaHelper::XML] do
[OpenNebulaHelper::FORMAT] do
helper.list(options)
end
@ -340,8 +340,8 @@ CommandParser::CmdParser.new(ARGV) do
command :show,
provision_show_desc,
:provisionid,
:options => CommandParser::OPTIONS + [OpenNebulaHelper::XML] do
helper.show(args[0], (options.key? :xml))
:options => CommandParser::OPTIONS + OpenNebulaHelper::FORMAT do
helper.show(args[0], options)
end
###

View File

@ -54,7 +54,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -221,7 +221,10 @@ CommandParser::CmdParser.new(ARGV) do
Shows information for the given Security Group
EOT
command :show, show_desc, :secgroupid, :options => OpenNebulaHelper::XML do
command :show,
show_desc,
:secgroupid,
:options => OpenNebulaHelper::FORMAT do
helper.show_resource(args[0], options)
end
end

View File

@ -92,18 +92,20 @@ CommandParser::CmdParser.new(ARGV) do
pool = OpenNebula::VirtualMachinePool.new(helper.client)
if options[:json] || options[:xml]
if options[:json] || options[:xml] || options[:yaml]
xml_str = pool.showback_xml(filter_flag, common_opts)
if OpenNebula.is_error?(xml_str)
puts xml_str.message
exit(-1)
end
if options[:json]
xmldoc = XMLElement.new
xmldoc.initialize_xml(xml_str, 'SHOWBACK_RECORDS')
if options[:json]
puts JSON.pretty_generate(xmldoc.to_hash)
elsif options[:yaml]
puts xmldoc.to_hash.to_yaml(:indent => 4)
elsif options[:xml]
puts xml_str
end

View File

@ -79,7 +79,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -366,7 +366,8 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, :templateid,
:options => [OpenNebulaHelper::XML, OneTemplateHelper::EXTENDED] do
:options => [OpenNebulaHelper::FORMAT,
OneTemplateHelper::EXTENDED] do
helper.show_resource(args[0], options)
end

View File

@ -69,7 +69,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -559,7 +559,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, [:userid, nil],
:options => OpenNebulaHelper::XML do
:options => OpenNebulaHelper::FORMAT do
user = args[0] || OpenNebula::User::SELF
helper.show_resource(user, options)
end

View File

@ -54,7 +54,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -297,7 +297,7 @@ CommandParser::CmdParser.new(ARGV) do
Shows information for the given VDC
EOT
command :show, show_desc, :vdcid, :options => OpenNebulaHelper::XML do
command :show, show_desc, :vdcid, :options => OpenNebulaHelper::FORMAT do
helper.show_resource(args[0], options)
end
end

View File

@ -1152,7 +1152,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, :vmid,
:options => [OpenNebulaHelper::XML,
:options => [OpenNebulaHelper::FORMAT,
OpenNebulaHelper::DECRYPT,
OneVMHelper::ALL_TEMPLATE] do
helper.show_resource(args[0], options)

View File

@ -78,7 +78,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -148,7 +148,10 @@ CommandParser::CmdParser.new(ARGV) do
Shows information for the given VM Group
EOT
command :show, show_desc, :vmgroupid, :options => OpenNebulaHelper::XML do
command :show,
show_desc,
:vmgroupid,
:options => OpenNebulaHelper::FORMAT do
helper.show_resource(args[0], options)
end

View File

@ -320,7 +320,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, :vnetid,
:options => [OpenNebulaHelper::XML,
:options => [OpenNebulaHelper::FORMAT,
OpenNebulaHelper::DECRYPT,
OneVNetHelper::SHOW_AR] do
helper.show_resource(args[0], options)

View File

@ -79,7 +79,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -313,7 +313,8 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, :templateid,
:options => [OpenNebulaHelper::XML, OneTemplateHelper::EXTENDED] do
:options => [OpenNebulaHelper::FORMAT,
OneTemplateHelper::EXTENDED] do
helper.show_resource(args[0], options)
end

View File

@ -80,7 +80,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -339,7 +339,7 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :show, show_desc, :vrouterid,
:options => [OpenNebulaHelper::XML, OneVMHelper::ALL_TEMPLATE] do
:options => [OpenNebulaHelper::FORMAT, OneVMHelper::ALL_TEMPLATE] do
helper.show_resource(args[0], options)
end

View File

@ -69,7 +69,7 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
@ -208,7 +208,7 @@ CommandParser::CmdParser.new(ARGV) do
Shows information for the given Zone
EOT
command :show, show_desc, :zoneid, :options => OpenNebulaHelper::XML do
command :show, show_desc, :zoneid, :options => OpenNebulaHelper::FORMAT do
helper.show_resource(args[0], options)
end