# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1193915264 -3600
# Node ID b14cdc8c5e904694b025850856a238cf7a4f93db
# Parent 50cd94057045e93e7978797b0c204731191e6909
Enhance RegisteredProfile to support getInstance and gets static ID
Signed-off-by: Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
diff -r 50cd94057045 -r b14cdc8c5e90 src/Virt_RegisteredProfile.c
--- a/src/Virt_RegisteredProfile.c Thu Nov 01 11:07:40 2007 +0100
+++ b/src/Virt_RegisteredProfile.c Thu Nov 01 12:07:44 2007 +0100
@@ -38,39 +38,22 @@
const static CMPIBroker *_BROKER;
-static bool reg_prof_set_id(CMPIInstance *instance,
- struct reg_prof *profile)
-{
- char *id;
-
- if (asprintf(&id, "%s_%s", profile->reg_name,
- profile->reg_version) == -1)
- id = NULL;
-
- if(id)
- CMSetProperty(instance, "InstanceID",
- (CMPIValue *)id, CMPI_chars);
-
- return id != NULL;
-}
-
CMPIInstance *reg_prof_instance(const CMPIBroker *broker,
- const CMPIObjectPath *ref,
+ const char *namespace,
+ const char **properties,
struct reg_prof *profile)
{
- CMPIStatus s;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
CMPIObjectPath *op;
CMPIInstance *instance = NULL;
char *classname;
classname = get_typed_class("RegisteredProfile");
if (classname == NULL) {
- //TRACE(1, "Can't assemble classname.");
- printf("Can't assemble classname.\n");
- goto out;
- }
-
- op = CMNewObjectPath(broker, NAMESPACE(ref), classname, &s);
+ goto out;
+ }
+
+ op = CMNewObjectPath(broker, namespace, classname, &s);
if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op))
goto out;
@@ -78,10 +61,15 @@ CMPIInstance *reg_prof_instance(const CM
if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op))
goto out;
- reg_prof_set_id(instance, profile);
-
- CMSetProperty(instance, "CreationClassName",
- (CMPIValue *)classname, CMPI_chars);
+ if (properties) {
+ s = CMSetPropertyFilter(instance, properties, NULL);
+ if (s.rc != CMPI_RC_OK) {
+ goto out;
+ }
+ }
+
+ CMSetProperty(instance, "InstanceID",
+ (CMPIValue *)profile->reg_id, CMPI_chars);
CMSetProperty(instance, "RegisteredOrganization",
(CMPIValue *)&profile->reg_org, CMPI_uint16);
@@ -103,27 +91,20 @@ static CMPIStatus enum_profs(const CMPIO
const char **properties,
bool names_only)
{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *instance;
int i;
- CMPIStatus s = {CMPI_RC_OK, NULL};
- CMPIInstance *instance;
for (i = 0; profiles[i] != NULL; i++) {
- instance = reg_prof_instance(_BROKER, ref, profiles[i]);
+ instance = reg_prof_instance(_BROKER,
+ NAMESPACE(ref),
+ properties,
+ profiles[i]);
if (instance == NULL) {
CMSetStatusWithChars(_BROKER, &s, CMPI_RC_ERR_FAILED,
"Can't create profile
instance.");
goto out;
}
-
- if (properties) {
- s = CMSetPropertyFilter(instance, properties, NULL);
- if (s.rc != CMPI_RC_OK) {
- CMSetStatusWithChars(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "Property filter
failed.");
- goto out;
- }
- }
if (names_only)
cu_return_instance_name(results, instance);
@@ -132,6 +113,44 @@ static CMPIStatus enum_profs(const CMPIO
}
out:
+ return s;
+}
+
+static CMPIStatus get_prof(const CMPIObjectPath *ref,
+ const CMPIResult *results,
+ const char **properties)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *instance = NULL;
+ char* id;
+ int i;
+
+ id = cu_get_str_path(ref, "InstanceID");
+ if (id == NULL) {
+ CMSetStatusWithChars(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "No InstanceID specified");
+ return s;
+ }
+
+ for (i = 0; profiles[i] != NULL; i++) {
+ if(STREQ(id, profiles[i]->reg_id)) {
+ instance = reg_prof_instance(_BROKER,
+ NAMESPACE(ref),
+ properties,
+ profiles[i]);
+ break;
+ }
+ }
+
+ if(instance)
+ CMReturnInstance(results, instance);
+ else
+ CMSetStatus(&s, CMPI_RC_ERR_NOT_FOUND);
+
+
+ free(id);
+
return s;
}
@@ -152,7 +171,15 @@ static CMPIStatus EnumInstances(CMPIInst
return enum_profs(reference, results, properties, false);
}
-DEFAULT_GI();
+static CMPIStatus GetInstance(CMPIInstanceMI *self,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *reference,
+ const char **properties)
+{
+ return get_prof(reference, results, properties);
+}
+
DEFAULT_CI();
DEFAULT_MI();
DEFAULT_DI();
diff -r 50cd94057045 -r b14cdc8c5e90 src/Virt_RegisteredProfile.h
--- a/src/Virt_RegisteredProfile.h Thu Nov 01 11:07:40 2007 +0100
+++ b/src/Virt_RegisteredProfile.h Thu Nov 01 12:07:44 2007 +0100
@@ -22,8 +22,9 @@
#define __VIRT_REGISTERED_PROFILE_H
CMPIInstance *reg_prof_instance(const CMPIBroker *broker,
- const CMPIObjectPath *ref,
- struct reg_prof *profile);
+ const char *namespace,
+ const char **properties,
+ struct reg_prof *profile);
#endif
diff -r 50cd94057045 -r b14cdc8c5e90 src/profiles.h
--- a/src/profiles.h Thu Nov 01 11:07:40 2007 +0100
+++ b/src/profiles.h Thu Nov 01 12:07:44 2007 +0100
@@ -20,6 +20,7 @@
*/
struct reg_prof {
uint16_t reg_org; // Valid: 1 = Other, 2 = DMTF
+ char *reg_id;
char *reg_name;
char *reg_version;
int ad_types;
@@ -28,49 +29,27 @@ struct reg_prof {
char *provider_name;
};
-struct reg_prof Processor = {
+struct reg_prof SystemVirtualization = {
.reg_org = 2,
- .reg_name = "Processor Profile",
- .reg_version = "2.15",
- .provider_name = "Processor"
+ .reg_id = "DSP1042-1.0.0a",
+ .reg_name = "System Virtualization Profile",
+ .reg_version = "1.0.0a",
+ .provider_name = "HostSystem"
};
-struct reg_prof LogicalDisk = {
+struct reg_prof VirtualSystem = {
.reg_org = 2,
- .reg_name = "Logical Disk Profile",
- .reg_version = "2.15",
- .provider_name = "LogicalDisk"
-};
-
-struct reg_prof NetworkPort = {
- .reg_org = 2,
- .reg_name = "Network Port Profile",
- .reg_version = "2.15",
- .provider_name = "NetworkPort"
-};
-
-struct reg_prof ComputerSystem = {
- .reg_org = 2,
- .reg_name = "Computer System Profile",
- .reg_version = "2.15",
+ .reg_id = "DSP1057-1.0.0a",
+ .reg_name = "Virtual System Profile",
+ .reg_version = "1.0.0a",
.provider_name = "ComputerSystem"
};
-struct reg_prof SVP = {
- .reg_org = 2,
- .reg_name = "System Virtualization Profile",
- .reg_version = "2.15",
- .provider_name = "VirtualSystemManagementService"
-};
-
// Make sure to add pointer to your reg_prof struct here.
struct reg_prof *profiles[] = {
- &Processor,
- &LogicalDisk,
- &NetworkPort,
- &ComputerSystem,
- &SVP,
+ &SystemVirtualization,
+ &VirtualSystem,
NULL
};