[libvirt-users] creating a domain

hi, i am a bit confused on how to start an inactive domain using the python bindings, any help would be appreciated. (inactive as in the domain was created with virConnect.defineXML sometime in the past) looks like i have to use virDomain.create, however virDomain.create needs a defined domain xmldesc as a parameter and i am not sure on how to get that i guess if virConnect.create was happening right after virConnect.defineXML i could get the return value of virConnect.defineXML and pass that onto virDomain.create. however, since the domain was created sometime in the past, i am not sure on how to get the domain ptr which virDomain.create needs thanks

On May 9, 2012, at 4:26 PM, John Wayne <m01z04-libvirt@yahoo.com> wrote:
hi,
i am a bit confused on how to start an inactive domain using the python bindings, any help would be appreciated. (inactive as in the domain was created with virConnect.defineXML sometime in the past)
looks like i have to use virDomain.create, however virDomain.create needs a defined domain xmldesc as a parameter and i am not sure on how to get that
i guess if virConnect.create was happening right after virConnect.defineXML i could get the return value of virConnect.defineXML and pass that onto virDomain.create. however, since the domain was created sometime in the past, i am not sure on how to get the domain ptr which virDomain.create needs
thanks
John, I think you are confusing methods. libvirt.virDomain.create() just takes a virDomain object while libvirt.virConnect.createXML() takes an xmldesc. $ python
import libvirt conn = libvirt.open("qemu:///system") dom = conn.lookupByName("my-machine") dom.create()
Should do the trick. -- Doug Goldstein

On 05/09/2012 11:26 PM, John Wayne wrote:
hi,
i am a bit confused on how to start an inactive domain using the python bindings, any help would be appreciated. (inactive as in the domain was created with virConnect.defineXML sometime in the past)
looks like i have to use virDomain.create, however virDomain.create needs a defined domain xmldesc as a parameter and i am not sure on how to get that
Yes you need to use the create method of virDomain object.
i guess if virConnect.create was happening right after virConnect.defineXML i could get the return value of virConnect.defineXML and pass that onto virDomain.create. however, since the domain was created sometime in the past, i am not sure on how to get the domain ptr which virDomain.create needs
To lookup a previously defined domain, you have to use one of lookup methods provided by the virConnect object. An example with interactive python session: $ python Python 2.7.2 (default, Nov 3 2011, 10:48:09) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import libvirt conn = libvirt.open("") dom = conn.lookupByName("Bare") dom.create() 0 conn.listDomainsID() [3]
You also may use lookupByUUID if you prefer UUIDs. Peter

On Wed, May 09, 2012 at 02:26:47PM -0700, John Wayne wrote:
looks like i have to use virDomain.create, however virDomain.create needs a defined domain xmldesc as a parameter and i am not sure on how to get that
Have you tried one of these? lookupByID(self, id) Try to find a domain based on the hypervisor ID number Note that this won't work for inactive domains which have an ID of -1, in that case a lookup based on the Name or UUId need to be done instead. lookupByName(self, name) Try to lookup a domain on the given hypervisor based on its name. lookupByUUID(self, uuid) Try to lookup a domain on the given hypervisor based on its UUID. lookupByUUIDString(self, uuidstr) Try to lookup a domain on the given hypervisor based on its UUID.

On Thu, May 10, 2012 at 12:00:17PM +0300, Henrik Ahlgren wrote:
On Wed, May 09, 2012 at 02:26:47PM -0700, John Wayne wrote:
looks like i have to use virDomain.create, however virDomain.create needs a defined domain xmldesc as a parameter and i am not sure on how to get that
Have you tried one of these?
lookupByID(self, id) Try to find a domain based on the hypervisor ID number Note that this won't work for inactive domains which have an ID of -1, in that case a lookup based on the Name or UUId need to be done instead.
lookupByName(self, name) Try to lookup a domain on the given hypervisor based on its name.
lookupByUUID(self, uuid) Try to lookup a domain on the given hypervisor based on its UUID.
lookupByUUIDString(self, uuidstr) Try to lookup a domain on the given hypervisor based on its UUID.
Quick python tip... you can get a list of valid APIs from the interpretor: $ python import libvirt print dir(libvirt) ...snip output... conn = libvirt.open("qemu:///session") print dir(conn) ...snip output... print help(conn.lookupByID) ...snip output... Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (5)
-
Daniel P. Berrange
-
Doug Goldstein
-
Henrik Ahlgren
-
John Wayne
-
Peter Krempa