Question

I want to define a new persistent domain using Libvirt Java Bindings on an ESXi host. I created an xml description for it, in which I set (among other things) the devices for the VM and their source files. However, unless I manually create the source file for a device on the server, so that it exists already when defining the VM programatically, this will fail. Here is the xml code I use:

<disk type='file' device='disk'>
    <source file='[datastore1] TestVM/TestVM.vmdk'/>
    <target dev='sda' bus='scsi'/>
    <address type='drive' controller='0' bus='0' unit='0'/>
</disk>

So the TestVM.vmdk needs to exist before making the call to define the domain, but I need to somehow create this programmatically. Does anyone have any idea how I could do this using Libvirt Java Bindings?

Was it helpful?

Solution

OK, so I found a solution, in case someone else is looking for this. Libvirt provides Java API to create a storage volume in a storage pool, based on xml description. You need to specify the path to the vmdk file in the description, and use that path when creating a new vm. Get a storage pool via storagePoolLookupByName method in Connect object and add a volume to that pool via storageVolCreateXML.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top