[libvirt-users] Updating Multiple VM Guests?

Hi, The libvirt.org FAQ says that "virsh edit" is the recommended way of updating the libvirt xml. If a change has to be made to many VMs "virsh edit" is tedious, time-consuming and likely to be prone to careless errors. Is there a command line approach to updating multiple VMs? Thanks, Ken

On 11/10/2010 11:59 AM, Kenneth Stailey wrote:
Hi,
The libvirt.org FAQ says that "virsh edit" is the recommended way of updating the libvirt xml.
If a change has to be made to many VMs "virsh edit" is tedious, time-consuming and likely to be prone to careless errors.
Is there a command line approach to updating multiple VMs?
How about: for g in guest1 guest2 guest3 guest4; do virsh dumpxml --inactive $g >/tmp/g.xml # do whatever sed/etc commands you want here virsh define /tmp/g.xml done (or something like that, anyway :-)

--- On Wed, 11/10/10, Laine Stump <laine@laine.org> wrote:
From: Laine Stump <laine@laine.org> Subject: Re: [libvirt-users] Updating Multiple VM Guests? To: libvirt-users@redhat.com Date: Wednesday, November 10, 2010, 12:41 PM On 11/10/2010 11:59 AM, Kenneth Stailey wrote:
Hi,
The libvirt.org FAQ says that "virsh edit" is the recommended way of updating the libvirt xml.
If a change has to be made to many VMs "virsh edit" is tedious, time-consuming and likely to be prone to careless errors.
Is there a command line approach to updating multiple VMs?
How about:
for g in guest1 guest2 guest3 guest4; do virsh dumpxml --inactive $g
/tmp/g.xml # do whatever sed/etc commands you want here virsh define /tmp/g.xml done
(or something like that, anyway :-)
The "sed, etc." is a mistake since XML does not have guaranteed format. I suppose XMLStarlet could be used. http://xmlstar.sourceforge.net/

On 11/10/2010 01:20 PM, Kenneth Stailey wrote:
--- On Wed, 11/10/10, Laine Stump<laine@laine.org> wrote:
From: Laine Stump<laine@laine.org> Subject: Re: [libvirt-users] Updating Multiple VM Guests? To: libvirt-users@redhat.com Date: Wednesday, November 10, 2010, 12:41 PM On 11/10/2010 11:59 AM, Kenneth Stailey wrote:
Hi,
The libvirt.org FAQ says that "virsh edit" is the recommended way of updating the libvirt xml. If a change has to be made to many VMs "virsh edit" is tedious, time-consuming and likely to be prone to careless errors. Is there a command line approach to updating multiple VMs?
How about:
for g in guest1 guest2 guest3 guest4; do virsh dumpxml --inactive $g
/tmp/g.xml # do whatever sed/etc commands you want here virsh define /tmp/g.xml done
(or something like that, anyway :-) The "sed, etc." is a mistake since XML does not have guaranteed format.
I suppose XMLStarlet could be used.
Yeah. sed is just my general purpose "replacement for editing by hand" token ;-) Something that is xml-aware would obviously be a much better choice.

--- On Wed, 11/10/10, Laine Stump <laine@laine.org> wrote:
From: Laine Stump <laine@laine.org> Subject: Re: [libvirt-users] Updating Multiple VM Guests? To: libvirt-users@redhat.com Date: Wednesday, November 10, 2010, 1:27 PM On 11/10/2010 01:20 PM, Kenneth Stailey wrote:
--- On Wed, 11/10/10, Laine Stump<laine@laine.org>
wrote:
From: Laine Stump<laine@laine.org> Subject: Re: [libvirt-users] Updating Multiple VM
To: libvirt-users@redhat.com Date: Wednesday, November 10, 2010, 12:41 PM On 11/10/2010 11:59 AM, Kenneth Stailey wrote:
Hi,
The libvirt.org FAQ says that "virsh edit" is
Guests? the
recommended way of updating the libvirt xml.
If a change has to be made to many VMs "virsh edit" is tedious, time-consuming and likely to be prone to careless errors. Is there a command line approach to updating multiple VMs?
How about:
for g in guest1 guest2 guest3 guest4; do virsh dumpxml --inactive $g
/tmp/g.xml # do whatever sed/etc commands you want here virsh define /tmp/g.xml done
(or something like that, anyway :-) The "sed, etc." is a mistake since XML does not have guaranteed format.
I suppose XMLStarlet could be used.
Yeah. sed is just my general purpose "replacement for editing by hand" token ;-)
Something that is xml-aware would obviously be a much better choice.
It's too painful to get right anyway. I just used this: #! /bin/bash # hack to fixup qemu version numbers in libvirt xml if [ `id -un` != root ]; then echo this script only works as root exit 1 fi cd /dev/shm for i in `virsh list --all | awk '/running|shut off/ {print $2}'` do virsh dumpxml $i > $i.xml sed -i.bak -e 's/pc-0.11/pc-0.12/' $i.xml virsh define $i.xml done

