Revision a51b19de lib/runtime.py
b/lib/runtime.py | ||
---|---|---|
26 | 26 |
import grp |
27 | 27 |
import pwd |
28 | 28 |
import threading |
29 |
import os |
|
29 | 30 |
import platform |
30 | 31 |
|
31 | 32 |
from ganeti import constants |
32 | 33 |
from ganeti import errors |
34 |
from ganeti import luxi |
|
35 |
from ganeti import pathutils |
|
36 |
from ganeti import ssconf |
|
33 | 37 |
from ganeti import utils |
34 | 38 |
|
35 | 39 |
|
... | ... | |
235 | 239 |
" initialized") |
236 | 240 |
|
237 | 241 |
return _arch |
242 |
|
|
243 |
|
|
244 |
def GetClient(query=False): |
|
245 |
"""Connects to the a luxi socket and returns a client. |
|
246 |
|
|
247 |
@type query: boolean |
|
248 |
@param query: this signifies that the client will only be |
|
249 |
used for queries; if the build-time parameter |
|
250 |
enable-split-queries is enabled, then the client will be |
|
251 |
connected to the query socket instead of the masterd socket |
|
252 |
|
|
253 |
""" |
|
254 |
override_socket = os.getenv(constants.LUXI_OVERRIDE, "") |
|
255 |
if override_socket: |
|
256 |
if override_socket == constants.LUXI_OVERRIDE_MASTER: |
|
257 |
address = pathutils.MASTER_SOCKET |
|
258 |
elif override_socket == constants.LUXI_OVERRIDE_QUERY: |
|
259 |
address = pathutils.QUERY_SOCKET |
|
260 |
else: |
|
261 |
address = override_socket |
|
262 |
elif query: |
|
263 |
address = pathutils.QUERY_SOCKET |
|
264 |
else: |
|
265 |
address = None |
|
266 |
# TODO: Cache object? |
|
267 |
try: |
|
268 |
client = luxi.Client(address=address) |
|
269 |
except luxi.NoMasterError: |
|
270 |
ss = ssconf.SimpleStore() |
|
271 |
|
|
272 |
# Try to read ssconf file |
|
273 |
try: |
|
274 |
ss.GetMasterNode() |
|
275 |
except errors.ConfigurationError: |
|
276 |
raise errors.OpPrereqError("Cluster not initialized or this machine is" |
|
277 |
" not part of a cluster", |
|
278 |
errors.ECODE_INVAL) |
|
279 |
|
|
280 |
master, myself = ssconf.GetMasterAndMyself(ss=ss) |
|
281 |
if master != myself: |
|
282 |
raise errors.OpPrereqError("This is not the master node, please connect" |
|
283 |
" to node '%s' and rerun the command" % |
|
284 |
master, errors.ECODE_INVAL) |
|
285 |
raise |
|
286 |
return client |
Also available in: Unified diff