547
543
"resourcePool\0") < 0 ||
548
544
esxVI_LookupObjectContentByType(ctx, ctx->datacenter->hostFolder,
549
545
"ComputeResource", propertyNameList,
550
&computeResourceList) < 0) {
554
if (computeResourceList == NULL) {
555
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
556
_("Could not retrieve compute resource list"));
546
&computeResourceList,
547
esxVI_Occurrence_RequiredList) < 0) {
605
596
esxVI_String_Free(&propertyNameList);
607
598
if (esxVI_String_AppendValueListToList(&propertyNameList,
600
"configManager\0") < 0 ||
609
601
esxVI_LookupObjectContentByType(ctx, ctx->computeResource->_reference,
610
602
"HostSystem", propertyNameList,
611
&hostSystemList) < 0) {
615
if (hostSystemList == NULL) {
616
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
617
_("Could not retrieve host system list"));
604
esxVI_Occurrence_RequiredList) < 0) {
680
667
/* Lookup HostSystem */
681
668
if (esxVI_String_AppendValueListToList(&propertyNameList,
670
"configManager\0") < 0 ||
683
671
esxVI_FindByIp(ctx, NULL, hostSystemIpAddress, esxVI_Boolean_False,
684
672
&managedObjectReference) < 0 ||
685
673
esxVI_LookupObjectContentByType(ctx, managedObjectReference,
686
674
"HostSystem", propertyNameList,
691
if (hostSystem == NULL) {
692
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
693
_("Could not retrieve host system"));
697
if (esxVI_HostSystem_CastFromObjectContent(hostSystem,
676
esxVI_Occurrence_RequiredItem) < 0 ||
677
esxVI_HostSystem_CastFromObjectContent(hostSystem,
698
678
&ctx->hostSystem) < 0) {
702
/* Lookup ComputeResource */
682
/* Lookup (Cluster)ComputeResource */
703
683
esxVI_String_Free(&propertyNameList);
705
685
if (esxVI_String_AppendValueListToList(&propertyNameList,
708
688
"resourcePool\0") < 0 ||
709
689
esxVI_LookupObjectContentByType(ctx, hostSystem->obj,
710
690
"ComputeResource", propertyNameList,
711
&computeResource) < 0) {
715
if (computeResource == NULL) {
716
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
717
_("Could not retrieve compute resource of host system"));
721
if (esxVI_ComputeResource_CastFromObjectContent(computeResource,
692
esxVI_Occurrence_RequiredItem) < 0 ||
693
esxVI_ComputeResource_CastFromObjectContent(computeResource,
722
694
&ctx->computeResource) < 0) {
732
704
"hostFolder\0") < 0 ||
733
705
esxVI_LookupObjectContentByType(ctx, computeResource->obj,
734
706
"Datacenter", propertyNameList,
739
if (datacenter == NULL) {
740
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
741
_("Could not retrieve datacenter of compute resource"));
745
if (esxVI_Datacenter_CastFromObjectContent(datacenter,
708
esxVI_Occurrence_RequiredItem) < 0 ||
709
esxVI_Datacenter_CastFromObjectContent(datacenter,
746
710
&ctx->datacenter) < 0) {
1655
1621
if (STRNEQ(root->type, type)) {
1656
1622
if (STREQ(root->type, "Folder")) {
1657
if (STREQ(type, "Datacenter") || STREQ(type, "ComputeResource")) {
1623
if (STREQ(type, "Datacenter") || STREQ(type, "ComputeResource") ||
1624
STREQ(type, "ClusterComputeResource")) {
1658
1625
objectSpec->selectSet = ctx->selectSet_folderToChildEntity;
1660
1627
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
1676
1644
} else if (STREQ(root->type, "HostSystem")) {
1677
if (STREQ(type, "ComputeResource")) {
1645
if (STREQ(type, "ComputeResource") ||
1646
STREQ(type, "ClusterComputeResource")) {
1678
1647
objectSpec->selectSet = ctx->selectSet_hostSystemToParent;
1679
1648
} else if (STREQ(type, "VirtualMachine")) {
1680
1649
objectSpec->selectSet = ctx->selectSet_hostSystemToVm;
1704
1673
esxVI_PropertySpec_AppendToList(&propertyFilterSpec->propSet,
1705
1674
propertySpec) < 0 ||
1706
1675
esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet,
1711
result = esxVI_RetrieveProperties(ctx, propertyFilterSpec,
1677
esxVI_RetrieveProperties(ctx, propertyFilterSpec,
1678
objectContentList) < 0) {
1682
if (objectContentList == NULL) {
1683
switch (occurrence) {
1684
case esxVI_Occurrence_OptionalItem:
1685
case esxVI_Occurrence_OptionalList:
1689
case esxVI_Occurrence_RequiredItem:
1690
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
1691
_("Could not lookup '%s' from '%s'"),
1695
case esxVI_Occurrence_RequiredList:
1696
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
1697
_("Could not lookup '%s' list from '%s'"),
1702
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
1703
_("Invalid occurrence value"));
1833
1831
if (*value == esxVI_Boolean_Undefined &&
1834
occurence == esxVI_Occurrence_RequiredItem) {
1832
occurrence == esxVI_Occurrence_RequiredItem) {
1833
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
1834
_("Missing '%s' property"), propertyName);
1844
esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName,
1845
esxVI_Long **value, esxVI_Occurrence occurrence)
1847
esxVI_DynamicProperty *dynamicProperty;
1849
if (value == NULL || *value != NULL) {
1850
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
1854
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
1855
dynamicProperty = dynamicProperty->_next) {
1856
if (STREQ(dynamicProperty->name, propertyName)) {
1857
if (esxVI_Long_CastFromAnyType(dynamicProperty->val, value) < 0) {
1865
if (*value == NULL && occurrence == esxVI_Occurrence_RequiredItem) {
1835
1866
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
1836
1867
_("Missing '%s' property"), propertyName);
2233
int esxVI_LookupHostSystemProperties(esxVI_Context *ctx,
2234
esxVI_String *propertyNameList,
2235
esxVI_ObjectContent **hostSystem)
2265
esxVI_LookupHostSystemProperties(esxVI_Context *ctx,
2266
esxVI_String *propertyNameList,
2267
esxVI_ObjectContent **hostSystem)
2237
2269
return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
2238
2270
"HostSystem", propertyNameList,
2272
esxVI_Occurrence_RequiredItem);
3097
3136
datastorePathWithoutFileName, searchSpec,
3099
3138
esxVI_WaitForTaskCompletion(ctx, task, NULL, esxVI_Occurrence_None,
3100
esxVI_Boolean_False, &taskInfoState) < 0) {
3139
esxVI_Boolean_False, &taskInfoState,
3140
&taskInfoErrorMessage) < 0) {
3104
3144
if (taskInfoState != esxVI_TaskInfoState_Success) {
3105
3145
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
3106
_("Could not serach in datastore '%s'"), datastoreName);
3146
_("Could not search in datastore '%s': %s"),
3147
datastoreName, taskInfoErrorMessage);
3238
3281
datastorePath, searchSpec,
3240
3283
esxVI_WaitForTaskCompletion(ctx, task, NULL, esxVI_Occurrence_None,
3241
esxVI_Boolean_False, &taskInfoState) < 0) {
3284
esxVI_Boolean_False, &taskInfoState,
3285
&taskInfoErrorMessage) < 0) {
3245
3289
if (taskInfoState != esxVI_TaskInfoState_Success) {
3246
3290
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
3247
_("Could not serach in datastore '%s'"), datastoreName);
3291
_("Could not serach in datastore '%s': %s"),
3292
datastoreName, taskInfoErrorMessage);
3378
esxVI_LookupAutoStartDefaults(esxVI_Context *ctx,
3379
esxVI_AutoStartDefaults **defaults)
3382
esxVI_String *propertyNameList = NULL;
3383
esxVI_ObjectContent *hostAutoStartManager = NULL;
3384
esxVI_DynamicProperty *dynamicProperty = NULL;
3386
if (defaults == NULL || *defaults != NULL) {
3387
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
3392
* Lookup HostAutoStartManagerConfig from the HostAutoStartManager because
3393
* for some reason this is much faster than looking up the same info from
3394
* the HostSystem config.
3396
if (esxVI_String_AppendValueToList(&propertyNameList,
3397
"config.defaults") < 0 ||
3398
esxVI_LookupObjectContentByType
3399
(ctx, ctx->hostSystem->configManager->autoStartManager,
3400
"HostAutoStartManager", propertyNameList,
3401
&hostAutoStartManager, esxVI_Occurrence_RequiredItem) < 0) {
3405
for (dynamicProperty = hostAutoStartManager->propSet;
3406
dynamicProperty != NULL; dynamicProperty = dynamicProperty->_next) {
3407
if (STREQ(dynamicProperty->name, "config.defaults")) {
3408
if (esxVI_AutoStartDefaults_CastFromAnyType(dynamicProperty->val,
3417
if (*defaults == NULL) {
3418
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
3419
_("Could not retrieve the AutoStartDefaults object"));
3426
esxVI_String_Free(&propertyNameList);
3427
esxVI_ObjectContent_Free(&hostAutoStartManager);
3435
esxVI_LookupAutoStartPowerInfoList(esxVI_Context *ctx,
3436
esxVI_AutoStartPowerInfo **powerInfoList)
3439
esxVI_String *propertyNameList = NULL;
3440
esxVI_ObjectContent *hostAutoStartManager = NULL;
3441
esxVI_DynamicProperty *dynamicProperty = NULL;
3443
if (powerInfoList == NULL || *powerInfoList != NULL) {
3444
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
3449
* Lookup HostAutoStartManagerConfig from the HostAutoStartManager because
3450
* for some reason this is much faster than looking up the same info from
3451
* the HostSystem config.
3453
if (esxVI_String_AppendValueToList(&propertyNameList,
3454
"config.powerInfo") < 0 ||
3455
esxVI_LookupObjectContentByType
3456
(ctx, ctx->hostSystem->configManager->autoStartManager,
3457
"HostAutoStartManager", propertyNameList,
3458
&hostAutoStartManager, esxVI_Occurrence_RequiredItem) < 0) {
3462
for (dynamicProperty = hostAutoStartManager->propSet;
3463
dynamicProperty != NULL; dynamicProperty = dynamicProperty->_next) {
3464
if (STREQ(dynamicProperty->name, "config.powerInfo")) {
3465
if (esxVI_AutoStartPowerInfo_CastListFromAnyType
3466
(dynamicProperty->val, powerInfoList) < 0) {
3477
esxVI_String_Free(&propertyNameList);
3478
esxVI_ObjectContent_Free(&hostAutoStartManager);
3332
3486
esxVI_HandleVirtualMachineQuestion
3333
3487
(esxVI_Context *ctx, esxVI_ManagedObjectReference *virtualMachine,
3334
3488
esxVI_VirtualMachineQuestionInfo *questionInfo,
3741
if (*finalState != esxVI_TaskInfoState_Success) {
3742
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) {
3746
if (taskInfo->error == NULL) {
3747
*errorMessage = strdup(_("Unknown error"));
3749
if (*errorMessage == NULL) {
3750
virReportOOMError();
3753
} else if (taskInfo->error->localizedMessage == NULL) {
3754
*errorMessage = strdup(taskInfo->error->fault->_actualType);
3756
if (*errorMessage == NULL) {
3757
virReportOOMError();
3761
if (virAsprintf(errorMessage, "%s - %s",
3762
taskInfo->error->fault->_actualType,
3763
taskInfo->error->localizedMessage) < 0) {
3764
virReportOOMError();
3842
esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersion)
3845
* virtualHW.version compatibility matrix:
3853
switch (productVersion) {
3854
case esxVI_ProductVersion_ESX35:
3855
case esxVI_ProductVersion_VPX25:
3858
case esxVI_ProductVersion_GSX20:
3859
case esxVI_ProductVersion_ESX40:
3860
case esxVI_ProductVersion_ESX41:
3861
case esxVI_ProductVersion_VPX40:
3862
case esxVI_ProductVersion_VPX41:
3865
case esxVI_ProductVersion_ESX4x:
3866
case esxVI_ProductVersion_VPX4x:
3870
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
3871
_("Unexpected product version"));