Skip to content

Instantly share code, notes, and snippets.

View glarizza's full-sized avatar

Gary Larizza glarizza

  • Open Infrastructure Services
  • Portland, Oregon
View GitHub Profile
from SystemConfiguration import *
import syslog
def checkIP(self, interface):
"""This function accepts a BSD interface name and returns the system IP Address
for that interface using the SystemConfiguration Framework.
---
Arguments:
interface - Either en0 or en1, the BSD interface name of a Network Adapter.
Returns:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSWorkspace</key>
<dict>
<key>NSWorkspaceDidMountNotification</key>
<dict>
<key>command</key>
<string>/bin/echo "A new volume was mounted!"</string>
<key>State:/Network/Global/IPv4</key>
<dict>
<key>method</key>
<array>
<string>CrankTools</string>
<string>OnNetworkLoad</string>
</array>
</dict>
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
"""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.huronhs.crankd.plist</string>
<key>ProgramArguments</key>
<array>
#!/usr/bin/python2.5
#
# CrankTools.py
# The OnNetworkLoad method is called from crankd on a network state change, all other
# methods assist it. In the future, I will add other "On..." methods to respond
# to other state changes.
#
# Last Revised - 10/12/2010
__author__ = 'Gary Larizza (gary@huronhs.com)'
# /etc/puppet/manifests/classes/crankd.pp
class crankd {
# Global File defaults
File { owner => "root", group => "wheel", }
# Ensure the required directories
file { "/Library/HuronHS":
ensure => directory,
>>> store = SCDynamicStoreCreate(None, "global-network", None , None) >>> print store
<SCDynamicStore 0x104400f80 [0x7fff70174f20]> {server port = 0x369f, notification delivery not requested (yet)}
>>> print SCDynamicStoreCopyValue(store, None)
None
>>> print SCDynamicStoreCopyValue(store, "State:/Network/Global/IPv4")
{
PrimaryInterface = en0;
PrimaryService = "961CAB70-82E4-4781-8343-622FC8C81BB2";
Router = "10.13.0.1";
}
#!/usr/bin/env python
from SystemConfiguration import *
import syslog
interface = "en0"
store = SCDynamicStoreCreate(None, "global-network", None , None)
ifKey = "State:/Network/Interface/" + interface + "/IPv4"
keyStore = SCDynamicStoreCopyValue(store, ifKey)
def DSQueryLDAPv3(dstype, node, objectname, attribute=None):
"""LDAPv3 DirectoryServices query.
Args:
dstype: The type of objects to query. user, group.
node: The node to query.
objectname: the object to query.
attribute: the optional attribute to query.
Returns:
If an attribute is specified, the value of the attribute. Otherwise, the