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 /src/hardware | |
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
Diffstat (limited to 'src/hardware')
-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 |
4 files changed, 97 insertions, 1 deletions
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_ */ |