Added a --replace option to virt-image which allows it to replace an existing machine if it is current running or defined
On Thu, Jun 26, 2008 at 05:53:51PM +0000, David Lutterkort wrote:
> On Thu, 2008-06-26 at 12:47 -0400, Bryan M. Kearney @redhat.com wrote:
> > # HG changeset patch
> > # User "Bryan M. Kearney <bkearney@redhat.com>"
> > # Date 1214497967 14400
> > # Node ID efba908eb79ad0bf2805c27f784de92578207f1b
> > # Parent 63aca2dbb3154a65505b1ccef080a8887742cef5
> > Added a --replace option to virt-image which allows it to replace an existing machine if it is current running or defined
>
> Couldn't the same be achieved with a small shell script wrapper around
> the virt-image invocation, something like
>
> virsh list | grep -q $NAME && virsh destroy $NAME
> virt-image $IMAGE_XML
>
> It seems that this patch addresses a very specific use case (repeatedly
> starting a VM based on the same image.xml)
>
> Other than that it might be redundant though, the patch looks fine.
I thought it was too, however, I realize now that the reason it can';t
simply 'redefine' the existing VMs config is that it has the same name
but different (randomly generated UUID), causing a clash and error. So
it really is useful to explicitly re-define.
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
06-26-2008, 06:42 PM
"Daniel P. Berrange"
Added a --replace option to virt-image which allows it to replace an existing machine if it is current running or defined
On Thu, Jun 26, 2008 at 12:47:27PM -0400, "Bryan M. Kearney <bkearney@redhat.com>"@redhat.com wrote:
> + if vm.ID() == -1:
> + logging.info("Removing old definition for image %s" %(self.name))
> + vm.undefine()
> + else:
> + logging.info("Destroying image %s" %(self.name))
> + vm.destroy()
You don't want this to be an either / or conditional. If the VM exists
you should *always* attempt to undefine it - a running VM may or may
not have a config file
So you want something closer to
if vm.ID() != -1:
vm.destroy()
try:
vm.undefine()
except:
pass
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools