esx_vi.h 10.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

/*
 * 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__
24
# define __ESX_VI_H__
25

26 27 28
# include <libxml/tree.h>
# include <libxml/xpath.h>
# include <curl/curl.h>
29

30 31 32
# include "internal.h"
# include "datatypes.h"
# include "esx_vi_types.h"
33

34 35
typedef enum _esxVI_APIVersion esxVI_APIVersion;
typedef enum _esxVI_ProductVersion esxVI_ProductVersion;
M
Matthias Bolte 已提交
36
typedef enum _esxVI_Occurrence esxVI_Occurrence;
37
typedef struct _esxVI_Context esxVI_Context;
38
typedef struct _esxVI_Response esxVI_Response;
39 40 41 42 43 44
typedef struct _esxVI_Enumeration esxVI_Enumeration;
typedef struct _esxVI_EnumerationValue esxVI_EnumerationValue;
typedef struct _esxVI_List esxVI_List;



45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
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
};

M
Matthias Bolte 已提交
61 62 63 64
enum _esxVI_Occurrence {
    esxVI_Occurrence_Undefined = 0,
    esxVI_Occurrence_RequiredItem,
    esxVI_Occurrence_OptionalItem,
65 66
    esxVI_Occurrence_List,
    esxVI_Occurrence_None
67 68
};

69 70


71 72 73 74 75 76
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Context
 */

struct _esxVI_Context {
    char *url;
M
Matthias Bolte 已提交
77
    char *ipAddress;
78 79
    CURL *curl_handle;
    struct curl_slist *curl_headers;
80
    char curl_error[CURL_ERROR_SIZE];
81 82 83 84
    virMutex curl_lock;
    char *username;
    char *password;
    esxVI_ServiceContent *service;
85 86
    esxVI_APIVersion apiVersion;
    esxVI_ProductVersion productVersion;
87 88 89 90 91 92 93
    esxVI_UserSession *session;
    esxVI_ManagedObjectReference *datacenter;
    esxVI_ManagedObjectReference *vmFolder;
    esxVI_ManagedObjectReference *hostFolder;
    esxVI_SelectionSpec *fullTraversalSpecList;
};

94
int esxVI_Context_Alloc(esxVI_Context **ctx);
95
void esxVI_Context_Free(esxVI_Context **ctx);
96 97 98 99 100 101 102 103 104 105
int esxVI_Context_Connect(esxVI_Context *ctx, const char *ipAddress,
                          const char *url, const char *username,
                          const char *password, int noVerify);
int esxVI_Context_DownloadFile(esxVI_Context *ctx, const char *url,
                               char **content);
int esxVI_Context_UploadFile(esxVI_Context *ctx, const char *url,
                             const char *content);
int esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
                          const char *request, esxVI_Response **response,
                          esxVI_Occurrence occurrence);
106 107 108 109



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
110
 * Response
111 112
 */

113
struct _esxVI_Response {
114
    int responseCode;                                 /* required */
115
    char *content;                                    /* required */
116
    xmlDocPtr document;                               /* optional */
117
    xmlNodePtr node;                                  /* optional, list */
118 119
};

120
int esxVI_Response_Alloc(esxVI_Response **response);
121
void esxVI_Response_Free(esxVI_Response **response);
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Enumeration
 */

struct _esxVI_EnumerationValue {
    const char *name;
    int value;
};

struct _esxVI_Enumeration {
    const char *type;
    esxVI_EnumerationValue values[10];
};

139
int esxVI_Enumeration_CastFromAnyType(const esxVI_Enumeration *enumeration,
140
                                      esxVI_AnyType *anyType, int *value);
141
int esxVI_Enumeration_Serialize(const esxVI_Enumeration *enumeration,
142
                                int value, const char *element,
143
                                virBufferPtr output);
144
int esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration,
145 146 147 148 149 150 151 152 153 154 155 156 157
                                  xmlNodePtr node, int *value);



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * List
 */

struct _esxVI_List {
    esxVI_List *_next;
};

typedef int (*esxVI_List_FreeFunc) (esxVI_List **item);
158 159
typedef int (*esxVI_List_DeepCopyFunc) (esxVI_List **dest, esxVI_List *src);
typedef int (*esxVI_List_CastFromAnyTypeFunc) (esxVI_AnyType *anyType,
160
                                               esxVI_List **item);
161
typedef int (*esxVI_List_SerializeFunc) (esxVI_List *item, const char *element,
162
                                         virBufferPtr output);
163
typedef int (*esxVI_List_DeserializeFunc) (xmlNodePtr node, esxVI_List **item);
164

165 166
int esxVI_List_Append(esxVI_List **list, esxVI_List *item);
int esxVI_List_DeepCopy(esxVI_List **destList, esxVI_List *srcList,
167 168
                        esxVI_List_DeepCopyFunc deepCopyFunc,
                        esxVI_List_FreeFunc freeFunc);
169
int esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list,
170 171
                               esxVI_List_CastFromAnyTypeFunc castFromAnyTypeFunc,
                               esxVI_List_FreeFunc freeFunc);
