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 return self.facts
def get_virtual_facts(self): 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 # Check if it's a zone
if os.path.exists("/usr/bin/zonename"):
rc, out, err = self.module.run_command("/usr/bin/zonename") zonename = self.module.get_bin_path('zonename')
if out.rstrip() != "global": if zonename:
rc, out, err = self.module.run_command(zonename)
if rc == 0 and out.rstrip() != "global":
self.facts['container'] = 'zone' self.facts['container'] = 'zone'
# Check if it's a branded zone (i.e. Solaris 8/9 zone) # Check if it's a branded zone (i.e. Solaris 8/9 zone)
if os.path.isdir('/.SUNWnative'): 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. # 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 # Relies on the "guest tools" (e.g. vmware tools) to be installed
if 'container' in self.facts and self.facts['container'] == 'zone': 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'): for line in out.split('\n'):
if 'VMware' in line: if 'VMware' in line:
self.facts['virtualization_type'] = 'vmware' self.facts['virtualization_type'] = 'vmware'
@ -3282,8 +3274,14 @@ class SunOSVirtual(Virtual):
if 'VirtualBox' in line: if 'VirtualBox' in line:
self.facts['virtualization_type'] = 'virtualbox' self.facts['virtualization_type'] = 'virtualbox'
self.facts['virtualization_role'] = 'guest' 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 # 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 # 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. # 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") 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 # 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: # 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 # virtinfo can only be run from the global zone
if rc == 0:
try: try:
for line in out.split('\n'): for line in out.split('\n'):
fields = line.split('|') fields = line.split('|')
@ -3307,6 +3306,24 @@ class SunOSVirtual(Virtual):
except ValueError: except ValueError:
pass 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): class Ohai(Facts):
""" """
This is a subclass of Facts for including information gathered from Ohai. This is a subclass of Facts for including information gathered from Ohai.