esx_vi.h 11.6 KB
Newer Older
1 2 3 4

/*
 * esx_vi.h: client for the VMware VI API 2.5 to manage ESX hosts
 *
5
 * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte@googlemail.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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
# include "internal.h"
31
# include "virterror_internal.h"
32 33
# include "datatypes.h"
# include "esx_vi_types.h"
34

35 36 37 38 39 40 41 42


# define ESX_VI_ERROR(code, ...)                                              \
    virReportErrorHelper(NULL, VIR_FROM_ESX, code, __FILE__, __FUNCTION__,    \
                         __LINE__, __VA_ARGS__)



43 44
typedef enum _esxVI_APIVersion esxVI_APIVersion;
typedef enum _esxVI_ProductVersion esxVI_ProductVersion;
M
Matthias Bolte 已提交
45
typedef enum _esxVI_Occurrence esxVI_Occurrence;
46
typedef struct _esxVI_Context esxVI_Context;
47
typedef struct _esxVI_Response esxVI_Response;
48 49 50 51 52 53
typedef struct _esxVI_Enumeration esxVI_Enumeration;
typedef struct _esxVI_EnumerationValue esxVI_EnumerationValue;
typedef struct _esxVI_List esxVI_List;



54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
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 已提交
70 71 72
enum _esxVI_Occurrence {
    esxVI_Occurrence_Undefined = 0,
    esxVI_Occurrence_RequiredItem,
73
    esxVI_Occurrence_RequiredList,
M
Matthias Bolte 已提交
74
    esxVI_Occurrence_OptionalItem,
75
    esxVI_Occurrence_OptionalList,
76
    esxVI_Occurrence_None
77 78
};

79 80


81 82 83 84 85 86
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Context
 */

struct _esxVI_Context {
    char *url;
M
Matthias Bolte 已提交
87
    char *ipAddress;
88 89
    CURL *curl_handle;
    struct curl_slist *curl_headers;
90
    char curl_error[CURL_ERROR_SIZE];
91 92 93 94
    virMutex curl_lock;
    char *username;
    char *password;
    esxVI_ServiceContent *service;
95 96
    esxVI_APIVersion apiVersion;
    esxVI_ProductVersion productVersion;
97 98 99 100 101 102 103
    esxVI_UserSession *session;
    esxVI_ManagedObjectReference *datacenter;
    esxVI_ManagedObjectReference *vmFolder;
    esxVI_ManagedObjectReference *hostFolder;
    esxVI_SelectionSpec *fullTraversalSpecList;
};

104
int esxVI_Context_Alloc(esxVI_Context **ctx);
105
void esxVI_Context_Free(esxVI_Context **ctx);
106 107 108 109 110 111 112 113 114 115
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);
116 117 118 119



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
120
 * Response
121 122
 */

123
struct _esxVI_Response {
124
    int responseCode;                                 /* required */
125
    char *content;                                    /* required */
126
    xmlDocPtr document;                               /* optional */
127
    xmlNodePtr node;                                  /* optional, list */
128 129
};

130
int esxVI_Response_Alloc(esxVI_Response **response);
131
void esxVI_Response_Free(esxVI_Response **response);
132 133 134 135 136 137 138 139 140 141 142 143 144



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

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

struct _esxVI_Enumeration {
145
    esxVI_Type type;
146 147 148
    esxVI_EnumerationValue values[10];
};

149
int esxVI_Enumeration_CastFromAnyType(const esxVI_Enumeration *enumeration,
150
                                      esxVI_AnyType *anyType, int *value);
151
int esxVI_Enumeration_Serialize(const esxVI_Enumeration *enumeration,
152
                                int value, const char *element,
153
                                virBufferPtr output);
154
int esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration,
155 156 157 158 159 160 161 162 163 164 165 166 167
                                  xmlNodePtr node, int *value);



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

struct _esxVI_List {
    esxVI_List *_next;
};

typedef int (*esxVI_List_FreeFunc) (esxVI_List **item);
168 169
typedef int (*esxVI_List_DeepCopyFunc) (esxVI_List **dest, esxVI_List *src);
typedef int (*esxVI_List_CastFromAnyTypeFunc) (esxVI_AnyType *anyType,
170
                                               esxVI_List **item);
171
typedef int (*esxVI_List_SerializeFunc) (esxVI_List *item, const char *element,
172
                                         virBufferPtr output);
173
typedef int (*esxVI_List_DeserializeFunc) (xmlNodePtr node, esxVI_List **item);
174

175 176
int esxVI_List_Append(esxVI_List **list, esxVI_List *item);
int esxVI_List_DeepCopy(esxVI_List **destList, esxVI_List *srcList,
177 178
                        esxVI_List_DeepCopyFunc deepCopyFunc,
                        esxVI_List_FreeFunc freeFunc);
179
int esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list,
180 181
                               esxVI_List_CastFromAnyTypeFunc castFromAnyTypeFunc,
                               esxVI_List_FreeFunc freeFunc);
182
int esxVI_List_Serialize(esxVI_List *list, const char *element,
183
                         virBufferPtr output,
184
                         esxVI_List_SerializeFunc serializeFunc);
185
int esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list,
186 187 188 189 190 191 192
                           esxVI_List_DeserializeFunc deserializeFunc,
                           esxVI_List_FreeFunc freeFunc);



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Utility and Convenience Functions
193 194 195 196
 *
 * Function naming scheme:
 *  - 'lookup' functions query the ESX or vCenter for information
 *  - 'get' functions get information from a local object
197 198
 */

199
int esxVI_Alloc(void **ptrptr, size_t size);
200 201

