"hostFolder\0") < 0 ||
esxVI_LookupObjectContentByType(ctx, ctx->service->rootFolder,
"Datacenter", propertyNameList,
- &datacenterList) < 0) {
- goto cleanup;
- }
-
- if (datacenterList == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve datacenter list"));
+ &datacenterList,
+ esxVI_Occurrence_RequiredList) < 0) {
goto cleanup;
}
"resourcePool\0") < 0 ||
esxVI_LookupObjectContentByType(ctx, ctx->datacenter->hostFolder,
"ComputeResource", propertyNameList,
- &computeResourceList) < 0) {
- goto cleanup;
- }
-
- if (computeResourceList == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve compute resource list"));
+ &computeResourceList,
+ esxVI_Occurrence_RequiredList) < 0) {
goto cleanup;
}
"configManager\0") < 0 ||
esxVI_LookupObjectContentByType(ctx, ctx->computeResource->_reference,
"HostSystem", propertyNameList,
- &hostSystemList) < 0) {
- goto cleanup;
- }
-
- if (hostSystemList == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve host system list"));
+ &hostSystemList,
+ esxVI_Occurrence_RequiredList) < 0) {
goto cleanup;
}
&managedObjectReference) < 0 ||
esxVI_LookupObjectContentByType(ctx, managedObjectReference,
"HostSystem", propertyNameList,
- &hostSystem) < 0) {
- goto cleanup;
- }
-
- if (hostSystem == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve host system"));
- goto cleanup;
- }
-
- if (esxVI_HostSystem_CastFromObjectContent(hostSystem,
+ &hostSystem,
+ esxVI_Occurrence_RequiredItem) < 0 ||
+ esxVI_HostSystem_CastFromObjectContent(hostSystem,
&ctx->hostSystem) < 0) {
goto cleanup;
}
"resourcePool\0") < 0 ||
esxVI_LookupObjectContentByType(ctx, hostSystem->obj,
"ComputeResource", propertyNameList,
- &computeResource) < 0) {
- goto cleanup;
- }
-
- if (computeResource == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve compute resource of host system"));
- goto cleanup;
- }
-
- if (esxVI_ComputeResource_CastFromObjectContent(computeResource,
+ &computeResource,
+ esxVI_Occurrence_RequiredItem) < 0 ||
+ esxVI_ComputeResource_CastFromObjectContent(computeResource,
&ctx->computeResource) < 0) {
goto cleanup;
}
"hostFolder\0") < 0 ||
esxVI_LookupObjectContentByType(ctx, computeResource->obj,
"Datacenter", propertyNameList,
- &datacenter) < 0) {
- goto cleanup;
- }
-
- if (datacenter == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve datacenter of compute resource"));
- goto cleanup;
- }
-
- if (esxVI_Datacenter_CastFromObjectContent(datacenter,
+ &datacenter,
+ esxVI_Occurrence_RequiredItem) < 0 ||
+ esxVI_Datacenter_CastFromObjectContent(datacenter,
&ctx->datacenter) < 0) {
goto cleanup;
}
"currentSession") < 0 ||
esxVI_LookupObjectContentByType(ctx, ctx->service->sessionManager,
"SessionManager", propertyNameList,
- &sessionManager) < 0) {
+ &sessionManager,
+ esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}
esxVI_ManagedObjectReference *root,
const char *type,
esxVI_String *propertyNameList,
- esxVI_ObjectContent **objectContentList)
+ esxVI_ObjectContent **objectContentList,
+ esxVI_Occurrence occurrence)
{
int result = -1;
esxVI_ObjectSpec *objectSpec = NULL;
esxVI_PropertySpec_AppendToList(&propertyFilterSpec->propSet,
propertySpec) < 0 ||
esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet,
- objectSpec) < 0) {
+ objectSpec) < 0 ||
+ esxVI_RetrieveProperties(ctx, propertyFilterSpec,
+ objectContentList) < 0) {
goto cleanup;
}
- result = esxVI_RetrieveProperties(ctx, propertyFilterSpec,
- objectContentList);
+ if (objectContentList == NULL) {
+ switch (occurrence) {
+ case esxVI_Occurrence_OptionalItem:
+ case esxVI_Occurrence_OptionalList:
+ result = 0;
+ break;
+
+ case esxVI_Occurrence_RequiredItem:
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
+ _("Could not lookup '%s' from '%s'"),
+ type, root->type);
+ break;
+
+ case esxVI_Occurrence_RequiredList:
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
+ _("Could not lookup '%s' list from '%s'"),
+ type, root->type);
+ break;
+
+ default:
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Invalid occurrence value"));
+ break;
+ }
+
+ goto cleanup;
+ }
+
+ result = 0;
cleanup:
/*
{
return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
"HostSystem", propertyNameList,
- hostSystem);
+ hostSystem,
+ esxVI_Occurrence_RequiredItem);
}
* for cluster support */
return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
"VirtualMachine", propertyNameList,
- virtualMachineList);
+ virtualMachineList,
+ esxVI_Occurrence_OptionalList);
}
if (esxVI_LookupObjectContentByType(ctx, managedObjectReference,
"VirtualMachine", propertyNameList,
- virtualMachine) < 0) {
+ virtualMachine,
+ esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}
* support */
return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
"Datastore", propertyNameList,
- datastoreList);
+ datastoreList,
+ esxVI_Occurrence_OptionalList);
}
if (esxVI_String_AppendValueToList(&propertyNameList, "host") < 0 ||
esxVI_LookupObjectContentByType(ctx, datastore, "Datastore",
- propertyNameList, &objectContent) < 0) {
+ propertyNameList, &objectContent,
+ esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}
if (esxVI_String_AppendValueToList(&propertyNameList, "info") < 0 ||
esxVI_LookupObjectContentByType(ctx, task, "Task", propertyNameList,
- &objectContent) < 0) {
+ &objectContent,
+ esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}
esxVI_LookupObjectContentByType
(ctx, ctx->hostSystem->configManager->autoStartManager,
"HostAutoStartManager", propertyNameList,
- &hostAutoStartManager) < 0) {
- goto cleanup;
- }
-
- if (hostAutoStartManager == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve the HostAutoStartManager object"));
+ &hostAutoStartManager, esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}
esxVI_LookupObjectContentByType
(ctx, ctx->hostSystem->configManager->autoStartManager,
"HostAutoStartManager", propertyNameList,
- &hostAutoStartManager) < 0) {
- goto cleanup;
- }
-
- if (hostAutoStartManager == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve the HostAutoStartManager object"));
+ &hostAutoStartManager, esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}