[Libvirt-cim] [PATCH] Expose console information informally in ComputerSystem instance

Dan Smith danms at us.ibm.com
Tue Apr 15 18:29:49 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1208284176 25200
# Node ID a31e00ad17b63dcfcfab60295bd88f405a75e9ff
# Parent  93836f7ec3d282cb6186f6f0c0e4afdcdf4fbfab
Expose console information informally in ComputerSystem instance

By putting the vnc:// url in the caption field, users and clients can
at least get access to the information through the CIM providers until we
have a more formal console model established.

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

diff -r 93836f7ec3d2 -r a31e00ad17b6 src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c	Tue Apr 15 10:46:04 2008 -0700
+++ b/src/Virt_ComputerSystem.c	Tue Apr 15 11:29:36 2008 -0700
@@ -23,6 +23,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
+#include <limits.h>
 
 #include <cmpidt.h>
 #include <cmpift.h>
@@ -33,10 +35,12 @@
 #include "cs_util.h"
 #include <libcmpiutil/libcmpiutil.h>
 #include "misc_util.h"
+#include "device_parsing.h"
 #include <libcmpiutil/std_invokemethod.h>
 #include <libcmpiutil/std_instance.h>
 
 #include "Virt_ComputerSystem.h"
+#include "Virt_HostSystem.h"
 
 const static CMPIBroker *_BROKER;
 
@@ -90,13 +94,42 @@ static int set_uuid_from_dom(virDomainPt
         return 1;
 }
 
-static int set_capdesc_from_dom(virDomainPtr dom, CMPIInstance *instance)
-{
+static int set_capdesc_from_dominfo(const CMPIBroker *broker,
+                                    struct domain *domain,
+                                    const CMPIObjectPath *ref,
+                                    CMPIInstance *instance)
+{
+        char *cap = NULL;
+        int ret;
+        char host[HOST_NAME_MAX];
+
+        if (gethostname(host, sizeof(host)) != 0) {
+                CU_DEBUG("Unable to get hostname: %m");
+                strcpy(host, "localhost");
+        }
+
+        if (domain->dev_graphics != NULL)
+                ret = asprintf(&cap,
+                               "Virtual System (Console on %s://%s:%s)",
+                               domain->dev_graphics->dev.graphics.type,
+                               host,
+                               domain->dev_graphics->dev.graphics.port);
+        else
+                ret = asprintf(&cap,
+                               "Virtual System (No console)");
+
+        if (ret == -1) {
+                CU_DEBUG("Failed to create caption string");
+                goto out;
+        }
+
         CMSetProperty(instance, "Caption",
-                      (CMPIValue *)"Virtual System", CMPI_chars);
+                      (CMPIValue *)cap, CMPI_chars);
 
         CMSetProperty(instance, "Description",
                       (CMPIValue *)"Virtual System", CMPI_chars);
+ out:
+        free(cap);
 
         return 1;
 }
@@ -309,6 +342,20 @@ static CMPIStatus set_properties(const C
 {
         CMPIStatus s = {CMPI_RC_ERR_FAILED, NULL};
         char *uuid = NULL;
+        struct domain *domain = NULL;
+        CMPIObjectPath *ref = NULL;
+
+        ref = CMGetObjectPath(instance, &s);
+        if ((ref == NULL) || (s.rc != CMPI_RC_OK))
+                return s;
+
+        if (get_dominfo(dom, &domain) == 0) {
+                CU_DEBUG("Unable to get domain information");
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Unable to get domain information");
+                goto out;
+        }
 
         if (!set_name_from_dom(dom, instance)) {
                 /* Print trace error */
@@ -320,7 +367,7 @@ static CMPIStatus set_properties(const C
                 goto out;
         }
 
-        if (!set_capdesc_from_dom(dom, instance)) {
+        if (!set_capdesc_from_dominfo(broker, domain, ref, instance)) {
                 /* Print trace error */
                 goto out;
         }
@@ -348,6 +395,7 @@ static CMPIStatus set_properties(const C
 
  out:
         free(uuid);
+        cleanup_dominfo(&domain);
 
         return s;
 }




More information about the Libvirt-cim mailing list