[Libvirt-cim] [PATCH 2 of 3] Make HostSystem return the SBLIM ComputerSystem, if present

Dan Smith danms at us.ibm.com
Tue Aug 19 21:14:05 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1219180424 25200
# Node ID 304d6c3d06697f93c35b64c0b059090648de8e5e
# Parent  a55c6df52f5e8108d3e1dc978a2f3b8b32db71dc
Make HostSystem return the SBLIM ComputerSystem, if present

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

diff -r a55c6df52f5e -r 304d6c3d0669 src/Virt_HostSystem.c
--- a/src/Virt_HostSystem.c	Tue Aug 19 14:13:24 2008 -0700
+++ b/src/Virt_HostSystem.c	Tue Aug 19 14:13:44 2008 -0700
@@ -57,11 +57,9 @@
         return 1;
 }
 
-CMPIStatus get_host(const CMPIBroker *broker,
-                    const CMPIContext *context,
-                    const CMPIObjectPath *reference,
-                    CMPIInstance **_inst,
-                    bool is_get_inst)
+static CMPIStatus fake_host(const CMPIBroker *broker,
+                            const CMPIObjectPath *reference,
+                            CMPIInstance **_inst)
 {
         CMPIStatus s = {CMPI_RC_OK, NULL};
         CMPIInstance *inst = NULL;
@@ -69,10 +67,9 @@
 
         conn = connect_by_classname(broker, CLASSNAME(reference), &s);
         if (conn == NULL) {
-                if (is_get_inst)
-                        cu_statusf(broker, &s,
-                                   CMPI_RC_ERR_NOT_FOUND,
-                                   "No such instance");
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_NOT_FOUND,
+                           "No such instance");
                 goto out;
         }
 
@@ -89,17 +86,71 @@
         }
 
         set_host_system_properties(inst);
+        *_inst = inst;
+ out:
+        virConnectClose(conn);
 
-        if (is_get_inst) {
-                s = cu_validate_ref(broker, reference, inst);
-                if (s.rc != CMPI_RC_OK)
-                        goto out;
+        return s;
+}
+
+static CMPIStatus sblim_host(const CMPIBroker *broker,
+                             const CMPIContext *context,
+                             const CMPIObjectPath *ref,
+                             CMPIInstance **inst)
+{
+        CMPIObjectPath *path;
+        CMPIStatus s;
+        const char *cn = "Linux_ComputerSystem";
+        char name[256];
+
+        if (gethostname(name, sizeof(name)) != 0) {
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Unable to get hostname: %m");
+                return s;
         }
 
-        *_inst = inst;
+        path = CMNewObjectPath(broker, "root/cimv2", cn, &s);
+        if ((path == NULL) || (s.rc != CMPI_RC_OK)) {
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Unable to create HostSystem path");
+                return s;
+        }
 
- out:
-        virConnectClose(conn);
+        CMAddKey(path, "CreationClassName", cn, CMPI_chars);
+        CMAddKey(path, "Name", name, CMPI_chars);
+
+        *inst = CBGetInstance(broker, context, path, NULL, &s);
+
+        if (s.rc != CMPI_RC_OK) {
+                CU_DEBUG("SBLIM: %i %s", s.rc, CMGetCharPtr(s.msg));
+        } else {
+                CU_DEBUG("SBLIM: Returned instance");
+        }
+
+        return s;
+}
+
+CMPIStatus get_host(const CMPIBroker *broker,
+                    const CMPIContext *context,
+                    const CMPIObjectPath *reference,
+                    CMPIInstance **_inst,
+                    bool is_get_inst)
+{
+        CMPIStatus s;
+
+        s = sblim_host(broker, context, reference, _inst);
+        if (s.rc != CMPI_RC_OK)
+                s = fake_host(broker, reference, _inst);
+
+        if (!is_get_inst && (s.rc == CMPI_RC_ERR_NOT_FOUND)) {
+                /* This is not an error */
+                return (CMPIStatus){CMPI_RC_OK, NULL};
+        }
+
+        if ((s.rc == CMPI_RC_OK) && is_get_inst)
+                s = cu_validate_ref(broker, reference, *_inst);
 
         return s;
 }




More information about the Libvirt-cim mailing list