mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
cpu-parse: Move json output to new script
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
58a1ad721f
commit
56d496d926
@ -244,13 +244,43 @@ def output_xml(data, filename):
|
||||
f.write("</cpudata>\n")
|
||||
|
||||
|
||||
def output_json(data, filename):
|
||||
replies = list()
|
||||
for reply in data["model"]:
|
||||
if "QMP" in reply:
|
||||
continue
|
||||
if "timestamp" in reply:
|
||||
continue
|
||||
if "return" in reply and not reply["return"]:
|
||||
continue
|
||||
replies.append(reply)
|
||||
|
||||
if not replies:
|
||||
return
|
||||
|
||||
if "model-expansion" not in [reply.get("id") for reply in replies]:
|
||||
exit(
|
||||
"Error: Missing query-cpu-model-expansion reply in "
|
||||
"{}".format(filename))
|
||||
|
||||
print(filename)
|
||||
with open(filename, "wt") as f:
|
||||
for reply in replies:
|
||||
if reply is not replies[0]:
|
||||
f.write("\n")
|
||||
json.dump(reply, f, indent=2)
|
||||
f.write("\n")
|
||||
|
||||
|
||||
def parse(args):
|
||||
data = json.load(sys.stdin)
|
||||
|
||||
filename = parse_filename(data)
|
||||
filename_xml = "{}.xml".format(filename)
|
||||
filename_json = "{}.json".format(filename)
|
||||
|
||||
output_xml(data, filename_xml)
|
||||
output_json(data, filename_json)
|
||||
|
||||
os.environ["CPU_GATHER_PY"] = "true"
|
||||
os.environ["model"] = data["name"]
|
||||
|
@ -7,23 +7,7 @@ fi
|
||||
|
||||
data=`cat`
|
||||
|
||||
json()
|
||||
{
|
||||
first=true
|
||||
sed -ne '/{"QMP".*/d;
|
||||
/{"return": {}}/d;
|
||||
/{"timestamp":.*/d;
|
||||
/^{/p' <<<"$data" | \
|
||||
while read; do
|
||||
$first || echo
|
||||
first=false
|
||||
$(dirname $0)/cpu-reformat.py <<<"$REPLY"
|
||||
done
|
||||
}
|
||||
|
||||
json <<<"$data" >$fname.json
|
||||
if [[ -s $fname.json ]]; then
|
||||
echo $fname.json
|
||||
if ! grep -q model-expansion $fname.json; then
|
||||
echo "Missing query-cpu-model-expansion reply in $name.json" >&2
|
||||
exit 1
|
||||
|
@ -1,9 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import json
|
||||
|
||||
dec = json.JSONDecoder()
|
||||
data, pos = dec.raw_decode(sys.stdin.read())
|
||||
json.dump(data, sys.stdout, indent=2, separators=(',', ': '))
|
||||
print("")
|
Loading…
x
Reference in New Issue
Block a user