From 9f85668bd7344016dcb378885d40846aab525a9b Mon Sep 17 00:00:00 2001 From: Matthias Bolte Date: Sat, 31 Jul 2010 22:27:32 +0200 Subject: [PATCH] esx: Map some managed object types Datacenter, ComputeResource and HostSystem will be used for simplified handling and caching. --- src/esx/esx_vi_types.c | 283 +++++++++++++++++++++++++++++++++++++++++ src/esx/esx_vi_types.h | 96 ++++++++++++++ 2 files changed, 379 insertions(+) diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 5cf30b1ccf..bb791af128 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -704,6 +704,15 @@ esxVI_Type_ToString(esxVI_Type type) case esxVI_Type_ManagedObjectReference: return "ManagedObjectReference"; + case esxVI_Type_Datacenter: + return "Datacenter"; + + case esxVI_Type_ComputeResource: + return "ComputeResource"; + + case esxVI_Type_HostSystem: + return "HostSystem"; + #include "esx_vi_types.generated.typetostring" case esxVI_Type_Other: @@ -734,8 +743,15 @@ esxVI_Type_FromString(const char *type) return esxVI_Type_Fault; } else if (STREQ(type, "ManagedObjectReference")) { return esxVI_Type_ManagedObjectReference; + } else if (STREQ(type, "Datacenter")) { + return esxVI_Type_Datacenter; + } else if (STREQ(type, "ComputeResource")) { + return esxVI_Type_ComputeResource; + } else if (STREQ(type, "HostSystem")) { + return esxVI_Type_HostSystem; } + #include "esx_vi_types.generated.typefromstring" else { @@ -1531,6 +1547,273 @@ esxVI_ManagedObjectReference_Deserialize +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * VI Managed Object: Datacenter + * extends ManagedEntity + */ + +/* esxVI_Datacenter_Alloc */ +ESX_VI__TEMPLATE__ALLOC(Datacenter) + +/* esxVI_Datacenter_Free */ +ESX_VI__TEMPLATE__FREE(Datacenter, +{ + esxVI_Datacenter_Free(&item->_next); + esxVI_ManagedObjectReference_Free(&item->_reference); + + /* ManagedEntity */ + VIR_FREE(item->name); + + /* Datacenter */ + esxVI_ManagedObjectReference_Free(&item->hostFolder); + esxVI_ManagedObjectReference_Free(&item->vmFolder); +}) + +/* esxVI_Datacenter_Validate */ +ESX_VI__TEMPLATE__VALIDATE(Datacenter, +{ + /* ManagedEntity */ + ESX_VI__TEMPLATE__PROPERTY__REQUIRE(name); + + /* Datacenter */ + ESX_VI__TEMPLATE__PROPERTY__REQUIRE(hostFolder); + ESX_VI__TEMPLATE__PROPERTY__REQUIRE(vmFolder); +}) + +int +esxVI_Datacenter_CastFromObjectContent(esxVI_ObjectContent *objectContent, + esxVI_Datacenter **datacenter) +{ + esxVI_DynamicProperty *dynamicProperty = NULL; + + if (objectContent == NULL || datacenter == NULL || *datacenter != NULL) { + ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); + return -1; + } + + if (esxVI_Datacenter_Alloc(datacenter) < 0) { + return -1; + } + + if (esxVI_ManagedObjectReference_DeepCopy(&(*datacenter)->_reference, + objectContent->obj) < 0) { + goto failure; + } + + for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + dynamicProperty = dynamicProperty->_next) { + if (STREQ(dynamicProperty->name, "name")) { + if (esxVI_AnyType_ExpectType(dynamicProperty->val, + esxVI_Type_String) < 0) { + goto failure; + } + + (*datacenter)->name = strdup(dynamicProperty->val->string); + + if ((*datacenter)->name == NULL) { + virReportOOMError(); + goto failure; + } + } else if (STREQ(dynamicProperty->name, "hostFolder")) { + if (esxVI_ManagedObjectReference_CastFromAnyType + (dynamicProperty->val, &(*datacenter)->hostFolder) < 0) { + goto failure; + } + } else if (STREQ(dynamicProperty->name, "vmFolder")) { + if (esxVI_ManagedObjectReference_CastFromAnyType + (dynamicProperty->val, &(*datacenter)->vmFolder) < 0) { + goto failure; + } + } + } + + if (esxVI_Datacenter_Validate(*datacenter) < 0) { + goto failure; + } + + return 0; + + failure: + esxVI_Datacenter_Free(datacenter); + + return -1; +} + + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * VI Managed Object: ComputeResource + * extends ManagedEntity + */ + +/* esxVI_ComputeResource_Alloc */ +ESX_VI__TEMPLATE__ALLOC(ComputeResource) + +/* esxVI_ComputeResource_Free */ +ESX_VI__TEMPLATE__FREE(ComputeResource, +{ + esxVI_ComputeResource_Free(&item->_next); + esxVI_ManagedObjectReference_Free(&item->_reference); + + /* ManagedEntity */ + VIR_FREE(item->name); + + /* ComputeResource */ + esxVI_ManagedObjectReference_Free(&item->host); + esxVI_ManagedObjectReference_Free(&item->resourcePool); +}) + +/* esxVI_ComputeResource_Validate */ +ESX_VI__TEMPLATE__VALIDATE(ComputeResource, +{ + /* ManagedEntity */ + ESX_VI__TEMPLATE__PROPERTY__REQUIRE(name); + + /* ComputeResource */ +}) + +int +esxVI_ComputeResource_CastFromObjectContent + (esxVI_ObjectContent *objectContent, esxVI_ComputeResource **computeResource) +{ + esxVI_DynamicProperty *dynamicProperty = NULL; + + if (objectContent == NULL || computeResource == NULL || + *computeResource != NULL) { + ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); + return -1; + } + + if (esxVI_ComputeResource_Alloc(computeResource) < 0) { + return -1; + } + + if (esxVI_ManagedObjectReference_DeepCopy(&(*computeResource)->_reference, + objectContent->obj) < 0) { + goto failure; + } + + for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + dynamicProperty = dynamicProperty->_next) { + if (STREQ(dynamicProperty->name, "name")) { + if (esxVI_AnyType_ExpectType(dynamicProperty->val, + esxVI_Type_String) < 0) { + goto failure; + } + + (*computeResource)->name = strdup(dynamicProperty->val->string); + + if ((*computeResource)->name == NULL) { + virReportOOMError(); + goto failure; + } + } else if (STREQ(dynamicProperty->name, "host")) { + if (esxVI_ManagedObjectReference_CastListFromAnyType + (dynamicProperty->val, &(*computeResource)->host) < 0) { + goto failure; + } + } else if (STREQ(dynamicProperty->name, "resourcePool")) { + if (esxVI_ManagedObjectReference_CastFromAnyType + (dynamicProperty->val, &(*computeResource)->resourcePool) < 0) { + goto failure; + } + } + } + + if (esxVI_ComputeResource_Validate(*computeResource) < 0) { + goto failure; + } + + return 0; + + failure: + esxVI_ComputeResource_Free(computeResource); + + return -1; +} + + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * VI Managed Object: HostSystem + * extends ManagedEntity + */ + +/* esxVI_HostSystem_Alloc */ +ESX_VI__TEMPLATE__ALLOC(HostSystem) + +/* esxVI_HostSystem_Free */ +ESX_VI__TEMPLATE__FREE(HostSystem, +{ + esxVI_HostSystem_Free(&item->_next); + esxVI_ManagedObjectReference_Free(&item->_reference); + + /* ManagedEntity */ + VIR_FREE(item->name); + + /* HostSystem */ +}) + +/* esxVI_HostSystem_Validate */ +ESX_VI__TEMPLATE__VALIDATE(HostSystem, +{ + /* ManagedEntity */ + ESX_VI__TEMPLATE__PROPERTY__REQUIRE(name); + + /* HostSystem */ +}) + +int +esxVI_HostSystem_CastFromObjectContent(esxVI_ObjectContent *objectContent, + esxVI_HostSystem **hostSystem) +{ + esxVI_DynamicProperty *dynamicProperty = NULL; + + if (objectContent == NULL || hostSystem == NULL || *hostSystem != NULL) { + ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); + return -1; + } + + if (esxVI_HostSystem_Alloc(hostSystem) < 0) { + return -1; + } + + if (esxVI_ManagedObjectReference_DeepCopy(&(*hostSystem)->_reference, + objectContent->obj) < 0) { + goto failure; + } + + for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + dynamicProperty = dynamicProperty->_next) { + if (STREQ(dynamicProperty->name, "name")) { + if (esxVI_AnyType_ExpectType(dynamicProperty->val, + esxVI_Type_String) < 0) { + goto failure; + } + + (*hostSystem)->name = strdup(dynamicProperty->val->string); + + if ((*hostSystem)->name == NULL) { + virReportOOMError(); + goto failure; + } + } + } + + if (esxVI_HostSystem_Validate(*hostSystem) < 0) { + goto failure; + } + + return 0; + + failure: + esxVI_HostSystem_Free(hostSystem); + + return -1; +} + + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * VI Enum: VirtualMachinePowerState (Additions) */ diff --git a/src/esx/esx_vi_types.h b/src/esx/esx_vi_types.h index 4bedca9ca1..f659361d9c 100644 --- a/src/esx/esx_vi_types.h +++ b/src/esx/esx_vi_types.h @@ -26,6 +26,7 @@ typedef enum _esxVI_Type esxVI_Type; typedef struct _esxVI_Object esxVI_Object; +typedef struct _esxVI_ManagedObject esxVI_ManagedObject; @@ -48,6 +49,9 @@ typedef struct _esxVI_DateTime esxVI_DateTime; typedef struct _esxVI_Fault esxVI_Fault; typedef struct _esxVI_ManagedObjectReference esxVI_ManagedObjectReference; +typedef struct _esxVI_Datacenter esxVI_Datacenter; +typedef struct _esxVI_ComputeResource esxVI_ComputeResource; +typedef struct _esxVI_HostSystem esxVI_HostSystem; # include "esx_vi_types.generated.typedef" @@ -68,6 +72,9 @@ enum _esxVI_Type { esxVI_Type_DateTime, esxVI_Type_Fault, esxVI_Type_ManagedObjectReference, + esxVI_Type_Datacenter, + esxVI_Type_ComputeResource, + esxVI_Type_HostSystem, # include "esx_vi_types.generated.typeenum" @@ -90,6 +97,18 @@ struct _esxVI_Object { +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * ManagedObject extends Object + */ + +struct _esxVI_ManagedObject { + esxVI_ManagedObject *_next; /* optional */ + esxVI_Type _type; /* required */ + esxVI_ManagedObjectReference *_reference; /* required */ +}; + + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * XSD: Boolean */ @@ -300,6 +319,83 @@ int esxVI_ManagedObjectReference_Deserialize +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * VI Managed Object: Datacenter + * extends ManagedEntity + */ + +struct _esxVI_Datacenter { + esxVI_Datacenter *_next; /* optional */ + esxVI_Type _type; /* required */ + esxVI_ManagedObjectReference *_reference; /* required */ + + /* ManagedEntity */ + char *name; /* required */ + + /* Datacenter */ + esxVI_ManagedObjectReference *hostFolder; /* required */ + esxVI_ManagedObjectReference *vmFolder; /* required */ +}; + +int esxVI_Datacenter_Alloc(esxVI_Datacenter **datacenter); +void esxVI_Datacenter_Free(esxVI_Datacenter **datacenter); +int esxVI_Datacenter_Validate(esxVI_Datacenter *datacenter); +int esxVI_Datacenter_CastFromObjectContent(esxVI_ObjectContent *objectContent, + esxVI_Datacenter **datacenter); + + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * VI Managed Object: ComputeResource + * extends ManagedEntity + */ + +struct _esxVI_ComputeResource { + esxVI_ComputeResource *_next; /* optional */ + esxVI_Type _type; /* required */ + esxVI_ManagedObjectReference *_reference; /* required */ + + /* ManagedEntity */ + char *name; /* required */ + + /* ComputeResource */ + esxVI_ManagedObjectReference *host; /* optional, list */ + esxVI_ManagedObjectReference *resourcePool; /* optional */ +}; + +int esxVI_ComputeResource_Alloc(esxVI_ComputeResource **computeResource); +void esxVI_ComputeResource_Free(esxVI_ComputeResource **computeResource); +int esxVI_ComputeResource_Validate(esxVI_ComputeResource *computeResource); +int esxVI_ComputeResource_CastFromObjectContent + (esxVI_ObjectContent *objectContent, + esxVI_ComputeResource **computeResource); + + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * VI Managed Object: HostSystem + * extends ManagedEntity + */ + +struct _esxVI_HostSystem { + esxVI_HostSystem *_next; /* optional */ + esxVI_Type _type; /* required */ + esxVI_ManagedObjectReference *_reference; /* required */ + + /* ManagedEntity */ + char *name; /* required */ + + /* HostSystem */ +}; + +int esxVI_HostSystem_Alloc(esxVI_HostSystem **hostSystem); +void esxVI_HostSystem_Free(esxVI_HostSystem **hostSystem); +int esxVI_HostSystem_Validate(esxVI_HostSystem *hostSystem); +int esxVI_HostSystem_CastFromObjectContent(esxVI_ObjectContent *objectContent, + esxVI_HostSystem **hostSystem); + + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * VI Enum: VirtualMachinePowerState (Additions) */