mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Check presence of files under /proc before opening them
This commit is contained in:
parent
8b27085c34
commit
5e68143c46
1 changed files with 25 additions and 23 deletions
|
@ -967,30 +967,32 @@ class LinuxVirtual(Virtual):
|
||||||
self.facts['virtualization_role'] = 'guest'
|
self.facts['virtualization_role'] = 'guest'
|
||||||
return
|
return
|
||||||
|
|
||||||
for line in open('/proc/self/status').readlines():
|
if os.path.exists('/proc/self/status'):
|
||||||
if re.match('^VxID: \d+', line):
|
for line in open('/proc/self/status').readlines():
|
||||||
self.facts['virtualization_type'] = 'linux_vserver'
|
if re.match('^VxID: \d+', line):
|
||||||
if re.match('^VxID: 0', line):
|
self.facts['virtualization_type'] = 'linux_vserver'
|
||||||
self.facts['virtualization_role'] = 'host'
|
if re.match('^VxID: 0', line):
|
||||||
else:
|
self.facts['virtualization_role'] = 'host'
|
||||||
self.facts['virtualization_role'] = 'guest'
|
else:
|
||||||
return
|
self.facts['virtualization_role'] = 'guest'
|
||||||
|
return
|
||||||
|
|
||||||
for line in open('/proc/cpuinfo').readlines():
|
if os.path.exists('/proc/cpuinfo'):
|
||||||
if re.match('^model name.*QEMU Virtual CPU', line):
|
for line in open('/proc/cpuinfo').readlines():
|
||||||
self.facts['virtualization_type'] = 'kvm'
|
if re.match('^model name.*QEMU Virtual CPU', line):
|
||||||
elif re.match('^vendor_id.*User Mode Linux', line):
|
self.facts['virtualization_type'] = 'kvm'
|
||||||
self.facts['virtualization_type'] = 'uml'
|
elif re.match('^vendor_id.*User Mode Linux', line):
|
||||||
elif re.match('^model name.*UML', line):
|
self.facts['virtualization_type'] = 'uml'
|
||||||
self.facts['virtualization_type'] = 'uml'
|
elif re.match('^model name.*UML', line):
|
||||||
elif re.match('^vendor_id.*PowerVM Lx86', line):
|
self.facts['virtualization_type'] = 'uml'
|
||||||
self.facts['virtualization_type'] = 'powervm_lx86'
|
elif re.match('^vendor_id.*PowerVM Lx86', line):
|
||||||
elif re.match('^vendor_id.*IBM/S390', line):
|
self.facts['virtualization_type'] = 'powervm_lx86'
|
||||||
self.facts['virtualization_type'] = 'ibm_systemz'
|
elif re.match('^vendor_id.*IBM/S390', line):
|
||||||
else:
|
self.facts['virtualization_type'] = 'ibm_systemz'
|
||||||
continue
|
else:
|
||||||
self.facts['virtualization_role'] = 'guest'
|
continue
|
||||||
return
|
self.facts['virtualization_role'] = 'guest'
|
||||||
|
return
|
||||||
|
|
||||||
# Beware that we can have both kvm and virtualbox running on a single system
|
# Beware that we can have both kvm and virtualbox running on a single system
|
||||||
if os.path.exists("/proc/modules"):
|
if os.path.exists("/proc/modules"):
|
||||||
|
|
Loading…
Reference in a new issue