updated solaris virtualization detection (#17464)

avoid prtdiag since it seems to hang and require service restarts
hopefully fixes #4583
This commit is contained in:
Brian Coca 2016-09-13 09:03:05 -04:00 committed by GitHub
parent 036650cb09
commit 8ebd8ca259

View file

@ -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,7 +3263,10 @@ 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")
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'
@ -3282,8 +3274,14 @@ class SunOSVirtual(Virtual):
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,6 +3289,7 @@ 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
if rc == 0:
try:
for line in out.split('\n'):
fields = line.split('|')
@ -3307,6 +3306,24 @@ class SunOSVirtual(Virtual):
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'):
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'
class Ohai(Facts):
"""
This is a subclass of Facts for including information gathered from Ohai.