diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2014-02-12 14:32:13 +0100 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2014-02-14 10:05:05 +0100 |
commit | 0440fdf8c954e2199ccee9c69afb5ec61203f53d (patch) | |
tree | 26e89732beef70c35f53f090e0722042cb2263b7 | |
parent | 09060b6b95fc0e6a00142a7e5e141797a1ee28ca (diff) | |
download | openlmi-providers-0440fdf8c954e2199ccee9c69afb5ec61203f53d.tar.gz openlmi-providers-0440fdf8c954e2199ccee9c69afb5ec61203f53d.tar.xz openlmi-providers-0440fdf8c954e2199ccee9c69afb5ec61203f53d.zip |
Hardware: added VirtualMachine field to the Chassis provider
-rw-r--r-- | mof/60_LMI_Hardware.mof | 5 | ||||
-rw-r--r-- | openlmi-providers.spec | 6 | ||||
-rw-r--r-- | src/hardware/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/hardware/LMI_ChassisProvider.c | 9 | ||||
-rw-r--r-- | src/hardware/virt_what.c | 54 | ||||
-rw-r--r-- | src/hardware/virt_what.h | 34 |
6 files changed, 106 insertions, 3 deletions
diff --git a/mof/60_LMI_Hardware.mof b/mof/60_LMI_Hardware.mof index 4639978..977ddad 100644 --- a/mof/60_LMI_Hardware.mof +++ b/mof/60_LMI_Hardware.mof @@ -511,7 +511,7 @@ class LMI_MemorySystemDevice: CIM_SystemDevice * Physical Asset */ -[ Version("0.2.0"), Provider("cmpi:cmpiLMI_Chassis") ] +[ Version("0.3.0"), Provider("cmpi:cmpiLMI_Chassis") ] class LMI_Chassis: CIM_Chassis { [ Implemented(true), Description("Product name.") ] @@ -567,6 +567,9 @@ class LMI_Chassis: CIM_Chassis [ Implemented(true), Override("NumberOfPowerCords") ] uint16 NumberOfPowerCords; + + [ Implemented(true), Description("Type of virtualization technology.") ] + string VirtualMachine; }; [ Version("0.2.0"), Provider("cmpi:cmpiLMI_Baseboard") ] diff --git a/openlmi-providers.spec b/openlmi-providers.spec index 484c403..a6ac551 100644 --- a/openlmi-providers.spec +++ b/openlmi-providers.spec @@ -4,7 +4,7 @@ Name: openlmi-providers Version: 0.4.2 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Set of basic CIM providers %if 0%{?suse_version} @@ -227,6 +227,7 @@ Requires: sblim-cmpi-base %endif Requires: util-linux Requires: smartmontools +Requires: virt-what %description -n openlmi-hardware %{summary}. @@ -1043,6 +1044,9 @@ if [ "$1" -eq 0 ]; then fi >> %logfile 2>&1 %changelog +* Wed Feb 12 2014 Peter Schiffer <pschiffe@redhat.com> 0.4.2-2 +- Added dependency on virt-what to hardware subpackage + * Tue Jan 7 2014 Jan Safranek <jsafrane@redhat.com> 0.4.2-1 - Version 0.4.2 diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt index 74a20d0..29b63d3 100644 --- a/src/hardware/CMakeLists.txt +++ b/src/hardware/CMakeLists.txt @@ -12,6 +12,7 @@ set(provider_SRCS PCIDev.c smartctl.c lsblk.c + virt_what.c ) konkretcmpi_generate(${MOF} diff --git a/src/hardware/LMI_ChassisProvider.c b/src/hardware/LMI_ChassisProvider.c index 21eb83e..ef8567a 100644 --- a/src/hardware/LMI_ChassisProvider.c +++ b/src/hardware/LMI_ChassisProvider.c @@ -23,6 +23,7 @@ #include "LMI_Hardware.h" #include "globals.h" #include "dmidecode.h" +#include "virt_what.h" CMPIUint16 get_chassis_type(const char *dmi_chassis); @@ -60,7 +61,7 @@ static CMPIStatus LMI_ChassisEnumInstances( { LMI_Chassis lmi_chassis; const char *ns = KNameSpace(cop); - char instance_id[INSTANCE_ID_LEN], *tag; + char instance_id[INSTANCE_ID_LEN], *tag, *virt = NULL; DmiChassis dmi_chassis; if (dmi_get_chassis(&dmi_chassis) != 0) { @@ -106,6 +107,12 @@ static CMPIStatus LMI_ChassisEnumInstances( LMI_Chassis_Set_NumberOfPowerCords(&lmi_chassis, dmi_chassis.power_cords); } + if (virt_what_get_virtual_type(&virt) == 0 && virt && strlen(virt)) { + LMI_Chassis_Set_VirtualMachine(&lmi_chassis, virt); + } else { + LMI_Chassis_Set_VirtualMachine(&lmi_chassis, "No"); + } + free(virt); KReturnInstance(cr, lmi_chassis); diff --git a/src/hardware/virt_what.c b/src/hardware/virt_what.c new file mode 100644 index 0000000..83fc3d8 --- /dev/null +++ b/src/hardware/virt_what.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2013-2014 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 "utils.h" +#include "virt_what.h" + + +short virt_what_get_virtual_type(char **virt) +{ + short ret = -1; + unsigned buffer_size = 0; + char **buffer = NULL; + + *virt = NULL; + + /* get virt-what output */ + if (run_command("virt-what", &buffer, &buffer_size) != 0) { + goto done; + } + + if (buffer_size > 0) { + if (!(*virt = strdup(buffer[0]))) { + goto done; + } + } else { + if (!(*virt = strdup(""))) { + goto done; + } + } + + ret = 0; + +done: + free_2d_buffer(&buffer, &buffer_size); + + return ret; +} diff --git a/src/hardware/virt_what.h b/src/hardware/virt_what.h new file mode 100644 index 0000000..b133136 --- /dev/null +++ b/src/hardware/virt_what.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2013-2014 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> + */ + +#ifndef VIRT_WHAT_H_ +#define VIRT_WHAT_H_ + + +/* + * Get virtual machine type if running as a virtual machine. If running in + * bare metal, virt will be empty string. + * @param virt, should be NULL, function will dynamically allocate it + * @return 0 if success, negative value otherwise + */ +short virt_what_get_virtual_type(char **virt); + + +#endif /* VIRT_WHAT_H_ */ |