ESX: Change disk selection for datastore detection.

In order to register a new virtual machine the ESX driver needs to upload
a VMX file to a datastore. Try to put this file beside the main VMDK file
of the virtual machine. Change the disk selection for datastore detection
to choose the first file-based harddisk instead of just the first disk.
The first disk may be a CDROM disk and ISO images are normaly not located
in the virtual machine's directory.

* src/esx/esx_driver.c: change disk selection for datastore detection
This commit is contained in:
Matthias Bolte 2009-10-18 21:21:46 +02:00
parent b7abcf9d71
commit 7c7681dd90

View File

@ -2410,6 +2410,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
esxPrivate *priv = (esxPrivate *)conn->privateData; esxPrivate *priv = (esxPrivate *)conn->privateData;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
char *vmx = NULL; char *vmx = NULL;
int i;
virDomainDiskDefPtr disk = NULL;
esxVI_ObjectContent *virtualMachine = NULL; esxVI_ObjectContent *virtualMachine = NULL;
char *datastoreName = NULL; char *datastoreName = NULL;
char *directoryName = NULL; char *directoryName = NULL;
@ -2458,31 +2460,51 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
goto failure; goto failure;
} }
/* Build VMX datastore URL */ /*
* Build VMX datastore URL. Use the source of the first file-based harddisk
* to deduce the datastore and path for the VMX file. Don't just use the
* first disk, because it may be CDROM disk and ISO images are normaly not
* located in the virtual machine's directory. This approach to deduce the
* datastore isn't perfect but should work in the majority of cases.
*/
if (def->ndisks < 1) { if (def->ndisks < 1) {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Domain XML doesn't contain a disk, cannot deduce datastore " "Domain XML doesn't contain any disks, cannot deduce "
"and path for VMX file"); "datastore and path for VMX file");
goto failure; goto failure;
} }
if (def->disks[0]->src == NULL) { for (i = 0; i < def->ndisks; ++i) {
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
def->disks[i]->type == VIR_DOMAIN_DISK_TYPE_FILE) {
disk = def->disks[i];
break;
}
}
if (disk == NULL) {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"First disk has no source, cannot deduce datastore and path " "Domain XML doesn't contain any file-based harddisks, "
"for VMX file"); "cannot deduce datastore and path for VMX file");
goto failure; goto failure;
} }
if (esxUtil_ParseDatastoreRelatedPath(conn, def->disks[0]->src, if (disk->src == NULL) {
&datastoreName, &directoryName, ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
&fileName) < 0) { "First file-based harddisk has no source, cannot deduce "
"datastore and path for VMX file");
goto failure;
}
if (esxUtil_ParseDatastoreRelatedPath(conn, disk->src, &datastoreName,
&directoryName, &fileName) < 0) {
goto failure; goto failure;
} }
if (! virFileHasSuffix(fileName, ".vmdk")) { if (! virFileHasSuffix(fileName, ".vmdk")) {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Expecting source of first disk '%s' to be a VMDK image", "Expecting source '%s' of first file-based harddisk to be a "
def->disks[0]->src); "VMDK image", disk->src);
goto failure; goto failure;
} }