mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #850 from akhayyat/virt-facts
Add openvz detection to virtualization facts, and some cleanup
This commit is contained in:
commit
e0765be1ea
1 changed files with 24 additions and 19 deletions
|
@ -565,10 +565,31 @@ class LinuxVirtual(Virtual):
|
||||||
def get_virtual_facts(self):
|
def get_virtual_facts(self):
|
||||||
if os.path.exists("/proc/xen"):
|
if os.path.exists("/proc/xen"):
|
||||||
self.facts['virtualization_type'] = 'xen'
|
self.facts['virtualization_type'] = 'xen'
|
||||||
self.facts['virtualization_role'] = 'guest'
|
if os.path.exists('/proc/xen/capabilities'):
|
||||||
if os.path.exists("/proc/xen/capabilities"):
|
|
||||||
self.facts['virtualization_role'] = 'host'
|
self.facts['virtualization_role'] = 'host'
|
||||||
if os.path.exists("/proc/modules"):
|
else:
|
||||||
|
self.facts['virtualization_role'] = 'guest'
|
||||||
|
|
||||||
|
elif os.path.exists('/proc/vz'):
|
||||||
|
self.facts['virtualization_type'] = 'openvz'
|
||||||
|
if os.path.exists('/proc/vz/version'):
|
||||||
|
self.facts['virtualization_role'] = 'host'
|
||||||
|
else:
|
||||||
|
self.facts['virtualization_role'] = 'guest'
|
||||||
|
|
||||||
|
elif get_file_content('/sys/devices/virtual/dmi/id/product_name') in ['KVM','Bochs']:
|
||||||
|
self.facts['virtualization_type'] = 'kvm'
|
||||||
|
self.facts['virtualization_role'] = 'guest'
|
||||||
|
|
||||||
|
elif get_file_content('/sys/devices/virtual/dmi/id/sys_vendor') == 'VMware, Inc.':
|
||||||
|
self.facts['virtualization_type'] = 'VMware'
|
||||||
|
self.facts['virtualization_role'] = 'guest'
|
||||||
|
|
||||||
|
elif get_file_content('/sys/devices/virtual/dmi/id/sys_vendor') == 'Microsoft Corporation':
|
||||||
|
self.facts['virtualization_type'] = 'VirtualPC'
|
||||||
|
self.facts['virtualization_role'] = 'guest'
|
||||||
|
|
||||||
|
elif os.path.exists("/proc/modules"):
|
||||||
modules = []
|
modules = []
|
||||||
for line in open("/proc/modules").readlines():
|
for line in open("/proc/modules").readlines():
|
||||||
data = line.split(" ", 1)
|
data = line.split(" ", 1)
|
||||||
|
@ -582,22 +603,6 @@ class LinuxVirtual(Virtual):
|
||||||
elif 'vboxguest' in modules:
|
elif 'vboxguest' in modules:
|
||||||
self.facts['virtualization_type'] = 'virtualbox'
|
self.facts['virtualization_type'] = 'virtualbox'
|
||||||
self.facts['virtualization_role'] = 'guest'
|
self.facts['virtualization_role'] = 'guest'
|
||||||
data = get_file_content('/proc/cpuinfo')
|
|
||||||
if 'QEMU' in data:
|
|
||||||
self.facts['virtualization_type'] = 'kvm'
|
|
||||||
self.facts['virtualization_role'] = 'guest'
|
|
||||||
if 'distribution' in self.facts and self.facts['distribution'] == 'VMwareESX':
|
|
||||||
self.facts['virtualization_type'] = 'VMware'
|
|
||||||
self.facts['virtualization_role'] = 'host'
|
|
||||||
# You can spawn a dmidecode process and parse that or infer from devices
|
|
||||||
for dev_model in glob.glob('/sys/block/?da/device/vendor'):
|
|
||||||
info = open(dev_model).read()
|
|
||||||
if 'VMware' in info:
|
|
||||||
self.facts['virtualization_type'] = 'VMware'
|
|
||||||
self.facts['virtualization_role'] = 'guest'
|
|
||||||
elif 'Virtual HD' in info or 'Virtual CD' in info:
|
|
||||||
self.facts['virtualization_type'] = 'VirtualPC'
|
|
||||||
self.facts['virtualization_role'] = 'guest'
|
|
||||||
|
|
||||||
def get_file_content(path):
|
def get_file_content(path):
|
||||||
data = None
|
data = None
|
||||||
|
|
Loading…
Reference in a new issue