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 80 81 82 83
    CURL *curl_handle;
    struct curl_slist *curl_headers;
    virMutex curl_lock;
    char *username;
    char *password;
    esxVI_ServiceContent *service;
84 85
    esxVI_APIVersion apiVersion;
    esxVI_ProductVersion productVersion;
86 87 88 89 90 91 92
    esxVI_UserSession *session;
    esxVI_ManagedObjectReference *datacenter;
    esxVI_ManagedObjectReference *vmFolder;
    esxVI_ManagedObjectReference *hostFolder;
    esxVI_SelectionSpec *fullTraversalSpecList;
};

93
int esxVI_Context_Alloc(esxVI_Context **ctx);
94
void esxVI_Context_Free(esxVI_Context **ctx);
95 96 97 98 99 100 101 102 103 104
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);
105 106 107 108



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
109
 * Response
110 111
 */

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

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



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

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

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

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



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

struct _esxVI_List {
    esxVI_List *_next;
};

typedef int (*esxVI_List_FreeFunc) (esxVI_List **item);
157 158
typedef int (*esxVI_List_DeepCopyFunc) (esxVI_List **dest, esxVI_List *src);
typedef int (*esxVI_List_CastFromAnyTypeFunc) (esxVI_AnyType *anyType,
159
                                               esxVI_List **item);
160
typedef int (*esxVI_List_SerializeFunc) (esxVI_List *item, const char *element,
161 162
                                         virBufferPtr output,
                                         esxVI_Boolean required);
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 173
int esxVI_List_Serialize(esxVI_List *list, const char *element,
                         virBufferPtr output, esxVI_Boolean required,
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_CheckSerializationNecessity(const char *element,
192
                                      esxVI_Boolean required);
193 194

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

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

201
int esxVI_EnsureSession(esxVI_Context *ctx);
202

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#endif /* __ESX_VI_H__ */