[PATCH 0 of 2] Add Network parent pool and NetPoolRASD templates

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1241124395 25200 # Node ID d392e94325eca1a937a1a6a7ab11809174987368 # Parent 3b8498fe6e2b575456486434056042047187ccb9 Create parent network pool. Signed-off-by: Kaitlin Rupert <karupert@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);

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1241208154 25200 # Node ID aa3094d471dd82b0d682f76342d33d48a29e29cb # Parent d392e94325eca1a937a1a6a7ab11809174987368 Expose template NetPoolRASDs. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r d392e94325ec -r aa3094d471dd src/Virt_RASD.c --- a/src/Virt_RASD.c Thu Apr 30 13:46:35 2009 -0700 +++ b/src/Virt_RASD.c Fri May 01 13:02:34 2009 -0700 @@ -598,6 +598,9 @@ case CIM_RES_TYPE_DISK: *classname = "DiskPoolResourceAllocationSettingData"; break; + case CIM_RES_TYPE_NET: + *classname = "NetPoolResourceAllocationSettingData"; + break; default: rc = CMPI_RC_ERR_FAILED; } diff -r d392e94325ec -r aa3094d471dd src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Thu Apr 30 13:46:35 2009 -0700 +++ b/src/Virt_SettingsDefineCapabilities.c Fri May 01 13:02:34 2009 -0700 @@ -609,6 +609,143 @@ return s; } +static CMPIStatus set_net_pool_props(const CMPIObjectPath *ref, + const char *id, + uint16_t pool_type, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *addr = "192.168.122.1"; + const char *netmask = "255.255.255.0"; + const char *ip_start = "192.168.122.2"; + const char *ip_stop = "192.168.122.254"; + int dev_count; + int i; + + /* Isolated network pools don't have a forward device */ + if (pool_type == NETPOOL_FORWARD_NONE) + dev_count = 1; + else + dev_count = 2; + + for (i = 0; i < dev_count; i++) { + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_NET, POOL_RASD); + if ((inst == NULL) || (s.rc != CMPI_RC_OK)) + goto out; + + CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); + + CMSetProperty(inst, "Address", + (CMPIValue *)addr, CMPI_chars); + + CMSetProperty(inst, "Netmask", + (CMPIValue *)netmask, CMPI_chars); + + CMSetProperty(inst, "IPRangeStart", + (CMPIValue *)ip_start, CMPI_chars); + + CMSetProperty(inst, "IPRangeEnd", + (CMPIValue *)ip_stop, CMPI_chars); + + CMSetProperty(inst, "ForwardMode", + (CMPIValue *)&pool_type, CMPI_uint16); + + if (i == 1) { + CMSetProperty(inst, "ForwardDevice", + (CMPIValue *)"eth0", CMPI_chars); + } + + inst_list_add(list, inst); + } + + out: + return s; +} + +static CMPIStatus net_pool_template(const CMPIObjectPath *ref, + int template_type, + struct inst_list *list) +{ + const char *id; + CMPIStatus s = {CMPI_RC_OK, NULL}; + int type[3] = {NETPOOL_FORWARD_NONE, + NETPOOL_FORWARD_NAT, + NETPOOL_FORWARD_ROUTED}; + int pool_types = 3; + int i; + + switch (template_type) { + case SDC_RASD_MIN: + id = "Minimum"; + break; + case SDC_RASD_MAX: + id = "Maximum"; + break; + case SDC_RASD_INC: + id = "Increment"; + break; + case SDC_RASD_DEF: + id = "Default"; + break; + default: + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unsupported sdc_rasd type"); + goto out; + } + + for (i = 0; i < pool_types; i++) { + s = set_net_pool_props(ref, id, type[i], list); + if (s.rc != CMPI_RC_OK) + goto out; + } + + out: + return s; +} + +static CMPIStatus net_dev_or_pool_template(const CMPIObjectPath *ref, + int template_type, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *poolid; + bool val; + + if (cu_get_str_path(ref, "InstanceID", &poolid) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing InstanceID"); + goto out; + } + + s = get_pool_by_name(_BROKER, ref, poolid, &inst); + if (s.rc != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get pool instance from capabilities"); + goto out; + } + + if (cu_get_bool_prop(inst, "Primordial", &val) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to determine pool type"); + goto out; + } + + if (val) + s = net_pool_template(ref, template_type, list); + else + s = net_template(ref, template_type, list); + + out: + + return s; +} + static CMPIStatus set_disk_props(int type, const CMPIObjectPath *ref, const char *id, @@ -1390,7 +1527,7 @@ else if (type == CIM_RES_TYPE_PROC) s = proc_template(ref, i, list); else if (type == CIM_RES_TYPE_NET) - s = net_template(ref, i, list); + s = net_dev_or_pool_template(ref, i, list); else if (type == CIM_RES_TYPE_DISK) s = disk_dev_or_pool_template(ref, i, list); else if (type == CIM_RES_TYPE_GRAPHICS)

+1 Kaitlin Rupert wrote:
This is similar to the support that was added for disk pools.
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel