Revision b33e986b
b/lib/cli.py | ||
---|---|---|
35 | 35 |
from ganeti import constants |
36 | 36 |
from ganeti import opcodes |
37 | 37 |
from ganeti import luxi |
38 |
from ganeti import ssconf |
|
38 | 39 |
|
39 | 40 |
from optparse import (OptionParser, make_option, TitledHelpFormatter, |
40 | 41 |
Option, OptionValueError) |
... | ... | |
377 | 378 |
|
378 | 379 |
""" |
379 | 380 |
if cl is None: |
380 |
cl = luxi.Client()
|
|
381 |
cl = GetClient()
|
|
381 | 382 |
|
382 | 383 |
job_id = cl.SubmitJob([op]) |
383 | 384 |
|
... | ... | |
414 | 415 |
|
415 | 416 |
def GetClient(): |
416 | 417 |
# TODO: Cache object? |
417 |
return luxi.Client() |
|
418 |
try: |
|
419 |
client = luxi.Client() |
|
420 |
except luxi.NoMasterError: |
|
421 |
master, myself = ssconf.GetMasterAndMyself() |
|
422 |
if master != myself: |
|
423 |
raise errors.OpPrereqError("This is not the master node, please connect" |
|
424 |
" to node '%s' and rerun the command" % |
|
425 |
master) |
|
426 |
else: |
|
427 |
raise |
|
428 |
return client |
|
418 | 429 |
|
419 | 430 |
|
420 | 431 |
def FormatError(err): |
b/lib/ssconf.py | ||
---|---|---|
201 | 201 |
uid=0, gid=0, mode=0400) |
202 | 202 |
|
203 | 203 |
|
204 |
def CheckMaster(debug): |
|
204 |
def GetMasterAndMyself(ss=None): |
|
205 |
"""Get the master node and my own hostname. |
|
206 |
|
|
207 |
This can be either used for a 'soft' check (compared to CheckMaster, |
|
208 |
which exits) or just for computing both at the same time. |
|
209 |
|
|
210 |
The function does not handle any errors, these should be handled in |
|
211 |
the caller (errors.ConfigurationError, errors.ResolverError). |
|
212 |
|
|
213 |
""" |
|
214 |
if ss is None: |
|
215 |
ss = SimpleStore() |
|
216 |
return ss.GetMasterNode(), utils.HostInfo().name |
|
217 |
|
|
218 |
def CheckMaster(debug, ss=None): |
|
205 | 219 |
"""Checks the node setup. |
206 | 220 |
|
207 | 221 |
If this is the master, the function will return. Otherwise it will |
... | ... | |
209 | 223 |
|
210 | 224 |
""" |
211 | 225 |
try: |
212 |
ss = SimpleStore() |
|
213 |
master_name = ss.GetMasterNode() |
|
226 |
master_name, myself = GetMasterAndMyself(ss) |
|
214 | 227 |
except errors.ConfigurationError, err: |
215 | 228 |
print "Cluster configuration incomplete: '%s'" % str(err) |
216 | 229 |
sys.exit(constants.EXIT_NODESETUP_ERROR) |
217 |
|
|
218 |
try: |
|
219 |
myself = utils.HostInfo() |
|
220 | 230 |
except errors.ResolverError, err: |
221 | 231 |
sys.stderr.write("Cannot resolve my own name (%s)\n" % err.args[0]) |
222 | 232 |
sys.exit(constants.EXIT_NODESETUP_ERROR) |
223 | 233 |
|
224 |
if myself.name != master_name:
|
|
234 |
if myself != master_name: |
|
225 | 235 |
if debug: |
226 | 236 |
sys.stderr.write("Not master, exiting.\n") |
227 | 237 |
sys.exit(constants.EXIT_NOTMASTER) |
Also available in: Unified diff