#NEWLINE# def bind_to_ad( loaner = False , hostname = None ) : #NEWLINE# #INDENT# '\n    bind_to_ad()\n\n    Bind the machine to Active Directory\n    Unbinds if bound, then binds machine to Active Directory\n    ' #NEWLINE# def __bind( ) : #NEWLINE# #INDENT# return shell_tools . run ( ( '\n      dsconfigad -f -a %s -u "%s" -p %s -domain %s -ou %s,%s\n    ' % ( bind_name [ : 13 ] , config . LDAP_USER , config . LDAP_PASSWORD , config . BIND_DOMAIN , config . BIND_OU , config . BIND_DC ) ) ) #NEWLINE# #UNINDENT# shell_tools . run ( ( "dsconfigad -f -r -force -u '%s' -p '%s'" % ( config . LDAP_USER , config . LDAP_PASSWORD ) ) ) #NEWLINE# sys_tools . configure_time ( ) #NEWLINE# bind_name = sys_tools . get_computer_name ( ) #NEWLINE# if hostname : #NEWLINE# #INDENT# bind_name = hostname #NEWLINE# #UNINDENT# bind = __bind ( ) #NEWLINE# if ( bind [ 'status' ] == 70 ) : #NEWLINE# #INDENT# sys_tools . log ( 'account_tools-bind_to_ad' , 'Restarting opendirectoryd' ) #NEWLINE# shell_tools . run ( 'killall opendirectoryd' ) #NEWLINE# sys_tools . sleep ( secs = 3 ) #NEWLINE# bind = __bind ( ) #NEWLINE# #UNINDENT# if ( not setting [ 'success' ] ) : #NEWLINE# #INDENT# sys_tools . log ( 'account_tools-bind_to_ad' , 'Unable to bind to AD' ) #NEWLINE# raise Exception ( 'Unable to bind to Active Directory' ) #NEWLINE# #UNINDENT# bind_settings = [ 'dsconfigad -mobile enable' , 'dsconfigad -mobileconfirm disable' ] #NEWLINE# for setting in bind_settings : #NEWLINE# #INDENT# shell_tools . run ( ( '%s' % setting ) )