| | |
| | | #include "../../base/base.h" |
| | | #include "../cpu_info.hpp" |
| | | #include "../execution_environment.hpp" |
| | | #include "../../base/file_utils.hpp" |
| | | #include "../../base/StringUtils.h" |
| | | |
| | | namespace license { |
| | | namespace os { |
| | | using namespace std; |
| | | |
| | | // 0=NO 1=Docker/2=Lxc |
| | |
| | | return result; |
| | | } |
| | | |
| | | VIRTUALIZATION ExecutionEnvironment::getVirtualization() { |
| | | VIRTUALIZATION result; |
| | | CpuInfo cpuInfo; |
| | | bool isContainer = checkContainerProc() != 0 || checkSystemdContainer() != 0; |
| | | if (isContainer) { |
| | | result = CONTAINER; |
| | | } else if (cpuInfo.cpu_virtual() || is_cloud()) { |
| | | result = VM; |
| | | } else { |
| | | result = NONE; |
| | | ExecutionEnvironment::ExecutionEnvironment() { |
| | | try { |
| | | m_bios_vendor = toupper_copy(trim_copy(get_file_contents("/sys/class/dmi/id/sys_vendor", 256))); |
| | | |
| | | } catch (...) { |
| | | } |
| | | return result; |
| | | try { |
| | | m_bios_description = toupper_copy(trim_copy(get_file_contents("/sys/class/dmi/id/modalias", 256))); |
| | | char last_char = m_bios_description[m_bios_description.length() - 1]; |
| | | if (last_char == '\r' || last_char == '\n') { |
| | | m_bios_description = m_bios_description.erase(m_bios_description.length() - 1); |
| | | } |
| | | } catch (...) { |
| | | } |
| | | try { |
| | | m_sys_vendor = get_file_contents("/sys/class/dmi/id/sys_vendor", 256); |
| | | char last_char = m_sys_vendor[m_sys_vendor.length() - 2]; |
| | | if (last_char == '\r' || last_char == '\n') { |
| | | m_sys_vendor = m_sys_vendor.erase(m_sys_vendor.length() - 1); |
| | | } |
| | | } catch (...) { |
| | | } |
| | | } |
| | | |
| | | bool ExecutionEnvironment::is_cloud() { return getCloudProvider() == NONE; } |
| | | bool ExecutionEnvironment::is_container() const { return (checkContainerProc() != 0 || checkSystemdContainer() != 0); } |
| | | |
| | | bool ExecutionEnvironment::is_docker() { return (checkContainerProc() == 1 || checkSystemdContainer() == 1); } |
| | | bool ExecutionEnvironment::is_docker() const { return (checkContainerProc() == 1 || checkSystemdContainer() == 1); } |
| | | |
| | | CLOUD_PROVIDER ExecutionEnvironment::getCloudProvider() {} |
| | | |
| | | |
| | | } // namespace os |
| | | } // namespace license |