[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] Interface driver and ESX support



2009/9/9 Shahar Klein <shaharklein yahoo com>:
> I think I understand the mechanism of the VI API
> and the way esx_vi.c is using it
> the surounding is a bit more complex for me
> so
> can you provide the framework?
> I mean
> can you put in the esx_interface_driver.c and h
> and the registration etc...
> and also putting it all into the auto make mechanism(I should learn this
> sometime...)
> I will put in the content into the functions
> for the time being I am registering the esx_driver as the interface driver
> so I can get a fill of it

Well, if you want to give it a try, here you go.

I attached a patch that adds a basic interface driver with open and
close method. The interface driver doesn't need it's own private
driver struct, it just uses the same context already opened by the
main ESX driver.

Listing the available physical NICs should be easy. You'll need to
obtain the HostSystem object and query for its config.network.pnic
property. This is a list of PhysicalNic objects. You'll need to add a
mapping for the PhysicalNic type to the esx_vi_types.[ch]. There is
plenty of examples in the current ESX driver how to do all these
things.

Matthias
diff --git a/src/Makefile.am b/src/Makefile.am
index 628edc5..305f2fd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -165,6 +165,7 @@ ONE_DRIVER_SOURCES =						\
 
 ESX_DRIVER_SOURCES =						\
 		esx/esx_driver.c esx/esx_driver.h		\
+		esx/esx_interface_driver.c esx/esx_interface_driver.h		\
 		esx/esx_util.c esx/esx_util.h			\
 		esx/esx_vi.c esx/esx_vi.h			\
 		esx/esx_vi_methods.c esx/esx_vi_methods.h	\
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 8d1af71..b1dd12c 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -41,6 +41,7 @@
 #include "logging.h"
 #include "uuid.h"
 #include "esx_driver.h"
+#include "esx_interface_driver.h"
 #include "esx_vi.h"
 #include "esx_vi_methods.h"
 #include "esx_util.h"
@@ -54,17 +55,6 @@
 
 static int esxDomainGetMaxVcpus(virDomainPtr domain);
 
-typedef struct _esxPrivate {
-    esxVI_Context *host;
-    esxVI_Context *vCenter;
-    int phantom; // boolean
-    virCapsPtr caps;
-    char *transport;
-    int32_t maxVcpus;
-    esxVI_Boolean supportsVMotion;
-    int32_t usedCpuTimeCounterId;
-} esxPrivate;
-
 
 
 static virCapsPtr
@@ -3095,7 +3085,13 @@ static virDriver esxDriver = {
 int
 esxRegister(void)
 {
-    virRegisterDriver(&esxDriver);
+    if (virRegisterDriver(&esxDriver) < 0) {
+        return -1;
+    }
+
+    if (esxInterfaceRegister() < 0) {
+        return -1;
+    }
 
     return 0;
 }
diff --git a/src/esx/esx_driver.h b/src/esx/esx_driver.h
index 85f4b32..a378d34 100644
--- a/src/esx/esx_driver.h
+++ b/src/esx/esx_driver.h
@@ -24,6 +24,23 @@
 #ifndef __ESX_DRIVER_H__
 #define __ESX_DRIVER_H__
 
+#include "internal.h"
+#include "capabilities.h"
+#include "esx_vi.h"
+
+typedef struct _esxPrivate {
+    esxVI_Context *host;
+    esxVI_Context *vCenter;
+    int phantom; // boolean
+    virCapsPtr caps;
+    char *transport;
+    int32_t maxVcpus;
+    esxVI_Boolean supportsVMotion;
+    int32_t usedCpuTimeCounterId;
+} esxPrivate;
+
+
+
 int esxRegister(void);
 
 #endif /* __ESX_DRIVER_H__ */
diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c
new file mode 100644
index 0000000..9deaef8
--- /dev/null
+++ b/src/esx/esx_interface_driver.c
@@ -0,0 +1,95 @@
+
+/*
+ * esx_interface_driver.h: interface driver methods for managing VMware ESX
+ *                         hosts interfaces
+ *
+ * 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
+ *
+ */
+
+#include <config.h>
+
+#include "internal.h"
+#include "virterror_internal.h"
+#include "util.h"
+#include "memory.h"
+#include "logging.h"
+#include "uuid.h"
+#include "esx_driver.h"
+#include "esx_interface_driver.h"
+#include "esx_vi.h"
+#include "esx_vi_methods.h"
+#include "esx_util.h"
+
+#define VIR_FROM_THIS VIR_FROM_ESX
+
+#define ESX_ERROR(conn, code, fmt...)                                         \
+    virReportErrorHelper(conn, VIR_FROM_ESX, code, __FILE__, __FUNCTION__,    \
+                         __LINE__, fmt)
+
+
+
+static virDrvOpenStatus
+esxInterfaceOpen(virConnectPtr conn,
+                 virConnectAuthPtr auth ATTRIBUTE_UNUSED,
+                 int flags ATTRIBUTE_UNUSED)
+{
+    if (STRNEQ(conn->driver->name, "ESX")) {
+        return VIR_DRV_OPEN_DECLINED;
+    }
+
+    conn->interfacePrivateData = conn->privateData;
+
+    return VIR_DRV_OPEN_SUCCESS;
+}
+
+
+
+static int
+esxInterfaceClose(virConnectPtr conn)
+{
+    conn->interfacePrivateData = NULL;
+
+    return 0;
+}
+
+
+
+static virInterfaceDriver esxInterfaceDriver = {
+    "ESX",                                 /* name */
+    esxInterfaceOpen,                      /* open */
+    esxInterfaceClose,                     /* close */
+    NULL,                                  /* numOfInterfaces */
+    NULL,                                  /* listInterfaces */
+    NULL,                                  /* numOfDefinedInterfaces */
+    NULL,                                  /* listDefinedInterfaces */
+    NULL,                                  /* interfaceLookupByName */
+    NULL,                                  /* interfaceLookupByMACString */
+    NULL,                                  /* interfaceGetXMLDesc */
+    NULL,                                  /* interfaceDefineXML */
+    NULL,                                  /* interfaceUndefine */
+    NULL,                                  /* interfaceCreate */
+    NULL,                                  /* interfaceDestroy */
+};
+
+
+
+int
+esxInterfaceRegister(void)
+{
+    return virRegisterInterfaceDriver(&esxInterfaceDriver);
+}
diff --git a/src/esx/esx_interface_driver.h b/src/esx/esx_interface_driver.h
new file mode 100644
index 0000000..b9eec24
--- /dev/null
+++ b/src/esx/esx_interface_driver.h
@@ -0,0 +1,29 @@
+
+/*
+ * esx_interface_driver.h: interface driver methods for managing VMware ESX
+ *                         hosts interfaces
+ *
+ * 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_INTERFACE_DRIVER_H__
+#define __ESX_INTERFACE_DRIVER_H__
+
+int esxInterfaceRegister(void);
+
+#endif /* __ESX_INTERFACE_DRIVER_H__ */

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]