gcontini
2020-03-14 79b1b57045e86d9845e352c3f2aa0efbab6111a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * virtualization.hpp
 *
 *  Created on: Dec 15, 2019
 *      Author: GC
 */
 
#ifndef SRC_LIBRARY_OS_VIRTUALIZATION_HPP_
#define SRC_LIBRARY_OS_VIRTUALIZATION_HPP_
 
#include <string>
 
namespace license {
namespace os {
 
/*
 * windows bios sometimes reports vm names add execution environment detection from bios
const char *vmVendors[] = {
    "VMware", "Microsoft Corporation", "Virtual Machine", "innotek GmbH", "PowerVM", "Bochs", "KVM"};
*/
 
typedef enum { NONE, CONTAINER, VM } VIRTUALIZATION;
 
typedef enum {
    PROV_UNKNOWN,
    ON_PREMISE,
    GOOGLE_CLOUD,
    AZURE_CLOUD,
    AWS,
    /**
     * "/sys/class/dmi/id/bios_vendor" SeaBIOS
     * "/sys/class/dmi/id/sys_vendor" Alibaba Cloud
     * modalias
     * "dmi:bvnSeaBIOS:bvrrel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org:bd04/01/2014:svnAlibabaCloud:pnAlibabaCloudECS:pvrpc-i440fx-2.1:cvnAlibabaCloud:ct1:cvrpc-i440fx-2.1:"
     */
    ALI_CLOUD
} CLOUD_PROVIDER;
 
class ExecutionEnvironment {
private:
    std::string m_sys_vendor;
    std::string m_bios_vendor;
    std::string m_bios_description;
 
public:
    ExecutionEnvironment();
    ~ExecutionEnvironment(){};
    VIRTUALIZATION getVirtualization() const;
    bool is_cloud() const;
    bool is_docker() const;
    // detect if it's a kind of container technology (docker or lxc)
    bool is_container() const;
    CLOUD_PROVIDER getCloudProvider() const;
    const std::string& bios_vendor() const { return m_bios_vendor; };
    const std::string& sys_vendor() const { return m_sys_vendor; };
    const std::string& bios_description() const { return m_bios_description; };
    // VIRTUALIZATION_DETAIL getVirtualizationDetail() const; //as reported by the bios
};
 
}  // namespace os
}  // namespace license
 
#endif /* SRC_LIBRARY_OS_VIRTUALIZATION_HPP_ */