From: jbarkely <jbarkley(a)willo.(none)>
---
src/esx/esx_network_driver.c | 181 +++++++++++++++++++++++++++++++++++++++-
src/esx/esx_vi.c | 104 ++++++++++++++++++++++-
src/esx/esx_vi.h | 9 ++
src/esx/esx_vi_generator.input | 78 +++++++++++++++++
4 files changed, 366 insertions(+), 6 deletions(-)
diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index a64bb8e..c4cc7b4 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -34,6 +34,7 @@
#include "esx_vi.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
+#include "md5.h"
#define VIR_FROM_THIS VIR_FROM_ESX
@@ -63,18 +64,190 @@ esxNetworkClose(virConnectPtr conn)
return 0;
}
+static virNetworkPtr
+esxNetworkLookupByName(virConnectPtr conn, const char *name) {
+ //esxPrivate *priv = conn->networkPrivateData;
+ esxPrivate *priv = conn->networkPrivateData;
+ esxVI_String *propertyNameList = NULL;
+ esxVI_ObjectContent *network = NULL;
+ virNetworkPtr virNetwork = NULL;
+ unsigned char uuid[VIR_UUID_BUFLEN];
+ unsigned char md5[MD5_DIGEST_SIZE]; /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
+
+ if (esxVI_EnsureSession(priv->primary) < 0) {
+ return NULL;
+ }
+
+ if (esxVI_LookupNetworkByName(priv->primary, name, propertyNameList,
+ &network,
+ esxVI_Occurrence_OptionalItem) < 0) {
+ goto cleanup;
+ }
+
+ if (NULL==network) {
+ // raise error
+ ESX_ERROR(VIR_ERR_NO_NETWORK, _("No network with name '%s'"),
name);
+ goto cleanup;
+
+ }
+
+ char *name_candidate = NULL;
+ esxVI_GetStringValue(network, "name", &name_candidate,
esxVI_Occurrence_OptionalItem);
+
+ md5_buffer(name, strlen(name), md5);
+ virNetwork = virGetNetwork(conn, name, md5);
+
+ cleanup:
+ esxVI_String_Free(&propertyNameList);
+ //esxVI_ObjectContent_Free(&network);
+// printf("virNetwork=%s\n", virNetwork->name);
+ return virNetwork;
+}
+
+static int
+esxListNetworks(virConnectPtr conn, char **const names, int nnames)
+{
+ //setup
+ bool success = false;
+ esxPrivate *priv = conn->networkPrivateData;
+ esxVI_String *propertyNameList = NULL;
+ esxVI_DynamicProperty *dynamicProperty = NULL;
+ esxVI_ObjectContent *networkList = NULL;
+ esxVI_ObjectContent *network = NULL;
+ int count = 0;
+ int i;
+
+ //check args
+ if (names == NULL || nnames < 0) {
+ ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (nnames == 0) {
+ return 0;
+ }
+
+ //check connection
+ if (esxVI_EnsureSession(priv->primary) < 0) {
+ return -1;
+ }
+
+ //get network(s)
+ if (esxVI_String_AppendValueToList(&propertyNameList,
+ "summary.name") < 0 ||
+ esxVI_LookupNetworkList(priv->primary, propertyNameList,
+ &networkList) < 0) {
+ goto cleanup;
+ }
+
+ for (network = networkList; network != NULL;
+ network = network->_next) {
+ for (dynamicProperty = network->propSet; dynamicProperty != NULL;
+ dynamicProperty = dynamicProperty->_next) {
+ if (STREQ(dynamicProperty->name, "summary.name")) {
+ if (esxVI_AnyType_ExpectType(dynamicProperty->val,
+ esxVI_Type_String) < 0) {
+ goto cleanup;
+ }
+
+ names[count] = strdup(dynamicProperty->val->string);
+
+ if (names[count] == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ ++count;
+ break;
+ } else {
+ VIR_WARN("Unexpected '%s' property",
dynamicProperty->name);
+ }
+ }
+ }
+
+ success = true;
+
+ //cleanup
+ cleanup:
+ if (! success) {
+ for (i = 0; i < count; ++i) {
+ VIR_FREE(names[i]);
+ }
+
+ count = -1;
+ }
+
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&networkList);
+
+ return count;
+}
+
+static int
+esxNumOfNetworks(virConnectPtr conn)
+{
+ //setup
+ esxPrivate *priv = conn->networkPrivateData;
+ esxVI_String *propertyNameList = NULL;
+ esxVI_DynamicProperty *dynamicProperty = NULL;
+ esxVI_ObjectContent *networkList = NULL;
+ esxVI_ObjectContent *network = NULL;
+ int count = 0;
+ int i;
+
+ //check connection
+ if (esxVI_EnsureSession(priv->primary) < 0) {
+ return -1;
+ }
+
+ //get network(s)
+ if (esxVI_String_AppendValueToList(&propertyNameList,
+ "summary.name") < 0 ||
+ esxVI_LookupNetworkList(priv->primary, propertyNameList,
+ &networkList) < 0) {
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&networkList);
+
+ return -1;
+ }
+
+ for (network = networkList; network != NULL;
+ network = network->_next) {
+ for (dynamicProperty = network->propSet; dynamicProperty != NULL;
+ dynamicProperty = dynamicProperty->_next) {
+ if (STREQ(dynamicProperty->name, "summary.name")) {
+ ++count;
+ break;
+ } else {
+ VIR_WARN("Unexpected '%s' property",
dynamicProperty->name);
+ }
+ }
+ }
+
+
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&networkList);
+
+ return count;
+}
+
+static int esxNumOfDefinedNetworks(virConnectPtr conn)
+{
+ printf("JB-BUG C\n");
+ return 8;
+}
static virNetworkDriver esxNetworkDriver = {
"ESX", /* name */
esxNetworkOpen, /* open */
esxNetworkClose, /* close */
- NULL, /* numOfNetworks */
- NULL, /* listNetworks */
- NULL, /* numOfDefinedNetworks */
+ esxNumOfNetworks, /* numOfNetworks */
+ esxListNetworks, /* listNetworks */
+ esxNumOfDefinedNetworks, /* numOfDefinedNetworks */
NULL, /* listDefinedNetworks */
NULL, /* networkLookupByUUID */
- NULL, /* networkLookupByName */
+ esxNetworkLookupByName, /* networkLookupByName */
NULL, /* networkCreateXML */
NULL, /* networkDefineXML */
NULL, /* networkUndefine */
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 7446ec5..509cf07 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -109,6 +109,7 @@ ESX_VI__TEMPLATE__FREE(Context,
esxVI_SelectionSpec_Free(&item->selectSet_hostSystemToParent);
esxVI_SelectionSpec_Free(&item->selectSet_hostSystemToVm);
esxVI_SelectionSpec_Free(&item->selectSet_hostSystemToDatastore);
+ esxVI_SelectionSpec_Free(&item->selectSet_hostSystemToNetwork);
esxVI_SelectionSpec_Free(&item->selectSet_computeResourceToHost);
esxVI_SelectionSpec_Free(&item->selectSet_computeResourceToParentToParent);
});
@@ -1483,6 +1484,13 @@ esxVI_BuildSelectSetCollection(esxVI_Context *ctx)
return -1;
}
+ /* HostSystem -> network (Network) */
+ if (esxVI_BuildSelectSet(&ctx->selectSet_hostSystemToNetwork,
+ "hostSystemToNetwork",
+ "HostSystem", "network", NULL) < 0)
{
+ return -1;
+ }
+
/* Folder -> parent (Folder, Datacenter) */
if (esxVI_BuildSelectSet(&ctx->selectSet_computeResourceToParentToParent,
"managedEntityToParent",
@@ -1543,9 +1551,13 @@ esxVI_EnsureSession(esxVI_Context *ctx)
* Query the session manager for the current session of this connection
* and re-login if there is no current session for this connection.
*/
+
if (esxVI_String_AppendValueToList(&propertyNameList,
- "currentSession") < 0 ||
- esxVI_LookupObjectContentByType(ctx, ctx->service->sessionManager,
+ "currentSession") < 0) {
+ goto cleanup;
+ }
+
+ if (esxVI_LookupObjectContentByType(ctx, ctx->service->sessionManager,
"SessionManager",
propertyNameList,
&sessionManager,
esxVI_Occurrence_RequiredItem) < 0) {
@@ -1649,6 +1661,8 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
objectSpec->selectSet = ctx->selectSet_hostSystemToVm;
} else if (STREQ(type, "Datastore")) {
objectSpec->selectSet = ctx->selectSet_hostSystemToDatastore;
+ } else if (STREQ(type, "Network")) {
+ objectSpec->selectSet = ctx->selectSet_hostSystemToNetwork;
} else {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Invalid lookup of '%s' from
'%s'"),
@@ -2474,6 +2488,92 @@ esxVI_LookupDatastoreList(esxVI_Context *ctx, esxVI_String
*propertyNameList,
esxVI_Occurrence_OptionalList);
}
+int
+esxVI_LookupNetworkList(esxVI_Context *ctx,
+ esxVI_String *propertyNameList,
+ esxVI_ObjectContent **networkList)
+{
+ return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
+ "Network", propertyNameList,
+ networkList,
+ esxVI_Occurrence_OptionalList);
+}
+
+int
+esxVI_LookupNetworkByName(esxVI_Context *ctx, const char *name,
+ esxVI_String *propertyNameList,
+ esxVI_ObjectContent **network,
+ esxVI_Occurrence occurrence)
+{
+ int result = -1;
+ esxVI_String *completePropertyNameList = NULL;
+ esxVI_ObjectContent *networkList = NULL;
+ esxVI_ObjectContent *candidate = NULL;
+ char *name_candidate = NULL;
+
+ if (network == NULL || *network != NULL) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid
argument"));
+ return -1;
+ }
+
+
+ if (esxVI_String_DeepCopyList(&completePropertyNameList,
+ propertyNameList) < 0 ||
+ esxVI_String_AppendValueToList(&completePropertyNameList, "name")
< 0 ||
+ esxVI_LookupNetworkList(ctx, completePropertyNameList,
+ &networkList) < 0) {
+ goto cleanup;
+ }
+
+ for (candidate = networkList; candidate != NULL;
+ candidate = candidate->_next) {
+ VIR_FREE(name_candidate);
+
+ /*
+ if (esxVI_GetVirtualMachineIdentity(candidate, NULL, &name_candidate,
+ NULL) < 0) {
+ goto cleanup;
+ }
+ */
+ if (esxVI_GetStringValue(candidate, "name", &name_candidate,
+ esxVI_Occurrence_OptionalItem) < 0) {
+ goto cleanup;
+ }
+
+ if (STRNEQ(name, name_candidate)) {
+ continue;
+ }
+
+ if (esxVI_ObjectContent_DeepCopy(network, candidate) < 0) {
+ goto cleanup;
+ }
+
+ break;
+ }
+
+ /*
+ if (*network == NULL) {
+ if (occurrence == esxVI_Occurrence_OptionalItem) {
+ result = 0;
+
+ goto cleanup;
+ } else {
+ ESX_VI_ERROR(VIR_ERR_NO_NETWORK,
+ _("Could not find network with name '%s'"),
name);
+ goto cleanup;
+ }
+ }
+ */
+
+ result = 0;
+
+ cleanup:
+ esxVI_String_Free(&completePropertyNameList);
+ esxVI_ObjectContent_Free(&networkList);
+ //VIR_FREE(name_candidate);
+
+ return result;
+}
int
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index e150dbf..cbd6068 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -165,6 +165,7 @@ struct _esxVI_Context {
esxVI_SelectionSpec *selectSet_hostSystemToParent;
esxVI_SelectionSpec *selectSet_hostSystemToVm;
esxVI_SelectionSpec *selectSet_hostSystemToDatastore;
+ esxVI_SelectionSpec *selectSet_hostSystemToNetwork;
esxVI_SelectionSpec *selectSet_computeResourceToHost;
esxVI_SelectionSpec *selectSet_computeResourceToParentToParent;
bool hasQueryVirtualDiskUuid;
@@ -367,11 +368,19 @@ int esxVI_LookupVirtualMachineByUuidAndPrepareForTask
int esxVI_LookupDatastoreList(esxVI_Context *ctx, esxVI_String *propertyNameList,
esxVI_ObjectContent **datastoreList);
+int esxVI_LookupNetworkList(esxVI_Context *ctx, esxVI_String *propertyNameList,
+ esxVI_ObjectContent **networkList);
+
int esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
esxVI_String *propertyNameList,
esxVI_ObjectContent **datastore,
esxVI_Occurrence occurrence);
+int esxVI_LookupNetworkByName(esxVI_Context *ctx, const char *name,
+ esxVI_String *propertyNameList,
+ esxVI_ObjectContent **network,
+ esxVI_Occurrence occurrence);
+
int esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx,
const char *absolutePath,
esxVI_String *propertyNameList,
diff --git a/src/esx/esx_vi_generator.input b/src/esx/esx_vi_generator.input
index 44d1d9b..86c4b12 100644
--- a/src/esx/esx_vi_generator.input
+++ b/src/esx/esx_vi_generator.input
@@ -334,6 +334,84 @@ object HostNasVolume extends HostFileSystemVolume
String userName o
end
+object HostNetCapabilities
+end
+
+object HostIpRouteConfig
+end
+
+object HostDnsConfig
+end
+
+object HostIpRouteConfig
+end
+
+object HostNetworkConfig
+end
+
+object HostNetworkInfo
+end
+
+object HostNetworkSystem
+ HostNetCapabilities capabilities rl
+ HostIpRouteConfig consoleIpRuteConfig r
+ HostDnsConfig dnsConfig r
+ HostIpRouteConfig ipRouteConfig r
+ HostNetworkConfig networkConfig r
+ HostNetworkInfo networkInfo r
+end
+
+
+object HostIpRouteConfig
+end
+
+object HostVirtualNic
+end
+
+object HostDhcpService
+end
+
+object HostDnsConfig
+end
+
+object HostNatService
+end
+
+object PhysicalNic
+end
+
+object HostPortGroup
+end
+
+object HostProxySwitch
+end
+
+object HostIpRouteTableInfo
+end
+
+object HostVirtualNic
+end
+
+object HostVirtualSwitch
+end
+
+object HostNetworkInfo
+ Boolean atBootIpV6Enabled r
+ HostIpRouteConfig consoleIpRouteConfig r
+ HostVirtualNic consoleVnic rl
+ HostDhcpService dhcp rl
+ HostDnsConfig dnsConfig r
+ HostIpRouteConfig ipRouteConfig r
+ Boolean ipV6Enabled r
+ HostNatService nat rl
+ PhysicalNic pnic rl
+ HostPortGroup portgroup rl
+ HostProxySwitch proxySwitch rl
+ HostIpRouteTableInfo routeTableInfo r
+ HostVirtualNic vnic rl
+ HostVirtualSwitch vswitch rl
+end
+
object HostScsiDiskPartition
String diskName r
--
1.7.4.1