Added Get User List methods to win_client and linux_client

* Added get_user_list method to windows_client which uses the winrm
  remote client to run a powershell command to get user objects,
  parse them into dictionaries and make a list of the usernames
  on the target instance
* Added get_user_list method to linux_client which reads the
  /etc/passwd file on the target instance and returns a list of
  the usernames.

Change-Id: Ifeb408929d598fdff82a7f4f8c0f0912ff8fd1f4
This commit is contained in:
Anna Eilering
2014-07-29 07:55:54 -05:00
parent 9794ef2393
commit f608b5503e
2 changed files with 33 additions and 0 deletions

View File

@@ -149,6 +149,19 @@ class LinuxClient(RemoteInstanceClient):
uptime = float(result.stdout.split(' ')[0])
return uptime
def get_local_users(self):
"""
Get a list of the local user accounts on the server
@return: A list of users
@rtype: List of strings
"""
command = 'cat /etc/passwd | cut -d: -f1'
output = self.ssh_client.execute_command(command)
if output:
return output.stdout.split()
def create_file(self, file_name, file_content, file_path=None):
"""
Creates a new file with the provided content.

View File

@@ -146,6 +146,26 @@ class WindowsClient(RemoteInstanceClient):
diff = now - last_boot
return diff.total_seconds()
def get_local_users(self):
"""
Get a list of the local user accounts on the server
@return: A list of users
@rtype: List of strings
"""
command = ('powershell gwmi Win32_UserAccount')
output = self.client.execute_command(command)
if not output:
return None
raw_output = output.std_out.split('\r\n\r\n')
raw_users = [user for user in raw_output if user]
user_list = []
for user in raw_users:
user_info = self._convert_powershell_list_to_dict(user)
user_list.append(user_info.get('Name'))
return user_list
def create_file(self, file_name, file_content, file_path):
"""
Creates a new file with the provided content.