[libvirt] Create a copy of a Domain

Hello All, I am trying to create a Domain/VM copy program. In this program, a completely new domain should be created from a source domain. What I tried so far is this: 1. Get the XML Desc of the source Domain using "virDomainGetXMLDesc". 2. Get the Hypervisor Object for the source Domain using "virDomainGetConnect". 3. Create a new Domain using the "virDomainCreateXML" method. After doing this, I get the following error: libvirt.libvirtError: POST operation failed: xend_post: error from xen daemon: (xend.err "Error creating domain: VM name already in use by domain 4") First of all, Is this the correct way to create a new Domain as a copy of the original?? If not, please tell me how should I go about this?? Thanks and Regards Sagar Barve

Hello, Am Donnerstag 10 Juni 2010 10:28:15 schrieb IKI-サガル バルウェ:
1. Get the XML Desc of the source Domain using "virDomainGetXMLDesc". 2. Get the Hypervisor Object for the source Domain using "virDomainGetConnect". 3. Create a new Domain using the "virDomainCreateXML" method.
After doing this, I get the following error:
libvirt.libvirtError: POST operation failed: xend_post: error from xen daemon: (xend.err "Error creating domain: VM name already in use by domain 4")
I think you must at least change the UUID (/domain/uuid) and name (/domain/name) in the XML description. Very like you also need to duplicate the used disk images and update their paths (/domain/devices/disk/source/@file) accordingly, unless you really want your domians to share them. BYtE Philipp Hahn -- Philipp Hahn Open Source Software Engineer hahn@univention.de Univention GmbH Linux for Your Business fon: +49 421 22 232- 0 Mary-Somerville-Str.1 28359 Bremen fax: +49 421 22 232-99 http://www.univention.de Besuchen Sie uns auf dem LinuxTag in Berlin vom 9. - 12. Juni Stand 110 in Halle 7.2A