----- "Kenneth Stailey" <kstailey@yahoo.com> wrote:
--- On Wed, 11/10/10, Laine Stump <laine@laine.org> wrote:
From: Laine Stump <laine@laine.org> Subject: Re: [libvirt-users] Updating Multiple VM Guests? To: libvirt-users@redhat.com Date: Wednesday, November 10, 2010, 1:27 PM On 11/10/2010 01:20 PM, Kenneth Stailey wrote:
--- On Wed, 11/10/10, Laine Stump<laine@laine.org>
wrote:
From: Laine Stump<laine@laine.org> Subject: Re: [libvirt-users] Updating Multiple VM
To: libvirt-users@redhat.com Date: Wednesday, November 10, 2010, 12:41 PM On 11/10/2010 11:59 AM, Kenneth Stailey wrote:
Hi,
The libvirt.org FAQ says that "virsh edit" is
Guests? the
recommended way of updating the libvirt xml.
If a change has to be made to many VMs "virsh edit" is tedious, time-consuming and likely to be prone to careless errors. Is there a command line approach to updating multiple VMs?
How about:
for g in guest1 guest2 guest3 guest4; do virsh dumpxml --inactive $g
/tmp/g.xml # do whatever sed/etc commands you want here virsh define /tmp/g.xml done
(or something like that, anyway :-) The "sed, etc." is a mistake since XML does not have guaranteed format.
I suppose XMLStarlet could be used.
Yeah. sed is just my general purpose "replacement for editing by hand" token ;-)
Something that is xml-aware would obviously be a much better choice.
It's too painful to get right anyway. I just used this:
#! /bin/bash
# hack to fixup qemu version numbers in libvirt xml
if [ `id -un` != root ]; then echo this script only works as root exit 1 fi
cd /dev/shm
for i in `virsh list --all | awk '/running|shut off/ {print $2}'` do virsh dumpxml $i > $i.xml sed -i.bak -e 's/pc-0.11/pc-0.12/' $i.xml
yep, for case simple like this, sed is good enough to get it done. :-)
virsh define $i.xml done
_______________________________________________ libvirt-users mailing list libvirt-users@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-users

On Wed, Nov 10, 2010 at 10:20:21AM -0800, Kenneth Stailey wrote:
The "sed, etc." is a mistake since XML does not have guaranteed format.
Depends on the complexity. If you are just changing the size of the memory, you could probably do it with rpl; if you are just inserting fixed blocks of text, I'm sure you could manage it with sed. If it gets arbitrarily complex, then you can do arbitrarily complex things in emacs. The question then becomes whether it is worth the time. If the job were big enough (ie thousands of VM's) perhaps yes. If only a dozen or so, then emacs *.xml and manually fixing each is probably the most efficient, albiet boring, thing to do. Oh, and don't forget, emacs has an xml mode. So does vi.

On Wed, Nov 10, 2010 at 08:59:39AM -0800, Kenneth Stailey wrote:
Hi,
The libvirt.org FAQ says that "virsh edit" is the recommended way of updating the libvirt xml.
If a change has to be made to many VMs "virsh edit" is tedious, time-consuming and likely to be prone to careless errors.
Is there a command line approach to updating multiple VMs?
I rather like emacs.

On Wed, Nov 10, 2010 at 01:07:02PM -0500, Dale Amon wrote:
On Wed, Nov 10, 2010 at 08:59:39AM -0800, Kenneth Stailey wrote:
Is there a command line approach to updating multiple VMs?
I rather like emacs.
To expand on what I just said, emacs *.xml opens all the xml config files. Then you can write editing macros in emacs and step through each file pretty quickly. Then you make sure the machines in question are unloaded before you reload the new config and start them. Depending on the editing complexity, you might use sed or rpl to do it via a shell script.
participants (4)
-
Dale Amon
-
Kenneth Stailey
-
Laine Stump
-
Osier