def reset_password(username=None, password=None): """ Resets specified user password on all hosts :param username: Username :param password: Password """ status = True ssh_user = hosts.get_ssh_user() ssh_key = hosts.get_ssh_key() all_hosts = list(hosts.get_hosts()) env.user = ssh_user env.hosts = all_hosts env.disable_known_hosts = True # create temporary key file for fabric tmp_key = tempfile.mktemp() with open(tmp_key, "w") as f: f.write(ssh_key) os.chmod(tmp_key, 0600) env.key_filename = tmp_key result = {} try: for host in all_hosts: env.host_string = host with hide("running", "stdout", "stderr"): sudo("echo -e '{0}\n{0}' | (sudo passwd -q {1})".format(password, username)) result[host] = "success" except Exception, e: result[host] = str(e) status = False
def reset_password(username=None, password=None): """ Resets specified user password on all hosts :param username: Username :param password: Password """ status = True ssh_user = hosts.get_ssh_user() ssh_key = hosts.get_ssh_key() all_hosts = list(hosts.get_hosts()) env.user = ssh_user env.hosts = all_hosts env.disable_known_hosts = True # create temporary key file for fabric tmp_key = tempfile.mktemp() with open(tmp_key, 'w') as f: f.write(ssh_key) os.chmod(tmp_key, 0600) env.key_filename = tmp_key result = {} try: for host in all_hosts: env.host_string = host with hide('running', 'stdout', 'stderr'): sudo("echo -e '{0}\n{0}' | (sudo passwd -q {1})".format( password, username)) result[host] = 'success' except Exception, e: result[host] = str(e) status = False
def test_set_ssh_key(self): self.assertTrue(hosts.set_ssh_key(self.test_ssh_key)) self.assertEqual(hosts.get_ssh_key(), self.test_ssh_key)