On Thu, Jun 10, 2010 at 10:58:54AM +0200, Philipp Hahn wrote:
Hello,
Am Donnerstag 10 Juni 2010 10:28:15 schrieb IKI-サガル バルウェ:
1. Get the XML Desc of the source Domain using "virDomainGetXMLDesc". 2. Get the Hypervisor Object for the source Domain using "virDomainGetConnect". 3. Create a new Domain using the "virDomainCreateXML" method.
After doing this, I get the following error:
libvirt.libvirtError: POST operation failed: xend_post: error from xen daemon: (xend.err "Error creating domain: VM name already in use by domain 4")
I think you must at least change the UUID (/domain/uuid) and name (/domain/name) in the XML description. Very like you also need to duplicate the used disk images and update their paths (/domain/devices/disk/source/@file) accordingly, unless you really want your domians to share them.
Better yet use the 'virt-clone' command line tool, or virt-manager's clone capability Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Thanks Daniel,
I think you must at least change the UUID (/domain/uuid) and name (/domain/name) in the XML description. Very like you also need to duplicate the used disk images and update their paths (/domain/devices/disk/source/@file) accordingly, unless you really want your domians to share them.
I will definately try this out. As for changing the UUID, I think the new value has to be unique in terms of all other Domains present. I am right??
Better yet use the 'virt-clone' command line tool, or virt-manager's clone capability
As for using 'virt-clone', is there a way to implement this using python bindings for libvirt?? I want to provide the functionality in a python script. I thought of doing this by directly executing the command line 'virt-clone' command from my python script and check wheather it executes successfully or not. We can do this by the 'os.system' function in python. Thanks and Regards Sagar Barve ----- Original Message ----- From: "Daniel P. Berrange" <berrange@redhat.com> To: "Philipp Hahn" <hahn@univention.de> Cc: <libvir-list@redhat.com> Sent: Thursday, June 10, 2010 7:45 PM Subject: Re: [libvirt] Create a copy of a Domain
On Thu, Jun 10, 2010 at 10:58:54AM +0200, Philipp Hahn wrote:
Hello,
Am Donnerstag 10 Juni 2010 10:28:15 schrieb IKI-サガル バルウェ:
1. Get the XML Desc of the source Domain using "virDomainGetXMLDesc". 2. Get the Hypervisor Object for the source Domain using "virDomainGetConnect". 3. Create a new Domain using the "virDomainCreateXML" method.
After doing this, I get the following error:
libvirt.libvirtError: POST operation failed: xend_post: error from xen daemon: (xend.err "Error creating domain: VM name already in use by domain 4")
I think you must at least change the UUID (/domain/uuid) and name (/domain/name) in the XML description. Very like you also need to duplicate the used disk images and update their paths (/domain/devices/disk/source/@file) accordingly, unless you really want your domians to share them.
Better yet use the 'virt-clone' command line tool, or virt-manager's clone capability
Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Fri, Jun 11, 2010 at 10:22:18AM +0900, IKI-サガル バルウェ wrote:
Thanks Daniel,
I think you must at least change the UUID (/domain/uuid) and name (/domain/name) in the XML description. Very like you also need to duplicate the used disk images and update their paths (/domain/devices/disk/source/@file) accordingly, unless you really want your domians to share them.
I will definately try this out. As for changing the UUID, I think the new value has to be unique in terms of all other Domains present. I am right??
Better yet use the 'virt-clone' command line tool, or virt-manager's clone capability
As for using 'virt-clone', is there a way to implement this using python bindings for libvirt?? I want to provide the functionality in a python script. I thought of doing this by directly executing the command line 'virt-clone' command from my python script and check wheather it executes successfully or not. We can do this by the 'os.system' function in python.
virt-clone is written in python itself and most of its code is in a set of library modules, so you can call them directly if neccessary. Or just write the equivalent code yourself using libvirt python, since there isn't much too it Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Thanks Daniel,
virt-clone is written in python itself and most of its code is in a set of library modules, so you can call them directly if neccessary. Or just write the equivalent code yourself using libvirt python, since there isn't much too it I will take a look into the virt-clone python code.
As for your previous suggestion:
I think you must at least change the UUID (/domain/uuid) and name (/domain/name) in the XML description. Very like you also need to duplicate the used disk images and update their paths (/domain/devices/disk/source/@file) accordingly, unless you really want your domians to share them.
I tried this, i.e. assigned a new uuid, name and also created a new disk image file and assigned the new path to the XML description. Then tried to create a new VM using the "virDomainCreateXML" method passing the updated XML Desc. But I get the following error: error : POST operation failed: xend_post: error from xen daemon: (xend.err "Error creating domain: Boot loader didn't return any data!") I searched about this error, and could not find anything I could understand. Please help me with this. Thanks and Regards Sagar Barve ----- Original Message ----- From: "Daniel P. Berrange" <berrange@redhat.com> To: "IKI-サガル バルウェ" <sagar.barve@ikic.co.jp> Cc: "Philipp Hahn" <hahn@univention.de>; <libvir-list@redhat.com> Sent: Friday, June 11, 2010 6:32 PM Subject: Re: [libvirt] Create a copy of a Domain
On Fri, Jun 11, 2010 at 10:22:18AM +0900, IKI-サガル バルウェ wrote:
Thanks Daniel,
I think you must at least change the UUID (/domain/uuid) and name (/domain/name) in the XML description. Very like you also need to duplicate the used disk images and update their paths (/domain/devices/disk/source/@file) accordingly, unless you really want your domians to share them.
I will definately try this out. As for changing the UUID, I think the new value has to be unique in terms of all other Domains present. I am right??
Better yet use the 'virt-clone' command line tool, or virt-manager's clone capability
As for using 'virt-clone', is there a way to implement this using python bindings for libvirt?? I want to provide the functionality in a python script. I thought of doing this by directly executing the command line 'virt-clone' command from my python script and check wheather it executes successfully or not. We can do this by the 'os.system' function in python.
virt-clone is written in python itself and most of its code is in a set of library modules, so you can call them directly if neccessary. Or just write the equivalent code yourself using libvirt python, since there isn't much too it
Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (3)
-
Daniel P. Berrange
-
IKI-サガル バルウェ
-
Philipp Hahn