1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add OpenBSD virtualization facts. (#17227)

* Add OpenBSD virtualization facts.

Patch written by @jasperla.

Tested by various people on:
- virtualbox
- vmware esx(i) + fusion
- kvm (smartos + plain linux + a random cloud provider)

This patch is already present in the OpenBSD port of ansible.

* Rework diff to get rid of extra returns.

Requested by @bcoca.

While here, use four-space indentations of all code blocks.

* Set facts even if no match is found.

Discussed with @bcoca.

* Find sysctl via get_bin_path().

Requested by @bcoca.

* Fail if we do not find a sysctl binary.

* Do not fail if a sysctl binary is not found.

Just set empty fact values instead.
Requested by @bcoca.
This commit is contained in:
Patrik Lundin 2016-08-26 17:27:41 +02:00 committed by Brian Coca
parent b4a035718e
commit b4f338bca7

View file

@ -3171,8 +3171,49 @@ class OpenBSDVirtual(Virtual):
return self.facts
def get_virtual_facts(self):
sysctl_path = self.module.get_bin_path('sysctl')
if sysctl_path:
rc, out, err = self.module.run_command("%s -n hw.product" % sysctl_path)
if rc != 0:
self.facts['virtualization_type'] = ''
self.facts['virtualization_role'] = ''
elif re.match('(KVM|Bochs|SmartDC).*', out):
self.facts['virtualization_type'] = 'kvm'
self.facts['virtualization_role'] = 'guest'
elif re.match('.*VMware.*', out):
self.facts['virtualization_type'] = 'VMware'
self.facts['virtualization_role'] = 'guest'
elif out.rstrip() == 'VirtualBox':
self.facts['virtualization_type'] = 'virtualbox'
self.facts['virtualization_role'] = 'guest'
elif out.rstrip() == 'HVM domU':
self.facts['virtualization_type'] = 'xen'
self.facts['virtualization_role'] = 'guest'
elif out.rstrip() == 'Parallels':
self.facts['virtualization_type'] = 'parallels'
self.facts['virtualization_role'] = 'guest'
elif out.rstrip() == 'RHEV Hypervisor':
self.facts['virtualization_type'] = 'RHEV'
self.facts['virtualization_role'] = 'guest'
else:
# Try harder and see if hw.vendor has anything we could use.
rc, out, err = self.module.run_command("%s -n hw.vendor" % sysctl_path)
if rc != 0:
self.facts['virtualization_type'] = ''
self.facts['virtualization_role'] = ''
elif out.rstrip() == 'QEMU':
self.facts['virtualization_type'] = 'kvm'
self.facts['virtualization_role'] = 'guest'
else:
# Set empty values if we find no match at all.
self.facts['virtualization_type'] = ''
self.facts['virtualization_role'] = ''
else:
# Set empty values if we find no sysctl binary.
self.facts['virtualization_type'] = ''
self.facts['virtualization_role'] = ''
class HPUXVirtual(Virtual):
"""