Skip to content

Instantly share code, notes, and snippets.

@glarizza
Created January 7, 2011 22:01
Show Gist options
  • Save glarizza/770193 to your computer and use it in GitHub Desktop.
Save glarizza/770193 to your computer and use it in GitHub Desktop.
def searchContactNodes(self, nodeToFind):
"""A utility function to search through Contact nodes looking for a specific node
---
Arguments:
nodeToFind - The node you're looking to find.
Returns: Nothing
"""
for node in pymacds.GetLDAPv3ContactsNodes():
if node == nodeToFind:
return "true"
return ""
def searchSearchNodes(self, nodeToFind):
"""A utility function to search through Contact nodes looking for a specific node
---
Arguments:
nodeToFind - The node you're looking to find.
Returns: Nothing
"""
for node in pymacds.GetLDAPv3SearchNodes():
if node == nodeToFind:
return "true"
return ""
def ensureLDAPNodes(self, nodes):
"""A utility function to ensure our LDAP Search and Contact Nodes. Checks to
make sure nodes aren't already listed before it adds them.
---
Arguments:
nodes - a list of nodes to ensure.
Returns: Nothing
"""
for node in nodes:
if not self.searchSearchNodes(node):
pymacds.EnsureSearchNodePresent(node)
syslog.syslog(syslog.LOG_ALERT, "Added " + node + " to the Search path."
if not self.searchContactNodes(node):
pymacds.EnsureContactsNodePresent(node)
syslog.syslog(syslog.LOG_ALERT, "Added " + node + " to the Contacts path."
def removeLDAPNodes(self, nodeToRemove):
"""A utility function to remove specific LDAP Search and Contact Nodes. Checks to
make sure nodes aren't already listed before it adds them.
---
Arguments:
nodes - a list of nodes to remove.
Returns: Nothing
"""
for node in nodes:
if self.searchSearchNodes(node):
pymacds.EnsureSearchNodeAbsent(node)
syslog.syslog(syslog.LOG_ALERT, "Removed " + node + " from the Search path."
if self.searchContactNodes(node):
pymacds.EnsureContactsNodeAbsent(node)
syslog.syslog(syslog.LOG_ALERT, "Removed " + node + " from the Contacts path."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment