From f6ca62ea3618d2c55911e860069ce7d67bc25cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 1 Jun 2012 18:23:02 +0200 Subject: [PATCH] Feature #1287: Add --xpath option --- src/cli/oneacct | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/cli/oneacct b/src/cli/oneacct index c5e7d46594..0b93f57116 100755 --- a/src/cli/oneacct +++ b/src/cli/oneacct @@ -223,6 +223,11 @@ opts = OptionParser.new do |opts| "Host id to filter the results" ) do |ext| options[:host]=ext 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", "Output in json format" ) do |ext| @@ -286,6 +291,10 @@ end xmldoc = XMLElement.new xmldoc.initialize_xml(xml_str, 'HISTORY_RECORDS') +xpath = nil +hid = nil +gid = nil + if options[:host] rc = OpenNebulaHelper.rname_to_id(options[:host], "HOST") @@ -295,8 +304,6 @@ if options[:host] puts rc[1] exit -1 end - - xmldoc = redo_xmldoc(xmldoc, "HISTORY[HID=#{hid}]") end if options[:group] @@ -308,10 +315,24 @@ if options[:group] puts rc[1] exit -1 end - - xmldoc = redo_xmldoc(xmldoc, "HISTORY[VM/GID=#{gid}]") 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] when :table if ( time_start != -1 or time_end != -1 )