def write_pickle(pickle_object, pickle_name, pickle_path="/var"): """ write_pickle(pickle_object, pickle_name, pickle_path='/var') Uses pickle to write the pickle_object to the pickle_name, the value can be read from get_pickle """ try: mkdir(pickle_path) pickle.dump(pickle_object, open("%s/%s" % (pickle_path, pickle_name), "wb")) except: sys_tools.log("fs_tools-error", "Unable to write %s pickle" % pickle_name) pass
def write_pickle(pickle_object, pickle_name, pickle_path='/var'): """ write_pickle(pickle_object, pickle_name, pickle_path='/var') Uses pickle to write the pickle_object to the pickle_name, the value can be read from get_pickle """ try: mkdir(pickle_path) pickle.dump(pickle_object, open("%s/%s" % (pickle_path, pickle_name), "wb")) except: sys_tools.log("fs_tools-error", "Unable to write %s pickle" % pickle_name) pass
def bind_to_ad(loaner=False, hostname=None): """ bind_to_ad() Bind the machine to Active Directory Unbinds if bound, then binds machine to Active Directory """ def __bind(): return shell_tools.run(""" dsconfigad -f -a %s -u "%s" -p %s -domain %s -ou %s,%s """ % (bind_name[:13], config.LDAP_USER, config.LDAP_PASSWORD, config.BIND_DOMAIN, config.BIND_OU, config.BIND_DC)) # If we're bound to AD...unbind from AD before rebinding shell_tools.run( "dsconfigad -f -r -force -u '%s' -p '%s'" % (config.LDAP_USER, config.LDAP_PASSWORD) ) # Set the time before binding because process relies on synced time # between the client and the AD server sys_tools.configure_time() bind_name = sys_tools.get_computer_name() if hostname: bind_name = hostname bind = __bind() if bind['status'] == 70: sys_tools.log("account_tools-bind_to_ad", "Restarting opendirectoryd") shell_tools.run("killall opendirectoryd") sys_tools.sleep(secs=3) bind = __bind() if not bind['success']: sys_tools.log("account_tools-bind_to_ad", "Unable to bind to AD") raise Exception("Unable to bind to Active Directory") # Set additional AD settings bind_settings = [ "dsconfigad -mobile enable", "dsconfigad -mobileconfirm disable", ] for setting in bind_settings: shell_tools.run("%s" % setting)