172
int esxVI_List_Serialize(esxVI_List *list, const char *element,
173
                         virBufferPtr output,
174
                         esxVI_List_SerializeFunc serializeFunc);
175
int esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list,
176 177 178 179 180 181 182
                           esxVI_List_DeserializeFunc deserializeFunc,
                           esxVI_List_FreeFunc freeFunc);



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Utility and Convenience Functions
183 184 185 186
 *
 * Function naming scheme:
 *  - 'lookup' functions query the ESX or vCenter for information
 *  - 'get' functions get information from a local object
187 188
 */

189
int esxVI_Alloc(void **ptrptr, size_t size);
190 191

int esxVI_BuildFullTraversalSpecItem
192 193
      (esxVI_SelectionSpec **fullTraversalSpecList, const char *name,
       const char *type, const char *path, const char *selectSetNames);
194

195
int esxVI_BuildFullTraversalSpecList
196
      (esxVI_SelectionSpec **fullTraversalSpecList);
197

198
int esxVI_EnsureSession(esxVI_Context *ctx);
199

200
int esxVI_LookupObjectContentByType(esxVI_Context *ctx,
201 202 203 204 205
                                    esxVI_ManagedObjectReference *root,
                                    const char *type,
                                    esxVI_String *propertyNameList,
                                    esxVI_Boolean recurse,
                                    esxVI_ObjectContent **objectContentList);
206

207
int esxVI_GetManagedEntityStatus
208
      (esxVI_ObjectContent *objectContent, const char *propertyName,
209 210
       esxVI_ManagedEntityStatus *managedEntityStatus);

211
int esxVI_GetVirtualMachinePowerState
212
      (esxVI_ObjectContent *virtualMachine,
213 214
       esxVI_VirtualMachinePowerState *powerState);

215
int esxVI_GetVirtualMachineQuestionInfo
216
      (esxVI_ObjectContent *virtualMachine,
217 218
       esxVI_VirtualMachineQuestionInfo **questionInfo);

219
int esxVI_LookupNumberOfDomainsByPowerState
220 221
      (esxVI_Context *ctx, esxVI_VirtualMachinePowerState powerState,
       esxVI_Boolean inverse);
222

223
int esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
224 225
                                    int *id, char **name, unsigned char *uuid);

226
int esxVI_LookupResourcePoolByHostSystem
227
      (esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
228
       esxVI_ManagedObjectReference **resourcePool);
M
Matthias Bolte 已提交
229

230
int esxVI_LookupHostSystemByIp(esxVI_Context *ctx, const char *ipAddress,
M
Matthias Bolte 已提交
231
                               esxVI_String *propertyNameList,
232 233
                               esxVI_ObjectContent **hostSystem);

234
int esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx,
235 236
                                     const unsigned char *uuid,
                                     esxVI_String *propertyNameList,
237
                                     esxVI_ObjectContent **virtualMachine,
M
Matthias Bolte 已提交
238
                                     esxVI_Occurrence occurrence);
239

240 241 242 243 244
int esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
                                     esxVI_String *propertyNameList,
                                     esxVI_ObjectContent **virtualMachine,
                                     esxVI_Occurrence occurrence);

245
int esxVI_LookupVirtualMachineByUuidAndPrepareForTask
246
      (esxVI_Context *ctx, const unsigned char *uuid,
247 248 249
       esxVI_String *propertyNameList, esxVI_ObjectContent **virtualMachine,
       esxVI_Boolean autoAnswer);

250
int esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
M
Matthias Bolte 已提交
251 252
                                esxVI_String *propertyNameList,
                                esxVI_ObjectContent **datastore,
M
Matthias Bolte 已提交
253
                                esxVI_Occurrence occurrence);
M
Matthias Bolte 已提交
254

255
int esxVI_LookupTaskInfoByTask(esxVI_Context *ctx,
256 257 258 259
                               esxVI_ManagedObjectReference *task,
                               esxVI_TaskInfo **taskInfo);

int esxVI_LookupPendingTaskInfoListByVirtualMachine
260
      (esxVI_Context *ctx, esxVI_ObjectContent *virtualMachine,
261 262
       esxVI_TaskInfo **pendingTaskInfoList);

263
int esxVI_LookupAndHandleVirtualMachineQuestion(esxVI_Context *ctx,
264 265 266 267
                                                const unsigned char *uuid,
                                                esxVI_Boolean autoAnswer);

int esxVI_HandleVirtualMachineQuestion
268
      (esxVI_Context *ctx,
269 270 271 272
       esxVI_ManagedObjectReference *virtualMachine,
       esxVI_VirtualMachineQuestionInfo *questionInfo,
       esxVI_Boolean autoAnswer);

273
int esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
274
                                esxVI_ManagedObjectReference *task,
275 276
                                const unsigned char *virtualMachineUuid,
                                esxVI_Boolean autoAnswer,
277 278 279
                                esxVI_TaskInfoState *finalState);

#endif /* __ESX_VI_H__ */