lost and found ( for me ? )

Ubuntu 11.04 : how to use qemu-monitor command through virsh command

You may sometimes want to use qemu-monitor command through virsh.
Here’s an explanation of how to use qemu-monitor command.

Seen from the man manual of virsh , using qemu-monitor-command w/ virsh is discouraged.
# man virsh
QEMU-SPECIFIC COMMANDS
      NOTE: Use of the following commands is strongly discouraged.  They can
      cause libvirt to become confused and do the wrong thing on subsequent
      operations.  Once you have used this command, please do not report
      problems to the libvirt developers; the reports will be ignored.

      qemu-monitor-command domain command optional --hmp
          Send an arbitrary monitor command command to domain domain through
          the qemu monitor.  The results of the command will be printed on
          stdout.  If --hmp is passed, the command is considered to be a
          human monitor command and libvirt will automatically convert it
          into QMP if needed.  In that case the result will also be converted
          back from QMP.


[ How to use ]

start a VM (SL6-vm1)
# virsh start SL6-vm1

# LANG=C virsh list --all | grep running
21 SL6-vm1              running


usage : virsh qemu-monitor-command –hmp domain ‘commnad’

About qemu-monitor command , please see http://en.wikibooks.org/wiki/QEMU/Monitor ,
Or you can check what kind of commands you can use like this:
# virsh qemu-monitor-command --hmp SL6-vm1 'help'
# virsh qemu-monitor-command --hmp SL6-vm1 'info'


show network info of SL6-vm1
# virsh qemu-monitor-command --hmp SL6-vm1 'info network'
Devices not on any VLAN:
 hostnet0: fd=19 peer=net0
 net0: model=virtio-net-pci,macaddr=52:54:00:11:18:f1 peer=hostnet0


You can also use qemu-monitor command by stopping libvirt-bin and then connecting to a monitor socket with netcat. However when you stop libvrit-bin , you will not use virsh command , so I would not recommend this way.
# /etc/init.d/libvirt-bin stop

# LANG=C virsh start SL6-vm1
error: unable to connect to '/var/run/libvirt/libvirt-sock', libvirtd may need to be started: No such file or directory
error: failed to connect to the hypervisor

# /etc/init.d/libvirt-bin start

# LANG=C virsh start SL6-vm1
Domain SL6-vm1 started

# /etc/init.d/libvirt-bin stop

# nc -U /var/lib/libvirt/qemu/SL6-vm1.monitor
QEMU 0.14.0 monitor - type 'help' for more information
(qemu) info network
info network
Devices not on any VLAN:
 hostnet0: fd=18 peer=net0
 net0: model=virtio-net-pci,macaddr=52:54:00:11:18:f1 peer=hostnet0
(qemu)

# LANG=C virsh list --all
error: unable to connect to '/var/run/libvirt/libvirt-sock', libvirtd may need to be started: No such file or directory
error: failed to connect to the hypervisor

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.