ifxlookup/servicebase.py

57 lines
1.9 KiB
Python
Raw Normal View History

class ServiceBase :
config = {}
namespace = {}
data = {}
_status = "Ready"
_subjects = []
def __init__(self,config,namespace,subjects,dossiercopy):
if not config or config == {} :
self._status = "Error"
else :
self.config = config
self.data = dossiercopy
self.namespace = namespace
self._subjects = subjects
pass
def _lookup_subjects(self) :
args = self.get_arguments()
if args :
args = args[1][2:]
if getattr(self.namespace,args) == False and getattr(self.namespace,'all') == False :
return None
finaldictionary = {}
self.startup()
for item in self._subjects :
finaldictionary.update({item:self.perform_lookup(item)})
self.shutdown()
return finaldictionary
@classmethod
def get_arguments(cls) :
"""Returns an array of information used to construct an argumentparser argument."""
# [ <short flag>,<unix flag>,<arg type>,<description> ]
# Example return: [ '-n', '--net', 'store_true', "Output network information about the subject" ]
return None
def startup(self) :
"""Perform any setup that is needed to perform lookups, such as logging in or obtaining auth sessions."""
pass
def perform_lookup(self,host_tuple) :
"""Returns a dictionary with lookup information about the given IP or Hostname."""
# host_tuple is a socket triple (hostname, aliaslist, ipaddrlist) where hostname is
# the primary host name responding to the given ip_address, aliaslist is a (possibly
# empty) tuple of alternative host names for the same address, and ipaddrlist is a tuple
# of IPv4/v6 addresses for the same interface on the same host (most likely containing
# only a single address).
# Note: You should only return arrays and dictionaries with strings as keys so the information
# serializes correctly.
return None
def shutdown(self) :
"""Perform any cleanup that is needed, such as logging out of auth sessions."""
pass