mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
esx: Add esxVI_LookupVirtualMachineByName
Used in esxDomainLookupByName and to be used in esxDomainDefineXML later.
This commit is contained in:
parent
bba36f7fc7
commit
041a18be17
@ -1206,12 +1206,10 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
|
|||||||
{
|
{
|
||||||
esxPrivate *priv = conn->privateData;
|
esxPrivate *priv = conn->privateData;
|
||||||
esxVI_String *propertyNameList = NULL;
|
esxVI_String *propertyNameList = NULL;
|
||||||
esxVI_ObjectContent *virtualMachineList = NULL;
|
|
||||||
esxVI_ObjectContent *virtualMachine = NULL;
|
esxVI_ObjectContent *virtualMachine = NULL;
|
||||||
esxVI_VirtualMachinePowerState powerState;
|
esxVI_VirtualMachinePowerState powerState;
|
||||||
int id_candidate = -1;
|
int id = -1;
|
||||||
char *name_candidate = NULL;
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||||
unsigned char uuid_candidate[VIR_UUID_BUFLEN];
|
|
||||||
virDomainPtr domain = NULL;
|
virDomainPtr domain = NULL;
|
||||||
|
|
||||||
if (esxVI_EnsureSession(priv->host) < 0) {
|
if (esxVI_EnsureSession(priv->host) < 0) {
|
||||||
@ -1220,28 +1218,22 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
|
|||||||
|
|
||||||
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
||||||
"configStatus\0"
|
"configStatus\0"
|
||||||
"name\0"
|
|
||||||
"runtime.powerState\0"
|
"runtime.powerState\0"
|
||||||
"config.uuid\0") < 0 ||
|
"config.uuid\0") < 0 ||
|
||||||
esxVI_LookupObjectContentByType(priv->host, priv->host->vmFolder,
|
esxVI_LookupVirtualMachineByName(priv->host, name, propertyNameList,
|
||||||
"VirtualMachine", propertyNameList,
|
&virtualMachine,
|
||||||
esxVI_Boolean_True,
|
esxVI_Occurrence_OptionalItem) < 0) {
|
||||||
&virtualMachineList) < 0) {
|
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (virtualMachine = virtualMachineList; virtualMachine != NULL;
|
if (virtualMachine == NULL) {
|
||||||
virtualMachine = virtualMachine->_next) {
|
ESX_ERROR(VIR_ERR_NO_DOMAIN, "No domain with name '%s'", name);
|
||||||
VIR_FREE(name_candidate);
|
|
||||||
|
|
||||||
if (esxVI_GetVirtualMachineIdentity(virtualMachine,
|
|
||||||
&id_candidate, &name_candidate,
|
|
||||||
uuid_candidate) < 0) {
|
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STRNEQ(name, name_candidate)) {
|
|
||||||
continue;
|
if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id, NULL, uuid) < 0) {
|
||||||
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
|
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
|
||||||
@ -1249,7 +1241,7 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
|
|||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
domain = virGetDomain(conn, name_candidate, uuid_candidate);
|
domain = virGetDomain(conn, name, uuid);
|
||||||
|
|
||||||
if (domain == NULL) {
|
if (domain == NULL) {
|
||||||
goto failure;
|
goto failure;
|
||||||
@ -1257,22 +1249,14 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
|
|||||||
|
|
||||||
/* Only running/suspended virtual machines have an ID != -1 */
|
/* Only running/suspended virtual machines have an ID != -1 */
|
||||||
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
|
||||||
domain->id = id_candidate;
|
domain->id = id;
|
||||||
} else {
|
} else {
|
||||||
domain->id = -1;
|
domain->id = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (domain == NULL) {
|
|
||||||
ESX_ERROR(VIR_ERR_NO_DOMAIN, "No domain with name '%s'", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
esxVI_String_Free(&propertyNameList);
|
esxVI_String_Free(&propertyNameList);
|
||||||
esxVI_ObjectContent_Free(&virtualMachineList);
|
esxVI_ObjectContent_Free(&virtualMachine);
|
||||||
VIR_FREE(name_candidate);
|
|
||||||
|
|
||||||
return domain;
|
return domain;
|
||||||
|
|
||||||
|
@ -1876,6 +1876,78 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
|
||||||
|
esxVI_String *propertyNameList,
|
||||||
|
esxVI_ObjectContent **virtualMachine,
|
||||||
|
esxVI_Occurrence occurrence)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
esxVI_String *completePropertyNameList = NULL;
|
||||||
|
esxVI_ObjectContent *virtualMachineList = NULL;
|
||||||
|
esxVI_ObjectContent *candidate = NULL;
|
||||||
|
char *name_candidate = NULL;
|
||||||
|
|
||||||
|
if (virtualMachine == NULL || *virtualMachine != NULL) {
|
||||||
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (esxVI_String_DeepCopyList(&completePropertyNameList,
|
||||||
|
propertyNameList) < 0 ||
|
||||||
|
esxVI_String_AppendValueToList(&completePropertyNameList, "name") < 0 ||
|
||||||
|
esxVI_LookupObjectContentByType(ctx, ctx->vmFolder, "VirtualMachine",
|
||||||
|
completePropertyNameList,
|
||||||
|
esxVI_Boolean_True,
|
||||||
|
&virtualMachineList) < 0) {
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (candidate = virtualMachineList; candidate != NULL;
|
||||||
|
candidate = candidate->_next) {
|
||||||
|
VIR_FREE(name_candidate);
|
||||||
|
|
||||||
|
if (esxVI_GetVirtualMachineIdentity(candidate, NULL, &name_candidate,
|
||||||
|
NULL) < 0) {
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STRNEQ(name, name_candidate)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (esxVI_ObjectContent_DeepCopy(virtualMachine, candidate) < 0) {
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*virtualMachine == NULL) {
|
||||||
|
if (occurrence == esxVI_Occurrence_OptionalItem) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
|
||||||
|
"Could not find domain with name '%s'", name);
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
esxVI_String_Free(&completePropertyNameList);
|
||||||
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
||||||
|
VIR_FREE(name_candidate);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
failure:
|
||||||
|
result = -1;
|
||||||
|
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
||||||
(esxVI_Context *ctx, const unsigned char *uuid,
|
(esxVI_Context *ctx, const unsigned char *uuid,
|
||||||
|
@ -237,6 +237,11 @@ int esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx,
|
|||||||
esxVI_ObjectContent **virtualMachine,
|
esxVI_ObjectContent **virtualMachine,
|
||||||
esxVI_Occurrence occurrence);
|
esxVI_Occurrence occurrence);
|
||||||
|
|
||||||
|
int esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
|
||||||
|
esxVI_String *propertyNameList,
|
||||||
|
esxVI_ObjectContent **virtualMachine,
|
||||||
|
esxVI_Occurrence occurrence);
|
||||||
|
|
||||||
int esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
int esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
||||||
(esxVI_Context *ctx, const unsigned char *uuid,
|
(esxVI_Context *ctx, const unsigned char *uuid,
|
||||||
esxVI_String *propertyNameList, esxVI_ObjectContent **virtualMachine,
|
esxVI_String *propertyNameList, esxVI_ObjectContent **virtualMachine,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user