[Libvirt-cim] [PATCH] (#2) Add ConcreteComponent with NetworkPool support

Dan Smith danms at us.ibm.com
Fri Aug 22 17:52:55 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1219427442 25200
# Node ID 794e7f3b23d0eef1231cab33fc8df85f91d284b1
# Parent  90ac6766de08cb6f0beca7f7c4cba35331ac83a5
(#2) Add ConcreteComponent with NetworkPool support

This adds the ConcreteComponent association, and hooks it up to NetworkPool
for now.  If you have sblim-cmpi-network on your system, this references
the Linux_EthernetPort instance exposed by SBLIM for the bridge device
associated with the network pool.

Note that port_to_netpool() is untested and won't get called by the CIMOM
because we're not registering this association in root/cimv2.  I don't
think it makes much sense for us to do that to support this backwards,
so I'm content to leave this as kinda broken until someone comes up with a
better idea, or complains.

Changes:
 - Match the hypervisor prefix to avoid duplicate results
 - Rename GroupComponent and PartComponent to be more appropriate

Signed-off-by: Dan Smith <danms at us.ibm.com>

diff -r 90ac6766de08 -r 794e7f3b23d0 Makefile.am
--- a/Makefile.am	Wed Aug 20 15:33:36 2008 -0700
+++ b/Makefile.am	Fri Aug 22 10:50:42 2008 -0700
@@ -41,7 +41,8 @@
 	schema/VSMigrationService.mof \
 	schema/VSMigrationSettingData.mof \
 	schema/VirtualSystemSnapshotService.mof \
-	schema/VirtualSystemSnapshotServiceCapabilities.mof
+	schema/VirtualSystemSnapshotServiceCapabilities.mof \
+	schema/ConcreteComponent.mof
 
 INTEROP_MOFS = \
 	schema/ComputerSystem.mof \
@@ -88,7 +89,8 @@
 	schema/ElementConformsToProfile.registration \
 	schema/VSMigrationSettingData.registration \
 	schema/VirtualSystemSnapshotService.registration \
-	schema/VirtualSystemSnapshotServiceCapabilities.registration
+	schema/VirtualSystemSnapshotServiceCapabilities.registration \
+	schema/ConcreteComponent.registration
 
 INTEROP_REGS = \
 	schema/RegisteredProfile.registration \
diff -r 90ac6766de08 -r 794e7f3b23d0 schema/ConcreteComponent.mof
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/ConcreteComponent.mof	Fri Aug 22 10:50:42 2008 -0700
@@ -0,0 +1,5 @@
+// Copyright IBM Corp. 2008
+
+class Xen_ConcreteComponent : CIM_ConcreteComponent { };
+class KVM_ConcreteComponent : CIM_ConcreteComponent { };
+class LXC_ConcreteComponent : CIM_ConcreteComponent { };
diff -r 90ac6766de08 -r 794e7f3b23d0 schema/ConcreteComponent.registration
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/ConcreteComponent.registration	Fri Aug 22 10:50:42 2008 -0700
@@ -0,0 +1,5 @@
+# Copyright IBM Corp. 2008
+# Classname Namespace ProviderName ProviderModule ProviderTypes
+Xen_ConcreteComponent root/virt Virt_ConcreteComponent Virt_ConcreteComponent association
+KVM_ConcreteComponent root/virt Virt_ConcreteComponent Virt_ConcreteComponent association
+KVM_ConcreteComponent root/virt Virt_ConcreteComponent Virt_ConcreteComponent association
diff -r 90ac6766de08 -r 794e7f3b23d0 src/Makefile.am
--- a/src/Makefile.am	Wed Aug 20 15:33:36 2008 -0700
+++ b/src/Makefile.am	Fri Aug 22 10:50:42 2008 -0700
@@ -64,7 +64,8 @@
                        libVirt_ResourceAllocationFromPool.la \
                        libVirt_ElementAllocatedFromPool.la \
                        libVirt_HostedService.la \
-                       libVirt_ElementSettingData.la
+                       libVirt_ElementSettingData.la \
+                       libVirt_ConcreteComponent.la
 
 libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c
 libVirt_ComputerSystem_la_DEPENDENCIES = libVirt_VirtualSystemSnapshotService.la
@@ -186,3 +187,7 @@
 libVirt_VirtualSystemSnapshotServiceCapabilities_la_DEPENDENCIES = 
 libVirt_VirtualSystemSnapshotServiceCapabilities_la_SOURCES = Virt_VirtualSystemSnapshotServiceCapabilities.c
 libVirt_VirtualSystemSnapshotServiceCapabilities_la_LIBADD =
+
+libVirt_ConcreteComponent_la_DEPENDENCIES = libVirt_HostSystem.la libVirt_DevicePool.la
+libVirt_ConcreteComponent_la_SOURCES = Virt_ConcreteComponent.c
+libVirt_ConcreteComponent_la_LIBADD = -lVirt_HostSystem -lVirt_DevicePool
diff -r 90ac6766de08 -r 794e7f3b23d0 src/Virt_ConcreteComponent.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Virt_ConcreteComponent.c	Fri Aug 22 10:50:42 2008 -0700
@@ -0,0 +1,246 @@
+/*
+ * Copyright IBM Corp. 2007
+ *
+ * Authors:
+ *  Dan Smith <danms at us.ibm.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 <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#include <libvirt/libvirt.h>
+
+#include "cmpidt.h"
+#include "cmpift.h"
+#include "cmpimacs.h"
+
+#include <libcmpiutil/libcmpiutil.h>
+#include <libcmpiutil/std_association.h>
+#include "misc_util.h"
+
+#include "Virt_HostSystem.h"
+#include "Virt_DevicePool.h"
+
+const static CMPIBroker *_BROKER;
+
+static char *bridge_from_netpool(virConnectPtr conn,
+                                const char *poolid)
+{
+        char *netname = NULL;
+        char *bridge = NULL;
+        virNetworkPtr net = NULL;
+
+        netname = name_from_pool_id(poolid);
+        if (netname == NULL) {
+                CU_DEBUG("Unable to parse network pool id: %s", poolid);
+                goto out;
+        }
+
+        net = virNetworkLookupByName(conn, netname);
+        if (net == NULL) {
+                CU_DEBUG("Unable to find network %s", netname);
+                goto out;
+        }
+
+        bridge = virNetworkGetBridgeName(net);
+ out:
+        free(netname);
+        virNetworkFree(net);
+
+        return bridge;
+}
+
+static CMPIInstance *get_bridge_instance(const CMPIContext *context,
+                                         const CMPIObjectPath *ref,
+                                         const char *bridge,
+                                         CMPIStatus *s)
+{
+        CMPIObjectPath *path;
+        CMPIInstance *inst = NULL;
+        const char *cn = "Linux_EthernetPort";
+        const char *sys = NULL;
+        const char *syscc = NULL;
+
+        *s = get_host_system_properties(&sys, &syscc, ref, _BROKER, context);
+        if (s->rc != CMPI_RC_OK)
+                goto out;
+
+        path = CMNewObjectPath(_BROKER, "root/cimv2", cn, s);
+        if ((path == NULL) || (s->rc != CMPI_RC_OK))
+                goto out;
+
+        CMAddKey(path, "CreationClassName", cn, CMPI_chars);
+        CMAddKey(path, "SystemName", sys, CMPI_chars);
+        CMAddKey(path, "SystemCreationClassName", syscc, CMPI_chars);
+        CMAddKey(path, "DeviceID", bridge, CMPI_chars);
+
+        inst = CBGetInstance(_BROKER, context, path, NULL, s);
+ out:
+        return inst;
+}
+
+static CMPIStatus netpool_to_port(const CMPIObjectPath *ref,
+                                  struct std_assoc_info *info,
+                                  struct inst_list *list)
+{
+        virConnectPtr conn = NULL;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        const char *poolid;
+        char *bridge = NULL;
+        CMPIInstance *inst;
+
+        if (!match_hypervisor_prefix(ref, info))
+                return s;
+
+        conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
+        if (conn == NULL)
+                return s;
+
+        if (cu_get_str_path(ref, "InstanceID", &poolid) != CMPI_RC_OK) {
+                CU_DEBUG("Failed to get InstanceID from NetworkPool");
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Missing InstanceID in NetworkPool");
+                goto out;
+        }
+
+        bridge = bridge_from_netpool(conn, poolid);
+        if (bridge == NULL) {
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_NOT_FOUND,
+                           "NetworkPool not found");
+                goto out;
+        }
+
+        inst = get_bridge_instance(info->context, ref, bridge, &s);
+        if (inst != NULL)
+                inst_list_add(list, inst);
+
+ out:
+        free(bridge);
+        virConnectClose(conn);
+
+        return s;
+}
+
+static CMPIStatus port_to_netpool(const CMPIObjectPath *ref,
+                                  struct std_assoc_info *info,
+                                  struct inst_list *list)
+{
+        CMPIStatus s;
+        const char *device;
+        virConnectPtr conn = NULL;
+        CMPIInstance *inst = NULL;
+        char *id = NULL;
+
+        if (cu_get_str_path(ref, "DeviceID", &device) != CMPI_RC_OK) {
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Missing DeviceID from EthernetPort");
+                return s;
+        }
+
+        conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
+        if (conn == NULL)
+                return s;
+
+        if (asprintf(&id, "NetworkPool/%s", device) == -1) {
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Unable to format NetworkPool ID");
+                goto out;
+        }
+
+        s = get_pool_by_name(_BROKER, ref, id, &inst);
+        if ((inst != NULL) && (s.rc == CMPI_RC_OK))
+                inst_list_add(list, inst);
+ out:
+        free(id);
+        virConnectClose(conn);
+
+        return s;
+}
+
+LIBVIRT_CIM_DEFAULT_MAKEREF()
+
+static char *netpool[] = {
+        "Xen_NetworkPool",
+        "KVM_NetworkPool",
+        "LXC_NetworkPool",
+        NULL
+};
+
+static char *ethernetport[] = {
+        "Linux_EthernetPort",
+        NULL,
+};
+
+static char *assoc_classname[] = {
+        "Xen_ConcreteComponent",
+        "KVM_ConcreteComponent",
+        "LXC_ConcreteComponent",
+        NULL
+};
+
+static struct std_assoc _netpool_to_port = {
+        .source_class = (char **)&netpool,
+        .source_prop = "GroupComponent",
+
+        .target_class = (char **)&ethernetport,
+        .target_prop = "PartComponent",
+
+        .assoc_class = (char **)&assoc_classname,
+
+        .handler = netpool_to_port,
+        .make_ref = make_ref
+};
+
+static struct std_assoc _port_to_netpool = {
+        .source_class = (char **)&ethernetport,
+        .source_prop = "PartComponent",
+
+        .target_class = (char **)&netpool,
+        .target_prop = "GroupComponent",
+
+        .assoc_class = (char **)&assoc_classname,
+
+        .handler = port_to_netpool,
+        .make_ref = make_ref
+};
+
+static struct std_assoc *handlers[] = {
+        &_netpool_to_port,
+        &_port_to_netpool,
+        NULL
+};
+
+STDA_AssocMIStub(,
+                 Virt_ConcreteComponent,
+                 _BROKER,
+                 libvirt_cim_init(),
+                 handlers);
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-set-style: "K&R"
+ * tab-width: 8
+ * c-basic-offset: 8
+ * indent-tabs-mode: nil
+ * End:
+ */




More information about the Libvirt-cim mailing list