Created
October 13, 2010 14:47
-
-
Save glarizza/624170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def checkOD(self): | |
"""Checks for an active network connection and then compares the IP address | |
to see if it matches the scheme we use in Huron. If the IP matches, we ensure | |
that the search path and contacts path are correct. If the IP DOESN'T match, | |
we remove the search path and contacts path to stabilize logins. | |
--- | |
Arguments: None | |
Returns: | |
bool - True or False if an interface is active and has an IP Address on the Huron Network | |
""" | |
# Capture all bound LDAPv3 Servers | |
nodes = pymacds.ConfiguredNodesLDAPv3() | |
if not nodes: | |
syslog.syslog(syslog.LOG_ALERT, "We're not bound, skipping all checks.") | |
return 'false' | |
# Check all IP Addresses of Network Interfaces to see if we're on the Huron Network | |
airportIP = self.checkIP('en1') | |
ethernetIP = self.checkIP('en0') | |
# If either connection is active and on the Huron Network, make sure the Search/Contacts paths | |
# are set properly. | |
if airportIP == 'true' or ethernetIP == 'true': | |
syslog.syslog(syslog.LOG_ALERT, "Ensuring Bindings.") | |
for node in nodes: | |
pymacds.EnsureSearchNodePresent(node) | |
pymacds.EnsureContactsNodePresent(node) | |
return 'true' | |
# If we're bound and off the Huron Network, remove the Search/Contacts paths | |
if airportIP == 'false' and ethernetIP == 'false': | |
syslog.syslog(syslog.LOG_ALERT, "Removing Bindings.") | |
for node in nodes: | |
pymacds.EnsureSearchNodeAbsent(node) | |
pymacds.EnsureContactsNodeAbsent(node) | |
return 'false' | |
else: | |
syslog.syslog(syslog.LOG_ALERT, "Weird case where neither if statement in checkOD was true...") | |
return 'false' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment