Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair virt_query outputter #655

Open
wants to merge 2 commits into
base: openSUSE/release/3006.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/65841.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restore functionality of virt_query outputter and add support for block devices.
64 changes: 33 additions & 31 deletions salt/output/virt_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,37 @@ def output(data, **kwargs): # pylint: disable=unused-argument
Display output for the salt-run virt.query function
"""
out = ""
for id_ in data["data"]:
out += "{}\n".format(id_)
for vm_ in data["data"][id_]["vm_info"]:
out += " {}\n".format(vm_)
vm_data = data[id_]["vm_info"][vm_]
if "cpu" in vm_data:
out += " CPU: {}\n".format(vm_data["cpu"])
if "mem" in vm_data:
out += " Memory: {}\n".format(vm_data["mem"])
if "state" in vm_data:
out += " State: {}\n".format(vm_data["state"])
if "graphics" in vm_data:
if vm_data["graphics"].get("type", "") == "vnc":
out += " Graphics: vnc - {}:{}\n".format(
id_, vm_data["graphics"]["port"]
)
if "disks" in vm_data:
for disk, d_data in vm_data["disks"].items():
out += " Disk - {}:\n".format(disk)
out += " Size: {}\n".format(d_data["disk size"])
out += " File: {}\n".format(d_data["file"])
out += " File Format: {}\n".format(d_data["file format"])
if "nics" in vm_data:
for mac in vm_data["nics"]:
out += " Nic - {}:\n".format(mac)
out += " Source: {}\n".format(
vm_data["nics"][mac]["source"][
next(iter(vm_data["nics"][mac]["source"].keys()))
]
)
out += " Type: {}\n".format(vm_data["nics"][mac]["type"])
if isinstance(data, dict) and "event" in data:
for id_ in data["event"]["data"]:
out += "{}\n".format(id_)
for vm_ in data["event"]["data"][id_]["vm_info"]:
out += " {}\n".format(vm_)
vm_data = data["event"]["data"][id_]["vm_info"][vm_]
if "cpu" in vm_data:
out += " CPU: {}\n".format(vm_data["cpu"])
if "mem" in vm_data:
out += " Memory: {}\n".format(vm_data["mem"])
if "state" in vm_data:
out += " State: {}\n".format(vm_data["state"])
if "graphics" in vm_data:
if vm_data["graphics"].get("type", "") == "vnc":
out += " Graphics: vnc - {}:{}\n".format(
id_, vm_data["graphics"]["port"]
)
if "disks" in vm_data:
for disk, d_data in vm_data["disks"].items():
out += " Disk - {}:\n".format(disk)
if "disk size" in d_data:
out += " Size: {}\n".format(d_data["disk size"])
out += " File: {}\n".format(d_data["file"])
out += " File Format: {}\n".format(d_data["file format"])
if "nics" in vm_data:
for mac in vm_data["nics"]:
out += " NIC - {}:\n".format(mac)
out += " Source: {}\n".format(
vm_data["nics"][mac]["source"][
next(iter(vm_data["nics"][mac]["source"].keys()))
]
)
out += " Type: {}\n".format(vm_data["nics"][mac]["type"])
return out