[Libvirt-cim] [PATCH 1 of 2] Create parent network pool

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Fri May 1 20:02:37 UTC 2009


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1241124395 25200
# Node ID d392e94325eca1a937a1a6a7ab11809174987368
# Parent  3b8498fe6e2b575456486434056042047187ccb9
Create parent network pool.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r 3b8498fe6e2b -r d392e94325ec src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c	Fri May 01 13:02:07 2009 -0700
+++ b/src/Virt_DevicePool.c	Thu Apr 30 13:46:35 2009 -0700
@@ -651,7 +651,8 @@
                        uint16_t type,
                        const char *id,
                        const char *units,
-                       const char *caption)
+                       const char *caption,
+                       bool primordial)
 {
         CMSetProperty(inst, "InstanceID",
                       (CMPIValue *)id, CMPI_chars);
@@ -669,6 +670,9 @@
         if (caption != NULL)
                 CMSetProperty(inst, "Caption",
                               (CMPIValue *)caption, CMPI_chars);
+
+        CMSetProperty(inst, "Primordial",
+                      (CMPIValue *)&primordial, CMPI_boolean);
 }
 
 static CMPIStatus mempool_instance(virConnectPtr conn,
@@ -696,7 +700,7 @@
         mempool_set_total(inst, conn);
         mempool_set_reserved(inst, conn);
 
-        set_params(inst, CIM_RES_TYPE_MEM, id, "KiloBytes", NULL);
+        set_params(inst, CIM_RES_TYPE_MEM, id, "KiloBytes", NULL, true);
 
         inst_list_add(list, inst);
 
@@ -727,13 +731,51 @@
 
         procpool_set_total(inst, conn);
 
-        set_params(inst, CIM_RES_TYPE_PROC, id, "Processors", NULL);
+        set_params(inst, CIM_RES_TYPE_PROC, id, "Processors", NULL, true);
 
         inst_list_add(list, inst);
 
         return s;
 }
 
+static CMPIStatus _netpool_for_parent(struct inst_list *list,
+                                      const char *ns,
+                                      const char *refcn,
+                                      const CMPIBroker *broker)
+{
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        char *id = NULL;
+        CMPIInstance *inst;
+
+        inst = get_typed_instance(broker,
+                                  refcn,
+                                  "NetworkPool",
+                                  ns);
+        if (inst == NULL) {
+                CU_DEBUG("Unable to get instance: %s:%s_NetworkPool",
+                         ns, refcn);
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Error getting pool instance");
+                goto out;
+        }
+
+        if (asprintf(&id, "NetworkPool/0") == -1) {
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "");
+                goto out;
+        }
+
+        set_params(inst, CIM_RES_TYPE_NET, id, NULL, NULL, true);
+        free(id);
+
+        inst_list_add(list, inst);
+ out:
+
+        return s;
+}
+
 static CMPIStatus _netpool_for_network(struct inst_list *list,
                                        const char *ns,
                                        virConnectPtr conn,
@@ -748,6 +790,9 @@
         CMPIInstance *inst;
         virNetworkPtr network = NULL;
 
+        if (STREQC(netname, "0"))
+                return _netpool_for_parent(list, ns, refcn, broker);
+
         CU_DEBUG("Looking up network `%s'", netname);
         network = virNetworkLookupByName(conn, netname);
         if (network == NULL) {
@@ -787,7 +832,7 @@
                 goto out;
         }
 
-        set_params(inst, CIM_RES_TYPE_NET, id, NULL, cap);
+        set_params(inst, CIM_RES_TYPE_NET, id, NULL, cap, false);
         free(id);
         free(cap);
         free(bridge);
@@ -839,6 +884,17 @@
 
         nets = virConnectListNetworks(conn, netnames, nets);
 
+        nets++;
+        netnames = realloc(netnames, (nets) * (sizeof(*netnames)));
+        if (netnames == NULL) {
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Failed to allocate memory for %i net names", nets);
+                goto out;
+        }
+
+        netnames[nets - 1] = "0";
+
         for (i = 0; i < nets; i++) {
                 _netpool_for_network(list,
                                      ns,
@@ -868,10 +924,12 @@
         if (asprintf(&poolid, "DiskPool/%s", pool->tag) == -1)
                 return NULL;
 
-        set_params(inst, CIM_RES_TYPE_DISK, poolid, "Megabytes", pool->tag);
-
-        CMSetProperty(inst, "Primordial",
-                      (CMPIValue *)&pool->primordial, CMPI_boolean);
+        set_params(inst, 
+                   CIM_RES_TYPE_DISK, 
+                   poolid, 
+                   "Megabytes", 
+                   pool->tag, 
+                   pool->primordial);
 
         if (!diskpool_set_capacity(conn, inst, pool))
                 CU_DEBUG("Failed to set capacity for disk pool: %s",
@@ -951,7 +1009,7 @@
                 return s;
         }
 
-        set_params(inst, CIM_RES_TYPE_GRAPHICS, id, NULL, NULL);
+        set_params(inst, CIM_RES_TYPE_GRAPHICS, id, NULL, NULL, true);
 
         inst_list_add(list, inst);
 
@@ -987,7 +1045,7 @@
                 return s;
         }
 
-        set_params(inst, CIM_RES_TYPE_INPUT, id, NULL, NULL);
+        set_params(inst, CIM_RES_TYPE_INPUT, id, NULL, NULL, true);
 
         inst_list_add(list, inst);
 




More information about the Libvirt-cim mailing list