mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-25 06:03:36 +03:00
Feature #1287: Add --xpath option
This commit is contained in:
parent
8176f58401
commit
f6ca62ea36
@ -224,6 +224,11 @@ opts = OptionParser.new do |opts|
|
|||||||
options[:host]=ext
|
options[:host]=ext
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on("--xpath expression", String,
|
||||||
|
"Xpath expression to filter the results. For example: oneacct --xpath 'HISTORY[ETIME>0]'" ) do |ext|
|
||||||
|
options[:xpath]=ext
|
||||||
|
end
|
||||||
|
|
||||||
opts.on("-j", "--json",
|
opts.on("-j", "--json",
|
||||||
"Output in json format" ) do |ext|
|
"Output in json format" ) do |ext|
|
||||||
options[:format]=:json
|
options[:format]=:json
|
||||||
@ -286,6 +291,10 @@ end
|
|||||||
xmldoc = XMLElement.new
|
xmldoc = XMLElement.new
|
||||||
xmldoc.initialize_xml(xml_str, 'HISTORY_RECORDS')
|
xmldoc.initialize_xml(xml_str, 'HISTORY_RECORDS')
|
||||||
|
|
||||||
|
xpath = nil
|
||||||
|
hid = nil
|
||||||
|
gid = nil
|
||||||
|
|
||||||
if options[:host]
|
if options[:host]
|
||||||
rc = OpenNebulaHelper.rname_to_id(options[:host], "HOST")
|
rc = OpenNebulaHelper.rname_to_id(options[:host], "HOST")
|
||||||
|
|
||||||
@ -295,8 +304,6 @@ if options[:host]
|
|||||||
puts rc[1]
|
puts rc[1]
|
||||||
exit -1
|
exit -1
|
||||||
end
|
end
|
||||||
|
|
||||||
xmldoc = redo_xmldoc(xmldoc, "HISTORY[HID=#{hid}]")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:group]
|
if options[:group]
|
||||||
@ -308,10 +315,24 @@ if options[:group]
|
|||||||
puts rc[1]
|
puts rc[1]
|
||||||
exit -1
|
exit -1
|
||||||
end
|
end
|
||||||
|
|
||||||
xmldoc = redo_xmldoc(xmldoc, "HISTORY[VM/GID=#{gid}]")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if options[:host] && options[:group]
|
||||||
|
xpath = "HISTORY[VM/GID=#{gid} and HID=#{hid}]"
|
||||||
|
elsif options[:host]
|
||||||
|
xpath = "HISTORY[HID=#{hid}]"
|
||||||
|
elsif options[:group]
|
||||||
|
xpath = "HISTORY[VM/GID=#{gid}]"
|
||||||
|
end
|
||||||
|
|
||||||
|
xmldoc = redo_xmldoc(xmldoc, xpath) if !xpath.nil?
|
||||||
|
|
||||||
|
|
||||||
|
if options[:xpath]
|
||||||
|
xmldoc = redo_xmldoc(xmldoc, options[:xpath])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
case options[:format]
|
case options[:format]
|
||||||
when :table
|
when :table
|
||||||
if ( time_start != -1 or time_end != -1 )
|
if ( time_start != -1 or time_end != -1 )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user