def get(self, hostname): """Search for RPMs installed on given hostname""" cache = request.args.get('nocache') output = request.args.get('format') handler = OutputHandler(cache, output, request.url_rule.rule, request.base_url) if handler.cache: data = {"last-update": timestamp(), hostname: gather_rpms(hostname, username=SSH_USERNAME)} return handler.formatter(data) else: data = {"last-update": rpm_data.cached_rpms['last-update'], hostname: rpm_data.cached_rpms.get(hostname)} return handler.formatter(data)
def get(self, hostname): """List disk space for hostname""" cache = request.args.get('nocache') output = request.args.get('format') handler = OutputHandler(cache, output, request.url_rule.rule, request.base_url) if handler.cache: return handler.formatter( {"last-update": timestamp(), hostname: diskspace_output(hostname, username=SSH_USERNAME)}) else: return handler.formatter( {"last-update": diskspace_data.cached_diskspace['last-update'], hostname: diskspace_data.cached_diskspace.get(hostname)})
def get(self, hostname): """Search netstat info by hostname""" cache = request.args.get('nocache') output = request.args.get('format') handler = OutputHandler(cache, output, request.url_rule.rule, request.base_url) if cache and cache.lower() == 'true': return handler.formatter( {"last-update": timestamp(), hostname: netstat_output(hostname, username=SSH_USERNAME)}) else: return handler.formatter( {"last-update": netstat_data.cached_netstat['last-update'], hostname: netstat_data.cached_netstat.get(hostname)})
def get(self, rpmname): """Search for RPM by name or Regular Expression""" cache = request.args.get('nocache') output = request.args.get('format') handler = OutputHandler(cache, output, request.url_rule.rule, request.base_url) if handler.cache: data = rpm_search(rpmname, rpm_data.rpms(cached=False)) data["last-update"] = timestamp() return handler.formatter(data) else: data = rpm_search(rpmname, rpm_data.cached_rpms) data["last-update"] = rpm_data.cached_rpms['last-update'] return handler.formatter(data)
class DiskspaceData(Hosts): cached_diskspace = {"last-update": timestamp()} @classmethod def update_cached_diskspace(cls): for host in cls.cached_hosts: cls.cached_diskspace[host] = diskspace_output( host, username=SSH_USERNAME) cls.cached_diskspace['last-update'] = timestamp() return cls.cached_diskspace @classmethod def diskspace(cls, cached=True): if cached: return cls.cached_diskspace else: return cls.update_cached_diskspace()
class NetstatData(Hosts): cached_netstat = {"last-update": timestamp()} @classmethod def update_cached_netstat(cls): for host in cls.cached_hosts: cls.cached_netstat[host] = netstat_output(host, username=SSH_USERNAME) cls.cached_netstat['last-update'] = timestamp() return cls.cached_netstat @classmethod def netstat(cls, cached=True): if cached: return cls.cached_netstat else: return cls.update_cached_netstat()
class RPMData(Hosts): cached_rpms = { "last-update": timestamp(), } @classmethod def update_cached_rpms(cls): for host in cls.cached_hosts: cls.cached_rpms[host] = gather_rpms(host, username=SSH_USERNAME) cls.cached_rpms['last-update'] = timestamp() return cls.cached_rpms @classmethod def rpms(cls, cached=True): if cached: return cls.cached_rpms else: return cls.update_cached_rpms()
def update_cached_diskspace(cls): for host in cls.cached_hosts: cls.cached_diskspace[host] = diskspace_output( host, username=SSH_USERNAME) cls.cached_diskspace['last-update'] = timestamp() return cls.cached_diskspace
def update_cached_netstat(cls): for host in cls.cached_hosts: cls.cached_netstat[host] = netstat_output(host, username=SSH_USERNAME) cls.cached_netstat['last-update'] = timestamp() return cls.cached_netstat
def update_cached_rpms(cls): for host in cls.cached_hosts: cls.cached_rpms[host] = gather_rpms(host, username=SSH_USERNAME) cls.cached_rpms['last-update'] = timestamp() return cls.cached_rpms