Source code for inventory
"""inventory
=============
Utility functions for inventory scripts.
"""
import os
import json
import socket
[docs]def get_hostname():
    """Return FQDN for this host in lower case."""
    return socket.gethostname().lower()
 
[docs]def get_simple_hostname(fqdn):
    """Convert FQDN and return simple host name."""
    simple_hostname = fqdn.split('.')[0]
    return simple_hostname
 
[docs]def write_cache(cache_file, output):
    """Format and write inventory cache to file."""
    with open(cache_file, 'w') as cache:
        for line in format_output(output):
            cache.write(line)
 
[docs]def read_cache(cache_file):
    """Read cache file and return content or False."""
    if not os.path.isfile(cache_file):
        return False
    with open(cache_file, 'r') as cache:
        return cache.read()
 
if __name__ == '__main__':
    pass