summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2013-05-14 19:02:01 +0200
committerPeter Schiffer <pschiffe@redhat.com>2013-05-14 19:02:01 +0200
commitfcc1acdd4302e4c9e31d102ae8b7e25fc2d67a96 (patch)
tree0e09949cd4ccd21e12f7a767790f2d2b94255c4d
parentf3265d37cea12a5126f9e7ac8266142cd7a05f23 (diff)
downloadopenlmi-providers-fcc1acdd4302e4c9e31d102ae8b7e25fc2d67a96.tar.gz
openlmi-providers-fcc1acdd4302e4c9e31d102ae8b7e25fc2d67a96.tar.xz
openlmi-providers-fcc1acdd4302e4c9e31d102ae8b7e25fc2d67a96.zip
Hardware: Added Chassis provider
New Provider: * LMI_ChassisProvider
-rw-r--r--mof/60_LMI_Hardware.mof9
-rw-r--r--src/hardware/CMakeLists.txt6
-rw-r--r--src/hardware/LMI_ChassisProvider.c276
-rw-r--r--src/hardware/LMI_Hardware.h1
-rw-r--r--src/hardware/dmidecode.c177
-rw-r--r--src/hardware/dmidecode.h25
6 files changed, 494 insertions, 0 deletions
diff --git a/mof/60_LMI_Hardware.mof b/mof/60_LMI_Hardware.mof
index cba6459..a63028d 100644
--- a/mof/60_LMI_Hardware.mof
+++ b/mof/60_LMI_Hardware.mof
@@ -207,6 +207,15 @@ class LMI_PhysicalMemoryRealizes: CIM_Realizes
};
/******************************************************************************
+ * Physical Asset
+ */
+
+[ Provider("cmpi:cmpiLMI_Chassis") ]
+class LMI_Chassis: CIM_Chassis
+{
+};
+
+/******************************************************************************
* PCI Devices
*/
diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt
index eb45adc..68e283d 100644
--- a/src/hardware/CMakeLists.txt
+++ b/src/hardware/CMakeLists.txt
@@ -13,6 +13,12 @@ set(provider_SRCS
LMI_ProcessorElementCapabilitiesProvider.c
LMI_ProcessorCacheMemoryProvider.c
LMI_AssociatedProcessorCacheMemoryProvider.c
+ LMI_ProcessorChipProvider.c
+ LMI_ProcessorChipRealizesProvider.c
+ LMI_MemoryProvider.c
+ LMI_PhysicalMemoryProvider.c
+ LMI_PhysicalMemoryRealizesProvider.c
+ LMI_ChassisProvider.c
)
konkretcmpi_generate(${MOF}
diff --git a/src/hardware/LMI_ChassisProvider.c b/src/hardware/LMI_ChassisProvider.c
new file mode 100644
index 0000000..93345a4
--- /dev/null
+++ b/src/hardware/LMI_ChassisProvider.c
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Peter Schiffer <pschiffe@redhat.com>
+ */
+
+#include <konkret/konkret.h>
+#include "LMI_Chassis.h"
+#include "LMI_Hardware.h"
+#include "globals.h"
+#include "dmidecode.h"
+
+CMPIUint16 get_chassis_type(const char *dmi_chassis);
+
+static const CMPIBroker* _cb = NULL;
+
+static void LMI_ChassisInitialize()
+{
+}
+
+static CMPIStatus LMI_ChassisCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_ChassisEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus LMI_ChassisEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ LMI_Chassis lmi_chassis;
+ const char *ns = KNameSpace(cop);
+ char instance_id[INSTANCE_ID_LEN];
+ DmiChassis dmi_chassis;
+
+ if (dmi_get_chassis(&dmi_chassis) != 0) {
+ goto done;
+ }
+
+ LMI_Chassis_Init(&lmi_chassis, _cb, ns);
+
+ LMI_Chassis_Set_CreationClassName(&lmi_chassis,
+ ORGID "_" CHASSIS_CLASS_NAME);
+ LMI_Chassis_Set_PackageType(&lmi_chassis,
+ LMI_Chassis_PackageType_Chassis_Frame);
+ LMI_Chassis_Set_Caption(&lmi_chassis, "System Chassis");
+ LMI_Chassis_Set_Description(&lmi_chassis,
+ "This object represents physical chassis of the system.");
+
+ if (strcmp(dmi_chassis.serial_number, "Not Specified") == 0) {
+ LMI_Chassis_Set_Tag(&lmi_chassis, "0");
+ LMI_Chassis_Set_InstanceID(&lmi_chassis,
+ ORGID ":" ORGID "_" CHASSIS_CLASS_NAME ":0");
+ } else {
+ LMI_Chassis_Set_Tag(&lmi_chassis, dmi_chassis.serial_number);
+ snprintf(instance_id, INSTANCE_ID_LEN,
+ ORGID ":" ORGID "_" CHASSIS_CLASS_NAME ":%s",
+ dmi_chassis.serial_number);
+ LMI_Chassis_Set_InstanceID(&lmi_chassis, instance_id);
+ }
+ LMI_Chassis_Set_ChassisPackageType(&lmi_chassis,
+ get_chassis_type(dmi_chassis.type));
+ LMI_Chassis_Set_Name(&lmi_chassis, dmi_chassis.type);
+ LMI_Chassis_Set_ElementName(&lmi_chassis, dmi_chassis.type);
+ LMI_Chassis_Set_Manufacturer(&lmi_chassis, dmi_chassis.manufacturer);
+ LMI_Chassis_Set_SerialNumber(&lmi_chassis, dmi_chassis.serial_number);
+ LMI_Chassis_Set_SKU(&lmi_chassis, dmi_chassis.sku_number);
+ LMI_Chassis_Set_Version(&lmi_chassis, dmi_chassis.version);
+ LMI_Chassis_Set_LockPresent(&lmi_chassis, dmi_chassis.has_lock);
+ if (dmi_chassis.power_cords) {
+ LMI_Chassis_Set_NumberOfPowerCords(&lmi_chassis,
+ dmi_chassis.power_cords);
+ }
+
+ KReturnInstance(cr, lmi_chassis);
+
+done:
+ dmi_free_chassis(&dmi_chassis);
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_ChassisGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus LMI_ChassisCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_ChassisModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char** properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_ChassisDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_ChassisExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+CMInstanceMIStub(
+ LMI_Chassis,
+ LMI_Chassis,
+ _cb,
+ LMI_ChassisInitialize())
+
+static CMPIStatus LMI_ChassisMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_ChassisInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return LMI_Chassis_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ LMI_Chassis,
+ LMI_Chassis,
+ _cb,
+ LMI_ChassisInitialize())
+
+KUint32 LMI_Chassis_IsCompatible(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_ChassisRef* self,
+ const KRef* ElementToCheck,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+/*
+ * Get Chassis Type according to the dmidecode output.
+ * @param dmi_chassis chassis type from dmidecode
+ * @return chassis type ID defined by CIM
+ */
+CMPIUint16 get_chassis_type(const char *dmi_chassis)
+{
+ if (!dmi_chassis || strlen(dmi_chassis) < 1) {
+ return 0; /* Unknown */
+ }
+
+ static struct {
+ CMPIUint16 value_map; /* ValueMap defined by CIM */
+ char *search; /* String used to match the dmidecode chassis type */
+ } types[] = {
+ {0, "Unknown"},
+ {1, "Other"},
+ /*
+ {2, "SMBIOS Reserved"},
+ */
+ {3, "Desktop"},
+ {4, "Low Profile Desktop"},
+ {5, "Pizza Box"},
+ {6, "Mini Tower"},
+ {7, "Tower"},
+ {8, "Portable"},
+ {9, "Laptop"},
+ {10, "Notebook"},
+ {11, "Hand Held"},
+ {12, "Docking Station"},
+ {13, "All In One"},
+ {14, "Sub Notebook"},
+ {15, "Space-saving"},
+ {16, "Lunch Box"},
+ {17, "Main Server Chassis"},
+ {18, "Expansion Chassis"},
+ {19, "Sub Chassis"},
+ {20, "Bus Expansion Chassis"},
+ {21, "Peripheral Chassis"},
+ {22, "RAID Chassis"},
+ {23, "Rack Mount Chassis"},
+ {24, "Sealed-case PC"},
+ {25, "Multi-system"},
+ {26, "CompactPCI"},
+ {27, "AdvancedTCA"},
+ /*
+ {28, "Blade Enclosure"},
+ */
+ };
+
+ size_t i, types_length = sizeof(types) / sizeof(types[0]);
+
+ for (i = 0; i < types_length; i++) {
+ if (strcmp(dmi_chassis, types[i].search) == 0) {
+ return types[i].value_map;
+ }
+ }
+
+ return 1; /* Other */
+}
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "LMI_Chassis",
+ "LMI_Chassis",
+ "instance method")
diff --git a/src/hardware/LMI_Hardware.h b/src/hardware/LMI_Hardware.h
index 12e9871..7e721d8 100644
--- a/src/hardware/LMI_Hardware.h
+++ b/src/hardware/LMI_Hardware.h
@@ -30,5 +30,6 @@
#define CPU_CHIP_CLASS_NAME "ProcessorChip"
#define MEM_CLASS_NAME "Memory"
#define PHYS_MEM_CLASS_NAME "PhysicalMemory"
+#define CHASSIS_CLASS_NAME "Chassis"
#endif /* LMI_HARDWARE_H_ */
diff --git a/src/hardware/dmidecode.c b/src/hardware/dmidecode.c
index b3d00ef..d27c9dc 100644
--- a/src/hardware/dmidecode.c
+++ b/src/hardware/dmidecode.c
@@ -1101,3 +1101,180 @@ void dmi_free_memory(DmiMemory *memory)
memory->modules_nb = 0;
memory->modules = NULL;
}
+
+
+/******************************************************************************
+ * DmiChassis
+ */
+
+
+/*
+ * Initialize DmiChassis attributes.
+ * @param chassis
+ */
+void init_dmi_chassis_struct(DmiChassis *chassis)
+{
+ chassis->serial_number = NULL;
+ chassis->type = NULL;
+ chassis->manufacturer = NULL;
+ chassis->sku_number = NULL;
+ chassis->version = NULL;
+ chassis->has_lock = 0;
+ chassis->power_cords = 0;
+}
+
+/*
+ * Check attributes of chassis structure and fill in defaults if needed.
+ * @param chassis
+ * @return 0 if success, negative value otherwise
+ */
+short check_dmi_chassis_attributes(DmiChassis *chassis)
+{
+ short ret = -1;
+
+ if (!chassis->serial_number) {
+ if (!(chassis->serial_number = strdup("Not Specified"))) {
+ ret = -2;
+ goto done;
+ }
+ }
+ if (!chassis->type) {
+ if (!(chassis->type = strdup("Unknown"))) {
+ ret = -3;
+ goto done;
+ }
+ }
+ if (!chassis->manufacturer) {
+ if (!(chassis->manufacturer = strdup(""))) {
+ ret = -4;
+ goto done;
+ }
+ }
+ if (!chassis->sku_number) {
+ if (!(chassis->sku_number = strdup(""))) {
+ ret = -5;
+ goto done;
+ }
+ }
+ if (!chassis->version) {
+ if (!(chassis->version = strdup(""))) {
+ ret = -6;
+ goto done;
+ }
+ }
+
+ ret = 0;
+
+done:
+ if (ret != 0) {
+ warn("Failed to allocate memory.");
+ }
+
+ return ret;
+}
+
+short dmi_get_chassis(DmiChassis *chassis)
+{
+ short ret = -1;
+ unsigned i, buffer_size = 0;
+ char **buffer = NULL, *buf;
+
+ init_dmi_chassis_struct(chassis);
+
+ /* get dmidecode output for chassis */
+ if (run_command("dmidecode -t 3", &buffer, &buffer_size) != 0) {
+ ret = -2;
+ goto done;
+ }
+
+ /* parse information about chassis */
+ for (i = 0; i < buffer_size; i++) {
+ /* Serial Number */
+ buf = copy_string_part_after_delim(buffer[i], "Serial Number: ");
+ if (buf) {
+ chassis->serial_number = buf;
+ buf = NULL;
+ continue;
+ }
+ /* Type */
+ buf = copy_string_part_after_delim(buffer[i], "Type: ");
+ if (buf) {
+ chassis->type = buf;
+ buf = NULL;
+ continue;
+ }
+ /* Manufacturer */
+ buf = copy_string_part_after_delim(buffer[i], "Manufacturer: ");
+ if (buf) {
+ chassis->manufacturer = buf;
+ buf = NULL;
+ continue;
+ }
+ /* SKU Number */
+ buf = copy_string_part_after_delim(buffer[i], "SKU Number: ");
+ if (buf) {
+ chassis->sku_number = buf;
+ buf = NULL;
+ continue;
+ }
+ /* SKU Number */
+ buf = copy_string_part_after_delim(buffer[i], "Version: ");
+ if (buf) {
+ chassis->version = buf;
+ buf = NULL;
+ continue;
+ }
+ /* Has Lock */
+ buf = copy_string_part_after_delim(buffer[i], "Lock: ");
+ if (buf) {
+ if (strcmp(buf, "Present") == 0) {
+ chassis->has_lock = 1;
+ }
+ free(buf);
+ buf = NULL;
+ continue;
+ }
+ /* Number of power cords */
+ buf = copy_string_part_after_delim(buffer[i], "Number Of Power Cords: ");
+ if (buf) {
+ if (strcmp(buf, "Unspecified") != 0) {
+ sscanf(buf, "%u", &chassis->power_cords);
+ }
+ free(buf);
+ buf = NULL;
+ continue;
+ }
+ }
+
+ /* fill in default attributes if needed */
+ if (check_dmi_chassis_attributes(chassis) != 0) {
+ ret = -3;
+ goto done;
+ }
+
+ ret = 0;
+
+done:
+ free_2d_buffer(&buffer, &buffer_size);
+
+ if (ret != 0) {
+ dmi_free_chassis(chassis);
+ }
+
+ return ret;
+}
+
+void dmi_free_chassis(DmiChassis *chassis)
+{
+ free(chassis->serial_number);
+ chassis->serial_number = NULL;
+ free(chassis->type);
+ chassis->type = NULL;
+ free(chassis->manufacturer);
+ chassis->manufacturer = NULL;
+ free(chassis->sku_number);
+ chassis->sku_number = NULL;
+ free(chassis->version);
+ chassis->version = NULL;
+}
+
diff --git a/src/hardware/dmidecode.h b/src/hardware/dmidecode.h
index d838cf5..0fe546c 100644
--- a/src/hardware/dmidecode.h
+++ b/src/hardware/dmidecode.h
@@ -91,6 +91,17 @@ typedef struct _DmiMemory {
unsigned modules_nb; /* Number of Memory Modules */
} DmiMemory;
+/* Chassis from dmidecode. */
+typedef struct _DmiChassis {
+ char *serial_number; /* Chassis serial number */
+ char *type; /* Chassis Type */
+ char *manufacturer; /* Chassis Manufacturer */
+ char *sku_number; /* Chassis SKU number */
+ char *version; /* Chassis Version */
+ short has_lock; /* Has chassis lock? 0 or 1 */
+ unsigned power_cords; /* Number of Power Cords */
+} DmiChassis;
+
/*
* Get array of processors according to the dmidecode program.
* @param cpu array of cpus, this function will allocate necessary memory,
@@ -137,5 +148,19 @@ short dmi_get_memory(DmiMemory *memory);
*/
void dmi_free_memory(DmiMemory *memory);
+/*
+ * Get chassis structure according to the dmidecode program.
+ * @param chassis structure, this function will allocate
+ * necessary memory, but caller is responsible for freeing it
+ * @return 0 if success, negative value otherwise
+ */
+short dmi_get_chassis(DmiChassis *chassis);
+
+/*
+ * Free chassis structure.
+ * @param chassis structure
+ */
+void dmi_free_chassis(DmiChassis *chassis);
+
#endif /* DMIDECODE_H_ */