int esxVI_BuildFullTraversalSpecItem
202 203
      (esxVI_SelectionSpec **fullTraversalSpecList, const char *name,
       const char *type, const char *path, const char *selectSetNames);
204

205
int esxVI_BuildFullTraversalSpecList
206
      (esxVI_SelectionSpec **fullTraversalSpecList);
207

208
int esxVI_EnsureSession(esxVI_Context *ctx);
209

210
int esxVI_LookupObjectContentByType(esxVI_Context *ctx,
211 212 213 214 215
                                    esxVI_ManagedObjectReference *root,
                                    const char *type,
                                    esxVI_String *propertyNameList,
                                    esxVI_Boolean recurse,
                                    esxVI_ObjectContent **objectContentList);
216

217
int esxVI_GetManagedEntityStatus
218
      (esxVI_ObjectContent *objectContent, const char *propertyName,
219 220
       esxVI_ManagedEntityStatus *managedEntityStatus);

221
int esxVI_GetVirtualMachinePowerState
222
      (esxVI_ObjectContent *virtualMachine,
223 224
       esxVI_VirtualMachinePowerState *powerState);

225
int esxVI_GetVirtualMachineQuestionInfo
226
      (esxVI_ObjectContent *virtualMachine,
227 228
       esxVI_VirtualMachineQuestionInfo **questionInfo);

229
int esxVI_LookupNumberOfDomainsByPowerState
230 231
      (esxVI_Context *ctx, esxVI_VirtualMachinePowerState powerState,
       esxVI_Boolean inverse);
232

233
int esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
234 235
                                    int *id, char **name, unsigned char *uuid);

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
int esxVI_GetNumberOfSnapshotTrees
      (esxVI_VirtualMachineSnapshotTree *snapshotTreeList);

int esxVI_GetSnapshotTreeNames
      (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, char **names,
       int nameslen);

int esxVI_GetSnapshotTreeByName
      (esxVI_VirtualMachineSnapshotTree *snapshotTreeList, const char *name,
       esxVI_VirtualMachineSnapshotTree **snapshotTree,
       esxVI_VirtualMachineSnapshotTree **snapshotTreeParent,
       esxVI_Occurrence occurrence);

int esxVI_GetSnapshotTreeBySnapshot
      (esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
       esxVI_ManagedObjectReference *snapshot,
       esxVI_VirtualMachineSnapshotTree **snapshotTree);

254
int esxVI_LookupResourcePoolByHostSystem
255
      (esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
256
       esxVI_ManagedObjectReference **resourcePool);
M
Matthias Bolte 已提交
257

258
int esxVI_LookupHostSystemByIp(esxVI_Context *ctx, const char *ipAddress,
M
Matthias Bolte 已提交
259
                               esxVI_String *propertyNameList,
260 261
                               esxVI_ObjectContent **hostSystem);

262
int esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx,
263 264
                                     const unsigned char *uuid,
                                     esxVI_String *propertyNameList,
265
                                     esxVI_ObjectContent **virtualMachine,
M
Matthias Bolte 已提交
266
                                     esxVI_Occurrence occurrence);
267

268 269 270 271 272
int esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
                                     esxVI_String *propertyNameList,
                                     esxVI_ObjectContent **virtualMachine,
                                     esxVI_Occurrence occurrence);

273
int esxVI_LookupVirtualMachineByUuidAndPrepareForTask
274
      (esxVI_Context *ctx, const unsigned char *uuid,
275 276 277
       esxVI_String *propertyNameList, esxVI_ObjectContent **virtualMachine,
       esxVI_Boolean autoAnswer);

278
int esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
M
Matthias Bolte 已提交
279 280
                                esxVI_String *propertyNameList,
                                esxVI_ObjectContent **datastore,
M
Matthias Bolte 已提交
281
                                esxVI_Occurrence occurrence);
M
Matthias Bolte 已提交
282

283
int esxVI_LookupTaskInfoByTask(esxVI_Context *ctx,
284 285 286 287
                               esxVI_ManagedObjectReference *task,
                               esxVI_TaskInfo **taskInfo);

int esxVI_LookupPendingTaskInfoListByVirtualMachine
288
      (esxVI_Context *ctx, esxVI_ObjectContent *virtualMachine,
289 290
       esxVI_TaskInfo **pendingTaskInfoList);

291
int esxVI_LookupAndHandleVirtualMachineQuestion(esxVI_Context *ctx,
292 293 294
                                                const unsigned char *uuid,
                                                esxVI_Boolean autoAnswer);

295 296 297 298 299 300 301 302 303
int esxVI_LookupRootSnapshotTreeList
      (esxVI_Context *ctx, const unsigned char *virtualMachineUuid,
       esxVI_VirtualMachineSnapshotTree **rootSnapshotTreeList);

int esxVI_LookupCurrentSnapshotTree
      (esxVI_Context *ctx, const unsigned char *virtualMachineUuid,
       esxVI_VirtualMachineSnapshotTree **currentSnapshotTree,
       esxVI_Occurrence occurrence);

304
int esxVI_HandleVirtualMachineQuestion
305
      (esxVI_Context *ctx,
306 307 308 309
       esxVI_ManagedObjectReference *virtualMachine,
       esxVI_VirtualMachineQuestionInfo *questionInfo,
       esxVI_Boolean autoAnswer);

310
int esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
311
                                esxVI_ManagedObjectReference *task,
312 313
                                const unsigned char *virtualMachineUuid,
                                esxVI_Boolean autoAnswer,
314 315 316
                                esxVI_TaskInfoState *finalState);

#endif /* __ESX_VI_H__ */