Debian Codegraph @

lib/ansible/module_utils/facts/virtual/netbsd.py

raw
1 # This file is part of Ansible
2 #
3 # Ansible is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # Ansible is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
15
16 from __future__ import annotations
17
18 import os
19
20 from ansible.module_utils.facts.virtual.base import Virtual, VirtualCollector
21 from ansible.module_utils.facts.virtual.sysctl import VirtualSysctlDetectionMixin
22
23
24 class NetBSDVirtual(Virtual, VirtualSysctlDetectionMixin):
25 platform = 'NetBSD'
26
27 def get_virtual_facts(self):
28 virtual_facts = {}
29 host_tech = set()
30 guest_tech = set()
31
32 # Set empty values as default
33 virtual_facts['virtualization_type'] = ''
34 virtual_facts['virtualization_role'] = ''
35
36 virtual_product_facts = self.detect_virt_product('machdep.dmi.system-product')
37 guest_tech.update(virtual_product_facts['virtualization_tech_guest'])
38 host_tech.update(virtual_product_facts['virtualization_tech_host'])
39 virtual_facts.update(virtual_product_facts)
40
41 virtual_vendor_facts = self.detect_virt_vendor('machdep.dmi.system-vendor')
42 guest_tech.update(virtual_vendor_facts['virtualization_tech_guest'])
43 host_tech.update(virtual_vendor_facts['virtualization_tech_host'])
44
45 if virtual_facts['virtualization_type'] == '':
46 virtual_facts.update(virtual_vendor_facts)
47
48 # The above logic is tried first for backwards compatibility. If
49 # something above matches, use it. Otherwise if the result is still
50 # empty, try machdep.hypervisor.
51 virtual_vendor_facts = self.detect_virt_vendor('machdep.hypervisor')
52 guest_tech.update(virtual_vendor_facts['virtualization_tech_guest'])
53 host_tech.update(virtual_vendor_facts['virtualization_tech_host'])
54
55 if virtual_facts['virtualization_type'] == '':
56 virtual_facts.update(virtual_vendor_facts)
57
58 if os.path.exists('/dev/xencons'):
59 guest_tech.add('xen')
60
61 if virtual_facts['virtualization_type'] == '':
62 virtual_facts['virtualization_type'] = 'xen'
63 virtual_facts['virtualization_role'] = 'guest'
64
65 virtual_facts['virtualization_tech_guest'] = guest_tech
66 virtual_facts['virtualization_tech_host'] = host_tech
67 return virtual_facts
68
69
70 class NetBSDVirtualCollector(VirtualCollector):
71 _fact_class = NetBSDVirtual
72 _platform = 'NetBSD'