Last active
February 7, 2024 14:06
-
-
Save mjf/45435cd86e73ef7bb463d80071b4f8b2 to your computer and use it in GitHub Desktop.
KVM/QEMU/LibVirt HMP/QMP shell functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# KVM/QEMU/LibVirt HMP/QMP shell functions | |
# Copyright (C) 2024 Matous Jan Fialka, <https://mjf.cz/> | |
# Released under the terms of the "MIT" license | |
# Usage: qmp [DOMAIN [COMMAND]] | |
qmp() { | |
case "$#" in | |
('0') | |
virsh list | |
;; | |
('1') | |
virsh qemu-monitor-command $1 '{ | |
"execute": "query-version" | |
}' | | |
jq --indent 4 | |
;; | |
(*) | |
local DOMAIN="$1" | |
shift | |
local QUERY="$( | |
sed '{ | |
s|^|{"| | |
s|$|"}| | |
s|[ \t]\+|,|g | |
s|:|":"|g | |
}' <<< "$@" | |
)" | |
virsh qemu-monitor-command "$DOMAIN" "$QUERY" | | |
jq --indent 4 | |
esac | |
} | |
# Usage: hmp [DOMAIN [COMMAND]] | |
hmp() { | |
case "$#" in | |
('0') | |
virsh list | |
;; | |
('1') | |
virsh qemu-monitor-command "$1" --hmp 'info version' | |
;; | |
(*) | |
local DOMAIN="$1" | |
shift | |
virsh qemu-monitor-command $DOMAIN --hmp "$@" | |
esac | | |
cat -s | |
} | |
# vi:ft=sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment