mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
updated solaris virtualization detection (#17464)
avoid prtdiag since it seems to hang and require service restarts hopefully fixes #4583
This commit is contained in:
parent
036650cb09
commit
8ebd8ca259
1 changed files with 56 additions and 39 deletions
|
@ -3249,24 +3249,13 @@ class SunOSVirtual(Virtual):
|
|||
return self.facts
|
||||
|
||||
def get_virtual_facts(self):
|
||||
rc, out, err = self.module.run_command("/usr/sbin/prtdiag")
|
||||
for line in out.split('\n'):
|
||||
if 'VMware' in line:
|
||||
self.facts['virtualization_type'] = 'vmware'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
if 'Parallels' in line:
|
||||
self.facts['virtualization_type'] = 'parallels'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
if 'VirtualBox' in line:
|
||||
self.facts['virtualization_type'] = 'virtualbox'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
if 'HVM domU' in line:
|
||||
self.facts['virtualization_type'] = 'xen'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
|
||||
# Check if it's a zone
|
||||
if os.path.exists("/usr/bin/zonename"):
|
||||
rc, out, err = self.module.run_command("/usr/bin/zonename")
|
||||
if out.rstrip() != "global":
|
||||
|
||||
zonename = self.module.get_bin_path('zonename')
|
||||
if zonename:
|
||||
rc, out, err = self.module.run_command(zonename)
|
||||
if rc == 0 and out.rstrip() != "global":
|
||||
self.facts['container'] = 'zone'
|
||||
# Check if it's a branded zone (i.e. Solaris 8/9 zone)
|
||||
if os.path.isdir('/.SUNWnative'):
|
||||
|
@ -3274,16 +3263,25 @@ class SunOSVirtual(Virtual):
|
|||
# If it's a zone check if we can detect if our global zone is itself virtualized.
|
||||
# Relies on the "guest tools" (e.g. vmware tools) to be installed
|
||||
if 'container' in self.facts and self.facts['container'] == 'zone':
|
||||
rc, out, err = self.module.run_command("/usr/sbin/modinfo")
|
||||
for line in out.split('\n'):
|
||||
if 'VMware' in line:
|
||||
self.facts['virtualization_type'] = 'vmware'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
if 'VirtualBox' in line:
|
||||
self.facts['virtualization_type'] = 'virtualbox'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
modinfo = self.module.get_bin_path('modinfo')
|
||||
if modinfo:
|
||||
rc, out, err = self.module.run_command(modinfo)
|
||||
if rc == 0:
|
||||
for line in out.split('\n'):
|
||||
if 'VMware' in line:
|
||||
self.facts['virtualization_type'] = 'vmware'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
if 'VirtualBox' in line:
|
||||
self.facts['virtualization_type'] = 'virtualbox'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
|
||||
if os.path.exists('/proc/vz'):
|
||||
self.facts['virtualization_type'] = 'virtuozzo'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
|
||||
# Detect domaining on Sparc hardware
|
||||
if os.path.exists("/usr/sbin/virtinfo"):
|
||||
virtinfo = self.module.get_bin_path('virtinfo')
|
||||
if virtinfo:
|
||||
# The output of virtinfo is different whether we are on a machine with logical
|
||||
# domains ('LDoms') on a T-series or domains ('Domains') on a M-series. Try LDoms first.
|
||||
rc, out, err = self.module.run_command("/usr/sbin/virtinfo -p")
|
||||
|
@ -3291,21 +3289,40 @@ class SunOSVirtual(Virtual):
|
|||
# DOMAINROLE|impl=LDoms|control=false|io=false|service=false|root=false
|
||||
# The output may also be not formatted and the returncode is set to 0 regardless of the error condition:
|
||||
# virtinfo can only be run from the global zone
|
||||
try:
|
||||
if rc == 0:
|
||||
try:
|
||||
for line in out.split('\n'):
|
||||
fields = line.split('|')
|
||||
if( fields[0] == 'DOMAINROLE' and fields[1] == 'impl=LDoms' ):
|
||||
self.facts['virtualization_type'] = 'ldom'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
hostfeatures = []
|
||||
for field in fields[2:]:
|
||||
arg = field.split('=')
|
||||
if( arg[1] == 'true' ):
|
||||
hostfeatures.append(arg[0])
|
||||
if( len(hostfeatures) > 0 ):
|
||||
self.facts['virtualization_role'] = 'host (' + ','.join(hostfeatures) + ')'
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
else:
|
||||
smbios = self.module.get_bin_path('smbios')
|
||||
rc, out, err = self.module.run_command(smbios)
|
||||
if rc == 0:
|
||||
for line in out.split('\n'):
|
||||
fields = line.split('|')
|
||||
if( fields[0] == 'DOMAINROLE' and fields[1] == 'impl=LDoms' ):
|
||||
self.facts['virtualization_type'] = 'ldom'
|
||||
if 'VMware' in line:
|
||||
self.facts['virtualization_type'] = 'vmware'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
elif 'Parallels' in line:
|
||||
self.facts['virtualization_type'] = 'parallels'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
elif 'VirtualBox' in line:
|
||||
self.facts['virtualization_type'] = 'virtualbox'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
elif 'HVM domU' in line:
|
||||
self.facts['virtualization_type'] = 'xen'
|
||||
self.facts['virtualization_role'] = 'guest'
|
||||
hostfeatures = []
|
||||
for field in fields[2:]:
|
||||
arg = field.split('=')
|
||||
if( arg[1] == 'true' ):
|
||||
hostfeatures.append(arg[0])
|
||||
if( len(hostfeatures) > 0 ):
|
||||
self.facts['virtualization_role'] = 'host (' + ','.join(hostfeatures) + ')'
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
class Ohai(Facts):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue