@ -59,15 +59,16 @@ class Facts(object):
'/etc/vmware-release': 'VMwareESX' }
'/etc/vmware-release': 'VMwareESX' }
SELINUX_MODE_DICT = { 1: 'enforcing', 0: 'permissive', -1: 'disabled' }
SELINUX_MODE_DICT = { 1: 'enforcing', 0: 'permissive', -1: 'disabled' }
def __init__(self, facts):
def __init__(self):
self.facts = facts
self.facts = {}
def populate(self):
self.get_platform_facts()
self.get_platform_facts()
self.get_distribution_facts()
self.get_distribution_facts()
self.get_public_ssh_host_keys()
self.get_public_ssh_host_keys()
self.get_selinux_facts()
self.get_selinux_facts()
def populate(self):
return self.facts
# Platform
# Platform
# patform.system() can be Linux, Darwin, Java, or Windows
# patform.system() can be Linux, Darwin, Java, or Windows
def get_platform_facts(self):
def get_platform_facts(self):
@ -156,25 +157,18 @@ class Hardware(Facts):
"""
"""
platform = 'Generic'
platform = 'Generic'
def __new__(cls, facts, *arguments, **keyword):
def __new__(cls, *arguments, **keyword):
subclass = cls
subclass = cls
for sc in Hardware.__subclasses__():
for sc in Hardware.__subclasses__():
if sc.platform == platform.system():
if sc.platform == platform.system():
subclass = sc
subclass = sc
return super(cls, subclass).__new__(subclass, *arguments, **keyword)
return super(cls, subclass).__new__(subclass, *arguments, **keyword)
def __init__(self, facts):
def __init__(self):
Facts.__init__(self, facts)
Facts.__init__(self)
self.facts['memfree_mb'] = 'NA'
self.facts['memtotal_mb'] = 'NA'
self.facts['swapfree_mb'] = 'NA'
self.facts['swaptotal_mb'] = 'NA'
self.facts['processor'] = ['NA']
self.facts['processor_cores'] = 'NA'
self.facts['processor_count'] = 'NA'
def populate(self):
def populate(self):
pas s
return self.facts
class LinuxHardware(Hardware):
class LinuxHardware(Hardware):
"""
"""
@ -210,13 +204,14 @@ class LinuxHardware(Hardware):
"Rack Mount Chassis", "Sealed-case PC", "Multi-system",
"Rack Mount Chassis", "Sealed-case PC", "Multi-system",
"CompactPCI", "AdvancedTCA" ]
"CompactPCI", "AdvancedTCA" ]
def __init__(self, facts ):
def __init__(self):
Hardware.__init__(self, facts )
Hardware.__init__(self)
def populate(self):
def populate(self):
self.get_cpu_facts()
self.get_cpu_facts()
self.get_memory_facts()
self.get_memory_facts()
self.get_dmi_facts()
self.get_dmi_facts()
return self.facts
def get_memory_facts(self):
def get_memory_facts(self):
if not os.access("/proc/meminfo", os.R_OK):
if not os.access("/proc/meminfo", os.R_OK):
@ -274,12 +269,13 @@ class SunOSHardware(Hardware):
"""
"""
platform = 'SunOS'
platform = 'SunOS'
def __init__(self, facts ):
def __init__(self):
Hardware.__init__(self, facts )
Hardware.__init__(self)
def populate(self):
def populate(self):
self.get_cpu_facts()
self.get_cpu_facts()
self.get_memory_facts()
self.get_memory_facts()
return self.facts
def get_cpu_facts(self):
def get_cpu_facts(self):
cmd = subprocess.Popen("/usr/sbin/psrinfo -v", shell=True,
cmd = subprocess.Popen("/usr/sbin/psrinfo -v", shell=True,
@ -327,12 +323,13 @@ class FreeBSDHardware(Hardware):
platform = 'FreeBSD'
platform = 'FreeBSD'
DMESG_BOOT = '/var/run/dmesg.boot'
DMESG_BOOT = '/var/run/dmesg.boot'
def __init__(self, facts ):
def __init__(self):
Hardware.__init__(self, facts )
Hardware.__init__(self)
def populate(self):
def populate(self):
self.get_cpu_facts()
self.get_cpu_facts()
self.get_memory_facts()
self.get_memory_facts()
return self.facts
def get_cpu_facts(self):
def get_cpu_facts(self):
self.facts['processor'] = []
self.facts['processor'] = []
@ -387,19 +384,18 @@ class Network(Facts):
"""
"""
platform = 'Generic'
platform = 'Generic'
def __new__(cls, facts, *arguments, **keyword):
def __new__(cls, *arguments, **keyword):
subclass = cls
subclass = cls
for sc in Network.__subclasses__():
for sc in Network.__subclasses__():
if sc.platform == platform.system():
if sc.platform == platform.system():
subclass = sc
subclass = sc
return super(cls, subclass).__new__(subclass, *arguments, **keyword)
return super(cls, subclass).__new__(subclass, *arguments, **keyword)
def __init__(self, facts):
def __init__(self):
Facts.__init__(self, facts)
Facts.__init__(self)
self.facts['interfaces'] = ['NA']
def populate(self):
def populate(self):
pas s
return self.fact s
class LinuxNetwork(Network):
class LinuxNetwork(Network):
"""
"""
@ -411,11 +407,12 @@ class LinuxNetwork(Network):
SIOCGIFCONF = 0x8912
SIOCGIFCONF = 0x8912
SIOCGIFHWADDR = 0x8927
SIOCGIFHWADDR = 0x8927
def __init__(self, facts ):
def __init__(self):
Network.__init__(self, facts )
Network.__init__(self)
def populate(self):
def populate(self):
self.get_network_facts()
self.get_network_facts()
return self.facts
# get list of interfaces that are up
# get list of interfaces that are up
def get_interfaces(self):
def get_interfaces(self):
@ -501,20 +498,18 @@ class Virtual(Facts):
All subclasses MUST define platform.
All subclasses MUST define platform.
"""
"""
def __new__(cls, facts, *arguments, **keyword):
def __new__(cls, *arguments, **keyword):
subclass = cls
subclass = cls
for sc in Virtual.__subclasses__():
for sc in Virtual.__subclasses__():
if sc.platform == platform.system():
if sc.platform == platform.system():
subclass = sc
subclass = sc
return super(cls, subclass).__new__(subclass, *arguments, **keyword)
return super(cls, subclass).__new__(subclass, *arguments, **keyword)
def __init__(self, facts):
def __init__(self):
Facts.__init__(self, facts)
Facts.__init__(self)
self.facts['virtualization_type'] = 'NA'
self.facts['virtualization_role'] = 'NA'
def populate(self):
def populate(self):
pas s
return self.fact s
class LinuxVirtual(Virtual):
class LinuxVirtual(Virtual):
"""
"""
@ -524,11 +519,14 @@ class LinuxVirtual(Virtual):
"""
"""
platform = 'Linux'
platform = 'Linux'
def __init__(self, facts):
def __init__(self):
Virtual.__init__(self, facts)
Virtual.__init__(self)
self.facts = facts
def populate(self):
def populate(self):
self.get_virtual_facts()
return self.facts
def get_virtual_facts(self):
if os.path.exists("/proc/xen"):
if os.path.exists("/proc/xen"):
self.facts['virtualization_type'] = 'xen'
self.facts['virtualization_type'] = 'xen'
self.facts['virtualization_role'] = 'guest'
self.facts['virtualization_role'] = 'guest'
@ -548,10 +546,10 @@ class LinuxVirtual(Virtual):
elif 'vboxguest' in modules:
elif 'vboxguest' in modules:
self.facts['virtualization_type'] = 'virtualbox'
self.facts['virtualization_type'] = 'virtualbox'
self.facts['virtualization_role'] = 'guest'
self.facts['virtualization_role'] = 'guest'
if 'QEMU' in self.facts['processor'][0]:
if 'processor' in self.facts and ' QEMU' in self.facts['processor'][0]:
self.facts['virtualization_type'] = 'kvm'
self.facts['virtualization_type'] = 'kvm'
self.facts['virtualization_role'] = 'guest'
self.facts['virtualization_role'] = 'guest'
if self.facts['distribution'] == 'VMwareESX':
if 'distribution' in self.facts and self.facts['distribution'] == 'VMwareESX':
self.facts['virtualization_type'] = 'VMware'
self.facts['virtualization_type'] = 'VMware'
self.facts['virtualization_role'] = 'host'
self.facts['virtualization_role'] = 'host'
# You can spawn a dmidecode process and parse that or infer from devices
# You can spawn a dmidecode process and parse that or infer from devices
@ -566,15 +564,11 @@ class LinuxVirtual(Virtual):
def ansible_facts():
def ansible_facts():
facts = {}
facts = {}
f = Facts(facts)
facts.update(Facts().populate())
f.populate()
facts.update(Hardware().populate())
f = Hardware(f.facts)
facts.update(Network().populate())
f.populate()
facts.update(Virtual().populate())
f = Network(f.facts)
return facts
f.populate()
f = Virtual(f.facts)
f.populate()
return f.facts
# ===========================================
# ===========================================