Commit 2f8b60b3 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add small function to read the homedir of a user

This can be used to replace hardcoded "/root/" paths.

Reviewed-by: imsnah
parent 16abfbc2
......@@ -33,6 +33,7 @@ import socket
import tempfile
import shutil
import errno
import pwd
from ganeti import logger
from ganeti import errors
......@@ -822,3 +823,14 @@ def ListVisibleFiles(path):
"""
return [i for i in os.listdir(path) if not i.startswith(".")]
def GetHomeDir(uid, default=None):
"""Try to get the homedir of the given user id.
"""
try:
result = pwd.getpwuid(uid)
except KeyError:
return default
return result.pw_dir
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment