def remove_public_key(username, filename): from scanner.api import ssh_key host = 'vinz-ubuntu-12-04.student.iastate.edu' with open(filename) as f: result = ssh_key.remove_user_public_key(username, [host], f.read()) if result[host]['success']: print 'Successfully added key for user %s to host %s' % (username, host) else: print 'FAIL: %s' % (result[host]['error'])
def remove_user(username, hosts): """ :param username: The username of the user to be removed from the remote machines :param hosts: A list of servers to remove the user from """ if username == 'root': return if not isinstance(username, basestring): raise ValueError("Username must be a string") user = internal_user.get_user_by_username(username) if not user: return for key in list(user.key_list): ssh_key.remove_user_public_key(username, hosts, key.value)