1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """Module implementing configuration details at runtime.
21
22 """
23
24
25 import grp
26 import pwd
27 import threading
28
29 from ganeti import constants
30 from ganeti import errors
31
32
33 _priv = None
34 _priv_lock = threading.Lock()
35
36
38 """Retrieve the uid from the database.
39
40 @type user: string
41 @param user: The username to retrieve
42 @return: The resolved uid
43
44 """
45 try:
46 return _getpwnam(user).pw_uid
47 except KeyError, err:
48 raise errors.ConfigurationError("User '%s' not found (%s)" % (user, err))
49
50
52 """Retrieve the gid from the database.
53
54 @type group: string
55 @param group: The group name to retrieve
56 @return: The resolved gid
57
58 """
59 try:
60 return _getgrnam(group).gr_gid
61 except KeyError, err:
62 raise errors.ConfigurationError("Group '%s' not found (%s)" % (group, err))
63
64
66 """Resolves Ganeti uids and gids by name.
67
68 @ivar masterd_uid: The resolved uid of the masterd user
69 @ivar masterd_gid: The resolved gid of the masterd group
70 @ivar confd_uid: The resolved uid of the confd user
71 @ivar confd_gid: The resolved gid of the confd group
72 @ivar rapi_uid: The resolved uid of the rapi user
73 @ivar rapi_gid: The resolved gid of the rapi group
74 @ivar noded_uid: The resolved uid of the noded user
75
76 @ivar daemons_gid: The resolved gid of the daemons group
77 @ivar admin_gid: The resolved gid of the admin group
78 """
79 - def __init__(self, _getpwnam=pwd.getpwnam, _getgrnam=grp.getgrnam):
98
99
101 """Singleton wrapper around resolver instance.
102
103 As this method is accessed by multiple threads at the same time
104 we need to take thread-safty carefully
105
106 """
107
108 global _priv
109
110 if not _priv:
111 _priv_lock.acquire()
112 try:
113 if not _priv:
114
115 _priv = resolver()
116 finally:
117 _priv_lock.release()
118
119 return _priv
120