esx_vi.h 10.7 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 24 25 26 27 28 29 30 31 32 33

/*
 * 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"

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 143
                                int value, const char *element,
                                virBufferPtr output, esxVI_Boolean required);
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 163
                                         virBufferPtr output,
                                         esxVI_Boolean required);
164
typedef int (*esxVI_List_DeserializeFunc) (xmlNodePtr node, esxVI_List **item);
165

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



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

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

192
int esxVI_CheckSerializationNecessity(const char *element,
193
                                      esxVI_Boolean required);
194 195

int esxVI_BuildFullTraversalSpecItem
196 197
      (esxVI_SelectionSpec **fullTraversalSpecList, const char *name,
       const char *type, const char *path, const char *selectSetNames);
198

199
int esxVI_BuildFullTraversalSpecList
200
      (esxVI_SelectionSpec **fullTraversalSpecList);
201

202
int esxVI_EnsureSession(esxVI_Context *ctx);
203

204
int esxVI_LookupObjectContentByType(esxVI_Context *ctx,
205 206 207 208 209
                                    esxVI_ManagedObjectReference *root,
                                    const char *type,
                                    esxVI_String *propertyNameList,
                                    esxVI_Boolean recurse,
                                    esxVI_ObjectContent **objectContentList);
210

211
int esxVI_GetManagedEntityStatus
212
      (esxVI_ObjectContent *objectContent, const char *propertyName,
213 214
       esxVI_ManagedEntityStatus *managedEntityStatus);

215
int esxVI_GetVirtualMachinePowerState
216
      (esxVI_ObjectContent *virtualMachine,
217 218
       esxVI_VirtualMachinePowerState *powerState);

219
int esxVI_GetVirtualMachineQuestionInfo
220
      (esxVI_ObjectContent *virtualMachine,
221 222
       esxVI_VirtualMachineQuestionInfo **questionInfo);

223
int esxVI_LookupNumberOfDomainsByPowerState
224 225
      (esxVI_Context *ctx, esxVI_VirtualMachinePowerState powerState,
       esxVI_Boolean inverse);
226

227
int esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
228 229
                                    int *id, char **name, unsigned char *uuid);

230
int esxVI_LookupResourcePoolByHostSystem
231
      (esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
232
       esxVI_ManagedObjectReference **resourcePool);
M
Matthias Bolte 已提交
233

234
int esxVI_LookupHostSystemByIp(esxVI_Context *ctx, const char *ipAddress,
M
Matthias Bolte 已提交
235
                               esxVI_String *propertyNameList,
236 237
                               esxVI_ObjectContent **hostSystem);

238
int esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx,
239 240
                                     const unsigned char *uuid,
                                     esxVI_String *propertyNameList,
241
                                     esxVI_ObjectContent **virtualMachine,
M
Matthias Bolte 已提交
242
                                     esxVI_Occurrence occurrence);
243

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

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

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

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

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

266 267
int esxVI_StartVirtualMachineTask(esxVI_Context *ctx, const char *name,
                                  const char *request,
268 269 270
                                  esxVI_ManagedObjectReference **task);

int esxVI_StartSimpleVirtualMachineTask
271
      (esxVI_Context *ctx, const char *name,
272 273 274 275
       esxVI_ManagedObjectReference *virtualMachine,
       esxVI_ManagedObjectReference **task);

int esxVI_SimpleVirtualMachineMethod
276
      (esxVI_Context *ctx, const char *name,
277 278
       esxVI_ManagedObjectReference *virtualMachine);

279
int esxVI_HandleVirtualMachineQuestion
280
      (esxVI_Context *ctx,
281 282 283 284
       esxVI_ManagedObjectReference *virtualMachine,
       esxVI_VirtualMachineQuestionInfo *questionInfo,
       esxVI_Boolean autoAnswer);

285
int esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
286
                                esxVI_ManagedObjectReference *task,
287 288
                                const unsigned char *virtualMachineUuid,
                                esxVI_Boolean autoAnswer,
289 290 291
                                esxVI_TaskInfoState *finalState);

#endif /* __ESX_VI_H__ */