2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* esx_vi.h: client for the VMware VI API 2.5 to manage ESX hosts
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Matthias Bolte <matthias.bolte@googlemail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ESX_VI_H__
|
|
|
|
#define __ESX_VI_H__
|
|
|
|
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
#include <libxml/xpath.h>
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "esx_vi_types.h"
|
|
|
|
|
2009-08-05 08:23:59 +00:00
|
|
|
typedef enum _esxVI_APIVersion esxVI_APIVersion;
|
|
|
|
typedef enum _esxVI_ProductVersion esxVI_ProductVersion;
|
2009-09-23 12:40:41 +00:00
|
|
|
typedef enum _esxVI_Occurence esxVI_Occurence;
|
2009-07-23 20:21:08 +00:00
|
|
|
typedef struct _esxVI_Context esxVI_Context;
|
2009-09-04 16:24:25 +00:00
|
|
|
typedef struct _esxVI_Response esxVI_Response;
|
2009-07-23 20:21:08 +00:00
|
|
|
typedef struct _esxVI_Enumeration esxVI_Enumeration;
|
|
|
|
typedef struct _esxVI_EnumerationValue esxVI_EnumerationValue;
|
|
|
|
typedef struct _esxVI_List esxVI_List;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-05 08:23:59 +00:00
|
|
|
enum _esxVI_APIVersion {
|
|
|
|
esxVI_APIVersion_Undefined = 0,
|
|
|
|
esxVI_APIVersion_Unknown,
|
|
|
|
esxVI_APIVersion_25,
|
|
|
|
esxVI_APIVersion_40
|
|
|
|
};
|
|
|
|
|
|
|
|
enum _esxVI_ProductVersion {
|
|
|
|
esxVI_ProductVersion_Undefined = 0,
|
|
|
|
esxVI_ProductVersion_GSX20,
|
|
|
|
esxVI_ProductVersion_ESX35,
|
|
|
|
esxVI_ProductVersion_ESX40,
|
|
|
|
esxVI_ProductVersion_VPX25,
|
|
|
|
esxVI_ProductVersion_VPX40
|
|
|
|
};
|
|
|
|
|
2009-09-23 12:40:41 +00:00
|
|
|
enum _esxVI_Occurence {
|
|
|
|
esxVI_Occurence_Undefined = 0,
|
|
|
|
esxVI_Occurence_RequiredItem,
|
|
|
|
esxVI_Occurence_OptionalItem,
|
|
|
|
esxVI_Occurence_List
|
|
|
|
};
|
|
|
|
|
2009-08-05 08:23:59 +00:00
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Context
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct _esxVI_Context {
|
|
|
|
char *url;
|
2009-09-23 12:09:44 +00:00
|
|
|
char *ipAddress;
|
2009-07-23 20:21:08 +00:00
|
|
|
CURL *curl_handle;
|
|
|
|
struct curl_slist *curl_headers;
|
|
|
|
virMutex curl_lock;
|
|
|
|
char *username;
|
|
|
|
char *password;
|
|
|
|
esxVI_ServiceContent *service;
|
2009-08-05 08:23:59 +00:00
|
|
|
esxVI_APIVersion apiVersion;
|
|
|
|
esxVI_ProductVersion productVersion;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_UserSession *session;
|
|
|
|
esxVI_ManagedObjectReference *datacenter;
|
|
|
|
esxVI_ManagedObjectReference *vmFolder;
|
|
|
|
esxVI_ManagedObjectReference *hostFolder;
|
|
|
|
esxVI_SelectionSpec *fullTraversalSpecList;
|
|
|
|
};
|
|
|
|
|
|
|
|
int esxVI_Context_Alloc(virConnectPtr conn, esxVI_Context **ctx);
|
|
|
|
void esxVI_Context_Free(esxVI_Context **ctx);
|
|
|
|
int esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx,
|
2009-09-23 12:09:44 +00:00
|
|
|
const char *ipAddress, const char *url,
|
|
|
|
const char *username, const char *password,
|
|
|
|
int noVerify);
|
2009-09-23 12:52:36 +00:00
|
|
|
int esxVI_Context_DownloadFile(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
const char *url, char **content);
|
|
|
|
int esxVI_Context_UploadFile(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
const char *url, const char *content);
|
2009-09-04 16:24:25 +00:00
|
|
|
int esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
const char *request, const char *xpathExpression,
|
|
|
|
esxVI_Response **response, esxVI_Boolean expectList);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2009-09-04 16:24:25 +00:00
|
|
|
* Response
|
2009-07-23 20:21:08 +00:00
|
|
|
*/
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
struct _esxVI_Response {
|
2009-10-21 18:25:22 +00:00
|
|
|
int responseCode; /* required */
|
2009-09-04 16:24:25 +00:00
|
|
|
char *content; /* required */
|
2009-07-23 20:21:08 +00:00
|
|
|
xmlDocPtr document; /* optional */
|
|
|
|
xmlXPathContextPtr xpathContext; /* optional */
|
2009-09-04 16:08:52 +00:00
|
|
|
xmlNodePtr node; /* optional, list */
|
2009-07-23 20:21:08 +00:00
|
|
|
};
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
int esxVI_Response_Alloc(virConnectPtr conn, esxVI_Response **response);
|
|
|
|
void esxVI_Response_Free(esxVI_Response **response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Enumeration
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct _esxVI_EnumerationValue {
|
|
|
|
const char *name;
|
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _esxVI_Enumeration {
|
|
|
|
const char *type;
|
|
|
|
esxVI_EnumerationValue values[10];
|
|
|
|
};
|
|
|
|
|
|
|
|
int esxVI_Enumeration_CastFromAnyType(virConnectPtr conn,
|
|
|
|
const esxVI_Enumeration *enumeration,
|
|
|
|
esxVI_AnyType *anyType, int *boolean);
|
|
|
|
int esxVI_Enumeration_Serialize(virConnectPtr conn,
|
|
|
|
const esxVI_Enumeration *enumeration,
|
|
|
|
int value, const char *element,
|
|
|
|
virBufferPtr output, esxVI_Boolean required);
|
|
|
|
int esxVI_Enumeration_Deserialize(virConnectPtr conn,
|
|
|
|
const esxVI_Enumeration *enumeration,
|
|
|
|
xmlNodePtr node, int *value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* List
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct _esxVI_List {
|
|
|
|
esxVI_List *_next;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef int (*esxVI_List_FreeFunc) (esxVI_List **item);
|
|
|
|
typedef int (*esxVI_List_DeepCopyFunc) (virConnectPtr conn, esxVI_List **dest,
|
|
|
|
esxVI_List *src);
|
2009-09-23 12:29:39 +00:00
|
|
|
typedef int (*esxVI_List_CastFromAnyTypeFunc) (virConnectPtr conn,
|
|
|
|
esxVI_AnyType *anyType,
|
|
|
|
esxVI_List **item);
|
2009-07-23 20:21:08 +00:00
|
|
|
typedef int (*esxVI_List_SerializeFunc) (virConnectPtr conn, esxVI_List *item,
|
|
|
|
const char *element,
|
|
|
|
virBufferPtr output,
|
|
|
|
esxVI_Boolean required);
|
|
|
|
typedef int (*esxVI_List_DeserializeFunc) (virConnectPtr conn, xmlNodePtr node,
|
|
|
|
esxVI_List **item);
|
|
|
|
|
|
|
|
int esxVI_List_Append(virConnectPtr conn, esxVI_List **list, esxVI_List *item);
|
|
|
|
int esxVI_List_DeepCopy(virConnectPtr conn, esxVI_List **destList,
|
|
|
|
esxVI_List *srcList,
|
|
|
|
esxVI_List_DeepCopyFunc deepCopyFunc,
|
|
|
|
esxVI_List_FreeFunc freeFunc);
|
2009-09-23 12:29:39 +00:00
|
|
|
int esxVI_List_CastFromAnyType(virConnectPtr conn, esxVI_AnyType *anyType,
|
|
|
|
esxVI_List **list,
|
|
|
|
esxVI_List_CastFromAnyTypeFunc castFromAnyTypeFunc,
|
|
|
|
esxVI_List_FreeFunc freeFunc);
|
2009-07-23 20:21:08 +00:00
|
|
|
int esxVI_List_Serialize(virConnectPtr conn, esxVI_List *list,
|
|
|
|
const char *element, virBufferPtr output,
|
|
|
|
esxVI_Boolean required,
|
|
|
|
esxVI_List_SerializeFunc serializeFunc);
|
|
|
|
int esxVI_List_Deserialize(virConnectPtr conn, xmlNodePtr node,
|
|
|
|
esxVI_List **list,
|
|
|
|
esxVI_List_DeserializeFunc deserializeFunc,
|
|
|
|
esxVI_List_FreeFunc freeFunc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Utility and Convenience Functions
|
2009-10-18 19:31:46 +00:00
|
|
|
*
|
|
|
|
* Function naming scheme:
|
|
|
|
* - 'lookup' functions query the ESX or vCenter for information
|
|
|
|
* - 'get' functions get information from a local object
|
2009-07-23 20:21:08 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-18 19:31:46 +00:00
|
|
|
int esxVI_Alloc(virConnectPtr conn, void **ptrptr, size_t size);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-10-18 19:31:46 +00:00
|
|
|
int esxVI_CheckSerializationNecessity(virConnectPtr conn, const char *element,
|
|
|
|
esxVI_Boolean required);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
int esxVI_BuildFullTraversalSpecItem
|
|
|
|
(virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList,
|
|
|
|
const char *name, const char *type, const char *path,
|
|
|
|
const char *selectSetNames);
|
2009-10-18 19:31:46 +00:00
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int esxVI_BuildFullTraversalSpecList
|
|
|
|
(virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList);
|
|
|
|
|
|
|
|
int esxVI_EnsureSession(virConnectPtr conn, esxVI_Context *ctx);
|
|
|
|
|
2009-10-18 19:31:46 +00:00
|
|
|
int esxVI_LookupObjectContentByType(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
esxVI_ManagedObjectReference *root,
|
|
|
|
const char *type,
|
|
|
|
esxVI_String *propertyNameList,
|
|
|
|
esxVI_Boolean recurse,
|
|
|
|
esxVI_ObjectContent **objectContentList);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-04 16:03:22 +00:00
|
|
|
int esxVI_GetManagedEntityStatus
|
|
|
|
(virConnectPtr conn, esxVI_ObjectContent *objectContent,
|
|
|
|
const char *propertyName,
|
|
|
|
esxVI_ManagedEntityStatus *managedEntityStatus);
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int esxVI_GetVirtualMachinePowerState
|
|
|
|
(virConnectPtr conn, esxVI_ObjectContent *virtualMachine,
|
|
|
|
esxVI_VirtualMachinePowerState *powerState);
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
int esxVI_GetVirtualMachineQuestionInfo
|
|
|
|
(virConnectPtr conn, esxVI_ObjectContent *virtualMachine,
|
|
|
|
esxVI_VirtualMachineQuestionInfo **questionInfo);
|
|
|
|
|
2009-10-18 19:31:46 +00:00
|
|
|
int esxVI_LookupNumberOfDomainsByPowerState
|
2009-07-23 20:21:08 +00:00
|
|
|
(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
esxVI_VirtualMachinePowerState powerState, esxVI_Boolean inverse);
|
|
|
|
|
|
|
|
int esxVI_GetVirtualMachineIdentity(virConnectPtr conn,
|
|
|
|
esxVI_ObjectContent *virtualMachine,
|
|
|
|
int *id, char **name, unsigned char *uuid);
|
|
|
|
|
2009-10-18 19:31:46 +00:00
|
|
|
int esxVI_LookupResourcePoolByHostSystem
|
|
|
|
(virConnectPtr conn, esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
|
|
|
|
esxVI_ManagedObjectReference **resourcePool);
|
2009-09-23 12:09:44 +00:00
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int esxVI_LookupHostSystemByIp(virConnectPtr conn, esxVI_Context *ctx,
|
2009-09-23 12:09:44 +00:00
|
|
|
const char *ipAddress,
|
|
|
|
esxVI_String *propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent **hostSystem);
|
|
|
|
|
|
|
|
int esxVI_LookupVirtualMachineByUuid(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
const unsigned char *uuid,
|
|
|
|
esxVI_String *propertyNameList,
|
2009-09-23 12:40:41 +00:00
|
|
|
esxVI_ObjectContent **virtualMachine,
|
|
|
|
esxVI_Occurence occurence);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
int esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
|
|
|
(virConnectPtr conn, esxVI_Context *ctx, const unsigned char *uuid,
|
|
|
|
esxVI_String *propertyNameList, esxVI_ObjectContent **virtualMachine,
|
|
|
|
esxVI_Boolean autoAnswer);
|
|
|
|
|
2009-09-23 12:52:36 +00:00
|
|
|
int esxVI_LookupDatastoreByName(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
const char *name,
|
|
|
|
esxVI_String *propertyNameList,
|
|
|
|
esxVI_ObjectContent **datastore,
|
|
|
|
esxVI_Occurence occurence);
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
int esxVI_LookupTaskInfoByTask(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
esxVI_ManagedObjectReference *task,
|
|
|
|
esxVI_TaskInfo **taskInfo);
|
|
|
|
|
|
|
|
int esxVI_LookupPendingTaskInfoListByVirtualMachine
|
|
|
|
(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
esxVI_ObjectContent *virtualMachine,
|
|
|
|
esxVI_TaskInfo **pendingTaskInfoList);
|
|
|
|
|
|
|
|
int esxVI_LookupAndHandleVirtualMachineQuestion(virConnectPtr conn,
|
|
|
|
esxVI_Context *ctx,
|
|
|
|
const unsigned char *uuid,
|
|
|
|
esxVI_Boolean autoAnswer);
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int esxVI_StartVirtualMachineTask(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
const char *name, const char *request,
|
|
|
|
esxVI_ManagedObjectReference **task);
|
|
|
|
|
|
|
|
int esxVI_StartSimpleVirtualMachineTask
|
|
|
|
(virConnectPtr conn, esxVI_Context *ctx, const char *name,
|
|
|
|
esxVI_ManagedObjectReference *virtualMachine,
|
|
|
|
esxVI_ManagedObjectReference **task);
|
|
|
|
|
|
|
|
int esxVI_SimpleVirtualMachineMethod
|
|
|
|
(virConnectPtr conn, esxVI_Context *ctx, const char *name,
|
|
|
|
esxVI_ManagedObjectReference *virtualMachine);
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
int esxVI_HandleVirtualMachineQuestion
|
|
|
|
(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
esxVI_ManagedObjectReference *virtualMachine,
|
|
|
|
esxVI_VirtualMachineQuestionInfo *questionInfo,
|
|
|
|
esxVI_Boolean autoAnswer);
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int esxVI_WaitForTaskCompletion(virConnectPtr conn, esxVI_Context *ctx,
|
|
|
|
esxVI_ManagedObjectReference *task,
|
2009-11-15 21:22:47 +00:00
|
|
|
const unsigned char *virtualMachineUuid,
|
|
|
|
esxVI_Boolean autoAnswer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_TaskInfoState *finalState);
|
|
|
|
|
|
|
|
#endif /* __ESX_VI_H__ */
|