Revision 44fbd23b lib/runtime.py
b/lib/runtime.py | ||
---|---|---|
28 | 28 |
|
29 | 29 |
from ganeti import constants |
30 | 30 |
from ganeti import errors |
31 |
from ganeti import utils |
|
31 | 32 |
|
32 | 33 |
|
33 | 34 |
_priv = None |
... | ... | |
91 | 92 |
self.rapi_gid = GetGid(constants.RAPI_GROUP, _getgrnam) |
92 | 93 |
|
93 | 94 |
self.noded_uid = GetUid(constants.NODED_USER, _getpwnam) |
95 |
self.noded_gid = GetGid(constants.NODED_GROUP, _getgrnam) |
|
94 | 96 |
|
95 | 97 |
# Misc Ganeti groups |
96 | 98 |
self.daemons_gid = GetGid(constants.DAEMONS_GROUP, _getgrnam) |
97 | 99 |
self.admin_gid = GetGid(constants.ADMIN_GROUP, _getgrnam) |
98 | 100 |
|
101 |
self._uid2user = { |
|
102 |
self.masterd_uid: constants.MASTERD_USER, |
|
103 |
self.confd_uid: constants.CONFD_USER, |
|
104 |
self.rapi_uid: constants.RAPI_USER, |
|
105 |
self.noded_uid: constants.NODED_USER, |
|
106 |
} |
|
107 |
|
|
108 |
self._gid2group = { |
|
109 |
self.masterd_gid: constants.MASTERD_GROUP, |
|
110 |
self.confd_gid: constants.CONFD_GROUP, |
|
111 |
self.rapi_gid: constants.RAPI_GROUP, |
|
112 |
self.noded_gid: constants.NODED_GROUP, |
|
113 |
self.daemons_gid: constants.DAEMONS_GROUP, |
|
114 |
self.admin_gid: constants.ADMIN_GROUP, |
|
115 |
} |
|
116 |
|
|
117 |
self._user2uid = utils.InvertDict(self._uid2user) |
|
118 |
self._group2gid = utils.InvertDict(self._gid2group) |
|
119 |
|
|
120 |
def LookupUid(self, uid): |
|
121 |
"""Looks which Ganeti user belongs to this uid. |
|
122 |
|
|
123 |
@param uid: The uid to lookup |
|
124 |
@returns The user name associated with that uid |
|
125 |
|
|
126 |
""" |
|
127 |
try: |
|
128 |
return self._uid2user[uid] |
|
129 |
except KeyError: |
|
130 |
raise errors.ConfigurationError("Unknown Ganeti uid '%d'" % uid) |
|
131 |
|
|
132 |
def LookupGid(self, gid): |
|
133 |
"""Looks which Ganeti group belongs to this gid. |
|
134 |
|
|
135 |
@param gid: The gid to lookup |
|
136 |
@returns The group name associated with that gid |
|
137 |
|
|
138 |
""" |
|
139 |
try: |
|
140 |
return self._gid2group[gid] |
|
141 |
except KeyError: |
|
142 |
raise errors.ConfigurationError("Unknown Ganeti gid '%d'" % gid) |
|
143 |
|
|
144 |
def LookupUser(self, name): |
|
145 |
"""Looks which uid belongs to this name. |
|
146 |
|
|
147 |
@param name: The name to lookup |
|
148 |
@returns The uid associated with that user name |
|
149 |
|
|
150 |
""" |
|
151 |
try: |
|
152 |
return self._user2uid[name] |
|
153 |
except KeyError: |
|
154 |
raise errors.ConfigurationError("Unknown Ganeti user '%s'" % name) |
|
155 |
|
|
156 |
def LookupGroup(self, name): |
|
157 |
"""Looks which gid belongs to this name. |
|
158 |
|
|
159 |
@param name: The name to lookup |
|
160 |
@returns The gid associated with that group name |
|
161 |
|
|
162 |
""" |
|
163 |
try: |
|
164 |
return self._group2gid[name] |
|
165 |
except KeyError: |
|
166 |
raise errors.ConfigurationError("Unknown Ganeti group '%s'" % name) |
|
167 |
|
|
99 | 168 |
|
100 | 169 |
def GetEnts(resolver=GetentResolver): |
101 | 170 |
"""Singleton wrapper around resolver instance. |
Also available in: Unified diff