More stuff, can't really remember

I need to finish up some of the F5 features but I'm starting on Aruba anyway
This commit is contained in:
Daniel Dayley 2019-12-09 15:23:44 -07:00
parent 8d578dc9bf
commit 8ac4d52d5f
4 changed files with 25 additions and 16 deletions

24
ifxtool
View File

@ -20,8 +20,8 @@ class IFXTool():
configfilename = 'ifxtool.yml'
servicetemplate = {'hosts':[],'username':'','key':''}
configtemplate = {'bluecat':servicetemplate,'f5':servicetemplate,'paloalto':servicetemplate,'aruba':servicetemplate,'openvpn':servicetemplate}
errorinfo = []
warninfo = []
errorinfo = {}
warninfo = {}
namespace = ''
servicedelegates = []
totalconfig = {}
@ -37,8 +37,7 @@ class IFXTool():
self.totalconfig = yaml.safe_load(open(os.path.normpath(arglist.config)))
except Exception as exception :
#self.errorinfo = str(exception.__class__.__name__) + ': ' + str(exception)
self.errorinfo.append("There was a problem reading your config file, aborting.")
self.errorinfo.update({"config": "There was a problem reading your config file, aborting."})
else :
try:
self.totalconfig = yaml.safe_load(open(self.configdir + '/' + self.configfilename))
@ -48,13 +47,13 @@ class IFXTool():
if not os.path.exists(os.path.normpath(self.configdir + '/' + self.configfilename)):
with open(self.configdir + '/' + self.configfilename, 'w') as output :
yaml.dump(self.configtemplate, output)
self.errorinfo.append('Config file ' + self.configdir + '/' + self.configfilename + ' is empty, aborting.')
self.errorinfo.update({'config': 'Config file ' + self.configdir + '/' + self.configfilename + ' is empty, aborting.'})
else :
self.errorinfo.append("There was a problem reading your config file, aborting.")
self.errorinfo.update({"config": "There was a problem reading your config file, aborting."})
if self.totalconfig == {} :
with open(self.configdir + '/' + self.configfilename, 'w') as output :
yaml.dump(self.configtemplate, output)
self.errorinfo.append('Config file ' + self.configdir + '/' + self.configfilename + ' is empty, populating with a template.')
self.errorinfo.udpate({'config': 'Config file ' + self.configdir + '/' + self.configfilename + ' is empty, populating with a template.'})
def dispatch(self) :
@ -70,7 +69,7 @@ class IFXTool():
subjecttuple = socket.gethostbyname_ex(item)
except socket.gaierror :
# Not a valid host or IP
self.warninfo.append("Unable to resolve " + item)
self.warninfo.update({"resolution": "Unable to resolve " + item})
#self.namespace.subjects.remove(item)
#continue
subjecttuple = [item,[],['']]
@ -83,7 +82,7 @@ class IFXTool():
self._subjecttuples.append(immutablesubjecttuple)
# Stop on initialization error
if self.errorinfo != [] :
if self.errorinfo != {} :
self._internal_messages['error'] = self.errorinfo
exit(1)
@ -96,14 +95,17 @@ class IFXTool():
else :
delegateconfig = {}
delegateinstance = delegate(delegateconfig,self.namespace,self._subjecttuples,delegatereports)
#print(delegatename + ": " + delegateinstance._status)
delegateresponse = delegateinstance._lookup_subjects()
if delegateinstance.error != [] :
self.errorinfo.update({delegatename:delegateinstance.error})
if delegateresponse:
delegatereports.update({delegatename:delegateresponse})
# Format and display results
if self.warninfo != [] :
if self.warninfo != {} :
self._internal_messages['warn'] = self.warninfo
if self.errorinfo != {} :
self._internal_messages['error'] = self.errorinfo
delegatereports.update(self._internal_messages)
self.print_results(delegatereports)

View File

@ -8,9 +8,9 @@ class ServiceDelegate(ServiceBase) :
def perform_lookup(self,host_tuple) :
return_dict = {}
if len(host_tuple[2]) > 0 :
return_dict['IP Addresses'] = list(host_tuple[2])
return_dict['ipaddresses'] = list(host_tuple[2])
if host_tuple[0] and host_tuple[0] != '' :
return_dict['Hostname'] = host_tuple[0]
return_dict['hostname'] = host_tuple[0]
if len(host_tuple[1]) > 0 :
return_dict['Associated Aliases'] = list(host_tuple[1])
return_dict['aliases'] = list(host_tuple[1])
return return_dict

View File

@ -29,7 +29,7 @@ class ServiceDelegate(ServiceBase) :
logincandidates = self.choose_host(host_tuple)
if logincandidates == {} :
# Idk what to do here, do we give up or do we log in to all of them?
self.error.append('Unable to find an LB to log into to check this host')
self.error.append('Unable to find an LB to log into to check host ' + str(host_tuple))
return self.return_payload
for host in logincandidates.keys() :
@ -134,7 +134,10 @@ class ServiceDelegate(ServiceBase) :
return hosts
# No hostname match, maybe we have info from bluecat?
if 'bluecat' in self.data and host_tuple in self.data['bluecat'] and self.data['bluecat'][host_tuple]['object'] :
potentialdc = self.data['bluecat'][host_tuple]['object']['locationCode'].split(' ')[-1]
if 'locationCode' in self.data['bluecat'][host_tuple]['object'] :
potentialdc = self.data['bluecat'][host_tuple]['object']['locationCode'].split(' ')[-1]
elif 'parent' in self.data['bluecat'][host_tuple] and 'name' in self.data['bluecat'][host_tuple]['parent'] :
potentialdc = self.data['bluecat'][host_tuple]['parent']['name'].split(' ')[0]
for host in self.hosts.keys() :
if potentialdc.lower() in host.lower() :
hosts.update({host:self.hosts[host]})

View File

@ -13,6 +13,10 @@ class ServiceBase :
self._status = "Error"
else :
self.config = config
# The following lines indicate a problem in my understanding of Python's class structure.
# Why do new instances of subclasses inherit the written values of their superclass instance?
self.error = []
self.warn = []
self.data = dossiercopy
self.namespace = namespace
self._subjects = subjects