| 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 |
import re |
| 20 |
|
| 21 |
from ansible.module_utils.facts.virtual.base import Virtual, VirtualCollector |
| 22 |
|
| 23 |
|
| 24 |
class HPUXVirtual(Virtual): |
| 25 |
""" |
| 26 |
This is a HP-UX specific subclass of Virtual. It defines |
| 27 |
- virtualization_type |
| 28 |
- virtualization_role |
| 29 |
""" |
| 30 |
platform = 'HP-UX' |
| 31 |
|
| 32 |
def get_virtual_facts(self): |
| 33 |
virtual_facts = {} |
| 34 |
host_tech = set() |
| 35 |
guest_tech = set() |
| 36 |
|
| 37 |
if os.path.exists('/usr/sbin/vecheck'): |
| 38 |
rc, out, err = self.module.run_command("/usr/sbin/vecheck") |
| 39 |
if rc == 0: |
| 40 |
guest_tech.add('HP vPar') |
| 41 |
virtual_facts['virtualization_type'] = 'guest' |
| 42 |
virtual_facts['virtualization_role'] = 'HP vPar' |
| 43 |
if os.path.exists('/opt/hpvm/bin/hpvminfo'): |
| 44 |
rc, out, err = self.module.run_command("/opt/hpvm/bin/hpvminfo") |
| 45 |
if rc == 0 and re.match('.*Running.*HPVM vPar.*', out): |
| 46 |
guest_tech.add('HPVM vPar') |
| 47 |
virtual_facts['virtualization_type'] = 'guest' |
| 48 |
virtual_facts['virtualization_role'] = 'HPVM vPar' |
| 49 |
elif rc == 0 and re.match('.*Running.*HPVM guest.*', out): |
| 50 |
guest_tech.add('HPVM IVM') |
| 51 |
virtual_facts['virtualization_type'] = 'guest' |
| 52 |
virtual_facts['virtualization_role'] = 'HPVM IVM' |
| 53 |
elif rc == 0 and re.match('.*Running.*HPVM host.*', out): |
| 54 |
guest_tech.add('HPVM') |
| 55 |
virtual_facts['virtualization_type'] = 'host' |
| 56 |
virtual_facts['virtualization_role'] = 'HPVM' |
| 57 |
if os.path.exists('/usr/sbin/parstatus'): |
| 58 |
rc, out, err = self.module.run_command("/usr/sbin/parstatus") |
| 59 |
if rc == 0: |
| 60 |
guest_tech.add('HP nPar') |
| 61 |
virtual_facts['virtualization_type'] = 'guest' |
| 62 |
virtual_facts['virtualization_role'] = 'HP nPar' |
| 63 |
|
| 64 |
virtual_facts['virtualization_tech_guest'] = guest_tech |
| 65 |
virtual_facts['virtualization_tech_host'] = host_tech |
| 66 |
return virtual_facts |
| 67 |
|
| 68 |
|
| 69 |
class HPUXVirtualCollector(VirtualCollector): |
| 70 |
_fact_class = HPUXVirtual |
| 71 |
_platform = 'HP-UX' |