[PATCH] Set additional attribute values in Virt_ComputerSystem.c

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1201904890 28800 # Node ID 3b1671a993401889101969b3f5e3a25e45d13400 # Parent 19bd4c5ede1512bcd411a98b3c09acebc506b38e Set additional attribute values in Virt_ComputerSystem.c OtherIdentifyingInfo property and IdentifyingDescriptions. Modify instance_from_dom() to take a prefix parameter. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 19bd4c5ede15 -r 3b1671a99340 src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Fri Feb 01 10:55:58 2008 -0800 +++ b/src/Virt_ComputerSystem.c Fri Feb 01 14:28:10 2008 -0800 @@ -71,7 +71,9 @@ static int set_name_from_dom(virDomainPt } /* Set the "UUID" property of an instance from a domain */ -static int set_uuid_from_dom(virDomainPtr dom, CMPIInstance *instance) +static int set_uuid_from_dom(virDomainPtr dom, + CMPIInstance *instance, + char **out_uuid) { char uuid[VIR_UUID_STRING_BUFLEN]; int ret; @@ -82,6 +84,8 @@ static int set_uuid_from_dom(virDomainPt CMSetProperty(instance, "UUID", (CMPIValue *)uuid, CMPI_chars); + + *out_uuid = strdup(uuid); return 1; } @@ -239,17 +243,91 @@ static int set_creation_class(CMPIInstan return 1; } +static int set_other_id_info(const CMPIBroker *broker, + char *uuid, + const char *prefix, + CMPIInstance *instance) +{ + CMPIStatus s; + CMPIArray *id_info; + char *info[3]; + int count = 3; + char *type = "Virtual System"; + char *model; + int i; + + id_info = CMNewArray(broker, + count, + CMPI_string, + &s); + + if (s.rc != CMPI_RC_OK) + return 0; + + if (asprintf(&model, "%s%s", prefix, type) == 1) + return 0; + + info[0] = uuid; + info[1] = model; + info[2] = type; + + for (i = 0; i < count; i++) { + CMPIString *tmp = CMNewString(broker, info[i], NULL); + CMSetArrayElementAt(id_info, i, + &tmp, + CMPI_string); + } + + CMSetProperty(instance, "OtherIdentifyingInfo", + &id_info, CMPI_stringA); + + return 1; +} + +static int set_id_desc(const CMPIBroker *broker, + CMPIInstance *instance) +{ + CMPIStatus s; + CMPIArray *id_desc; + char *desc[3] = {"Type", "Model", "UUID"}; + int count = 3; + int i; + + id_desc = CMNewArray(broker, + count, + CMPI_string, + &s); + + if (s.rc != CMPI_RC_OK) + return 0; + + for (i = 0; i < count; i++) { + CMPIString *tmp = CMNewString(broker, desc[i], NULL); + CMSetArrayElementAt(id_desc, i, + &tmp, + CMPI_string); + } + + CMSetProperty(instance, "IdentifyingDescriptions", + (CMPIValue *)&id_desc, CMPI_stringA); + + return 1; +} + /* Populate an instance with information from a domain */ static int instance_from_dom(const CMPIBroker *broker, virDomainPtr dom, + const char *prefix, CMPIInstance *instance) { + char *uuid; + if (!set_name_from_dom(dom, instance)) { /* Print trace error */ return 0; } - if (!set_uuid_from_dom(dom, instance)) { + if (!set_uuid_from_dom(dom, instance, &uuid)) { /* Print trace error */ return 0; } @@ -269,7 +347,20 @@ static int instance_from_dom(const CMPIB return 0; } + if (!set_other_id_info(broker, uuid, prefix, instance)) { + /* Print trace error */ + free(uuid); + return 0; + } + + if (!set_id_desc(broker, instance)) { + /* Print trace error */ + return 0; + } + /* More attributes here, of course */ + + free(uuid); return 1; } @@ -294,7 +385,10 @@ CMPIInstance *instance_from_name(const C if (instance == NULL) goto out; - if (!instance_from_dom(broker, dom, instance)) + if (!instance_from_dom(broker, + dom, + pfx_from_conn(conn), + instance)) instance = NULL; out: @@ -327,7 +421,10 @@ int enum_domains(const CMPIBroker *broke if (inst == NULL) goto end; - if (instance_from_dom(broker, list[i], inst)) + if (instance_from_dom(broker, + list[i], + pfx_from_conn(conn), + inst)) inst_list_add(instlist, inst); end:

KR> +static int set_other_id_info(const CMPIBroker *broker, KR> + char *uuid, KR> + const char *prefix, KR> + CMPIInstance *instance) KR> +{ KR> + CMPIStatus s; KR> + CMPIArray *id_info; KR> + char *info[3]; KR> + int count = 3; KR> + char *type = "Virtual System"; KR> + char *model; KR> + int i; KR> + KR> + id_info = CMNewArray(broker, KR> + count, KR> + CMPI_string, KR> + &s); KR> + KR> + if (s.rc != CMPI_RC_OK) KR> + return 0; KR> + KR> + if (asprintf(&model, "%s%s", prefix, type) == 1) KR> + return 0; KR> + KR> + info[0] = uuid; KR> + info[1] = model; KR> + info[2] = type; KR> + KR> + for (i = 0; i < count; i++) { KR> + CMPIString *tmp = CMNewString(broker, info[i], NULL); KR> + CMSetArrayElementAt(id_info, i, KR> + &tmp, KR> + CMPI_string); KR> + } KR> + KR> + CMSetProperty(instance, "OtherIdentifyingInfo", KR> + &id_info, CMPI_stringA); KR> + KR> + return 1; KR> +} This is a style thing, I guess, but wouldn't it be easier to combine this function with the one that sets the descriptions? You could loop through both string arrays at the same time and construct the two CMPIArrays together. The two functions are almost identical, so I think doing them together would add six lines to the above function instead of the 30 it takes for the separate function. KR> static int instance_from_dom(const CMPIBroker *broker, KR> virDomainPtr dom, KR> + const char *prefix, KR> CMPIInstance *instance) KR> { KR> + char *uuid; KR> + KR> if (!set_name_from_dom(dom, instance)) { KR> /* Print trace error */ KR> return 0; KR> } KR> - if (!set_uuid_from_dom(dom, instance)) { KR> + if (!set_uuid_from_dom(dom, instance, &uuid)) { KR> /* Print trace error */ KR> return 0; KR> } KR> @@ -269,7 +347,20 @@ static int instance_from_dom(const CMPIB KR> return 0; Leak UUID here... KR> } KR> + if (!set_other_id_info(broker, uuid, prefix, instance)) { KR> + /* Print trace error */ KR> + free(uuid); KR> + return 0; ...but not here... KR> + } KR> + KR> + if (!set_id_desc(broker, instance)) { KR> + /* Print trace error */ KR> + return 0; ...and then again here. KR> + } KR> + KR> /* More attributes here, of course */ KR> + KR> + free(uuid); KR> return 1; KR> } Can we get either an "err:" target or a return variable and an "out:" target please? :) -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
This is a style thing, I guess, but wouldn't it be easier to combine this function with the one that sets the descriptions? You could loop through both string arrays at the same time and construct the two CMPIArrays together. The two functions are almost identical, so I think doing them together would add six lines to the above function instead of the 30 it takes for the separate function.
Good suggestion - much cleaner as one function.
...and then again here.
KR> + } KR> + KR> /* More attributes here, of course */ KR> + KR> + free(uuid);
KR> return 1; KR> }
Can we get either an "err:" target or a return variable and an "out:" target please? :)
Yep - will send a new patch with this issue cleaned up. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert