mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Ozones: enable raw JSON output from CLI commands
This commit is contained in:
parent
f44bb4940e
commit
e4b34a7e4e
@ -61,11 +61,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.create_resource(args[0], options)
|
||||
end
|
||||
|
||||
command :show, 'Show information of a particular VDC', :vdcid do
|
||||
command :show, 'Show information of a particular VDC', :vdcid,
|
||||
:options => OZonesHelper::JSON do
|
||||
helper.show_resource(args[0],options)
|
||||
end
|
||||
|
||||
command :list, 'Lists VDCs in the pool' do
|
||||
command :list, 'Lists VDCs in the pool', :options => OZonesHelper::JSON do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
|
@ -71,8 +71,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
onezone show 4 host
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :zoneid, [:resource, nil] do
|
||||
zone=helper.show_resource(args[0],options)[1]
|
||||
command :show, show_desc, :zoneid, [:resource, nil],
|
||||
:options => OZonesHelper::JSON do
|
||||
zone = helper.show_resource(args[0],options)[1]
|
||||
|
||||
#manually print here
|
||||
if options[:json]
|
||||
puts zone
|
||||
end
|
||||
|
||||
if !args[1] then next 0 end
|
||||
|
||||
case args[1]
|
||||
when "host"
|
||||
@ -87,35 +95,41 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
aux_helper = OneTemplateHelper.new
|
||||
when "user"
|
||||
aux_helper = OneUserHelper.new
|
||||
else
|
||||
puts "\n:!: Pool #{args[1]} doesn't exist or is not supported\n\n"
|
||||
next 0
|
||||
else
|
||||
puts "\n:!: Pool #{args[1]} doesn't exist or is not supported\n\n"
|
||||
next 0
|
||||
end
|
||||
|
||||
pool_hash_data = helper.get_resource_pool("zone", zone[:ID], args[1])
|
||||
pool_hash_data = helper.get_resource_pool("zone", args[0], args[1],
|
||||
options)
|
||||
|
||||
if pool_hash_data[0] != 0
|
||||
puts "\nError retrieving information for pool #{args[1]}. Reason: " + pool_hash_data[1] + "\n\n"
|
||||
if pool_hash_data[0] != 0
|
||||
puts "\nError retrieving information for pool #{args[1]}. Reason: " + pool_hash_data[1] + "\n\n"
|
||||
next 0
|
||||
end
|
||||
end
|
||||
|
||||
if !pool_hash_data[1]
|
||||
next 0
|
||||
if !pool_hash_data[1]
|
||||
next 0
|
||||
end
|
||||
|
||||
if options[:json]
|
||||
puts pool_hash_data[1]
|
||||
next 0
|
||||
end
|
||||
|
||||
if pool_hash_data[1].is_a?(Hash)
|
||||
pool_hash_data[1]=[Hash.transform_keys_to_strings(pool_hash_data[1])]
|
||||
else
|
||||
pool_hash_data[1].each{|hash| hash.replace(Hash.transform_keys_to_strings(hash))}
|
||||
else
|
||||
pool_hash_data[1].each{|hash| hash.replace(Hash.transform_keys_to_strings(hash))}
|
||||
end
|
||||
|
||||
table = aux_helper.format_pool(options)
|
||||
table.show(pool_hash_data[1])
|
||||
table.show(pool_hash_data[1])
|
||||
|
||||
0
|
||||
end
|
||||
|
||||
command :list, 'Lists Zones in the pool' do
|
||||
command :list, 'Lists Zones in the pool', :options=>OZonesHelper::JSON do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
|
@ -18,6 +18,15 @@ require 'zona'
|
||||
|
||||
module OZonesHelper
|
||||
|
||||
#Specific ozones CLI options
|
||||
|
||||
JSON={
|
||||
:name => "json",
|
||||
:short => "-j",
|
||||
:large => "--json",
|
||||
:description => "Show the resource in JSON format"
|
||||
}
|
||||
|
||||
class OZHelper
|
||||
def initialize(user=nil, pass=nil, endpoint_str=nil,
|
||||
timeout=nil, debug_flag=true)
|
||||
@ -45,8 +54,13 @@ module OZonesHelper
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
pool=Zona::OZonesJSON.parse_json(rc.body, kind.upcase + "_POOL")
|
||||
format_pool(pool, options)
|
||||
if options[:json]
|
||||
[0, rc.body]
|
||||
else
|
||||
resource_str = kind.upcase + "_POOL"
|
||||
pool=Zona::OZonesJSON.parse_json(rc.body, resource_str)
|
||||
format_pool(pool, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -56,18 +70,26 @@ module OZonesHelper
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
resource=Zona::OZonesJSON.parse_json(rc.body, kind.upcase)
|
||||
format_resource(resource, options)
|
||||
if options[:json]
|
||||
[0, rc.body]
|
||||
else
|
||||
resource=Zona::OZonesJSON.parse_json(rc.body, kind.upcase)
|
||||
format_resource(resource, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_resource_pool(kind, id, pool)
|
||||
def get_resource_pool(kind, id, pool, options)
|
||||
rc = @client.get_resource_pool(kind, id, pool)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
[0 , Zona::OZonesJSON.parse_json(rc.body, pool.upcase+"_POOL")[pool.upcase.to_sym]]
|
||||
if options[:json]
|
||||
[0, rc.body]
|
||||
else
|
||||
[0 , Zona::OZonesJSON.parse_json(rc.body, pool.upcase+"_POOL")[pool.upcase.to_sym]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user