Revision 4331f6cd
b/daemons/ganeti-masterd | ||
---|---|---|
428 | 428 |
utils.debug = options.debug |
429 | 429 |
utils.no_fork = True |
430 | 430 |
|
431 |
ssconf.CheckMaster(options.debug) |
|
431 |
rpc.Init() |
|
432 |
try: |
|
433 |
ssconf.CheckMaster(options.debug) |
|
432 | 434 |
|
433 |
# we believe we are the master, let's ask the other nodes... |
|
434 |
if not CheckAgreement(): |
|
435 |
return |
|
435 |
# we believe we are the master, let's ask the other nodes...
|
|
436 |
if not CheckAgreement():
|
|
437 |
return
|
|
436 | 438 |
|
437 |
master = IOServer(constants.MASTER_SOCKET, ClientRqHandler) |
|
439 |
master = IOServer(constants.MASTER_SOCKET, ClientRqHandler) |
|
440 |
finally: |
|
441 |
rpc.Shutdown() |
|
438 | 442 |
|
439 | 443 |
# become a daemon |
440 | 444 |
if options.fork: |
... | ... | |
446 | 450 |
utils.SetupLogging(constants.LOG_MASTERDAEMON, debug=options.debug, |
447 | 451 |
stderr_logging=not options.fork) |
448 | 452 |
|
449 |
logging.info("ganeti master daemon startup") |
|
453 |
rpc.Init() |
|
454 |
try: |
|
455 |
logging.info("ganeti master daemon startup") |
|
450 | 456 |
|
451 |
# activate ip |
|
452 |
master_node = ssconf.SimpleConfigReader().GetMasterNode() |
|
453 |
if not rpc.RpcRunner.call_node_start_master(master_node, False): |
|
454 |
logging.error("Can't activate master IP address") |
|
457 |
# activate ip
|
|
458 |
master_node = ssconf.SimpleConfigReader().GetMasterNode()
|
|
459 |
if not rpc.RpcRunner.call_node_start_master(master_node, False):
|
|
460 |
logging.error("Can't activate master IP address")
|
|
455 | 461 |
|
456 |
master.setup_queue() |
|
457 |
try: |
|
458 |
master.serve_forever() |
|
462 |
master.setup_queue() |
|
463 |
try: |
|
464 |
master.serve_forever() |
|
465 |
finally: |
|
466 |
master.server_cleanup() |
|
467 |
utils.RemovePidFile(constants.MASTERD_PID) |
|
459 | 468 |
finally: |
460 |
master.server_cleanup() |
|
461 |
utils.RemovePidFile(constants.MASTERD_PID) |
|
469 |
rpc.Shutdown() |
|
462 | 470 |
|
463 | 471 |
|
464 | 472 |
if __name__ == "__main__": |
b/lib/cli.py | ||
---|---|---|
36 | 36 |
from ganeti import opcodes |
37 | 37 |
from ganeti import luxi |
38 | 38 |
from ganeti import ssconf |
39 |
from ganeti import rpc |
|
39 | 40 |
|
40 | 41 |
from optparse import (OptionParser, make_option, TitledHelpFormatter, |
41 | 42 |
Option, OptionValueError) |
... | ... | |
51 | 52 |
"JobSubmittedException", "FormatTimestamp", "ParseTimespec", |
52 | 53 |
"ValidateBeParams", |
53 | 54 |
"ToStderr", "ToStdout", |
55 |
"UsesRPC", |
|
54 | 56 |
] |
55 | 57 |
|
56 | 58 |
|
... | ... | |
424 | 426 |
raise errors.ParameterError("Invalid number of VCPUs") |
425 | 427 |
|
426 | 428 |
|
429 |
def UsesRPC(fn): |
|
430 |
def wrapper(*args, **kwargs): |
|
431 |
rpc.Init() |
|
432 |
try: |
|
433 |
return fn(*args, **kwargs) |
|
434 |
finally: |
|
435 |
rpc.Shutdown() |
|
436 |
return wrapper |
|
437 |
|
|
438 |
|
|
427 | 439 |
def AskUser(text, choices=None): |
428 | 440 |
"""Ask the user a question. |
429 | 441 |
|
b/lib/rpc.py | ||
---|---|---|
41 | 41 |
from ganeti import serializer |
42 | 42 |
|
43 | 43 |
|
44 |
# Module level variable |
|
45 |
_http_manager = None |
|
46 |
|
|
47 |
|
|
48 |
def Init(): |
|
49 |
"""Initializes the module-global HTTP client manager. |
|
50 |
|
|
51 |
Must be called before using any RPC function. |
|
52 |
|
|
53 |
""" |
|
54 |
global _http_manager |
|
55 |
|
|
56 |
assert not _http_manager, "RPC module initialized more than once" |
|
57 |
|
|
58 |
_http_manager = http.HttpClientManager() |
|
59 |
|
|
60 |
|
|
61 |
def Shutdown(): |
|
62 |
"""Stops the module-global HTTP client manager. |
|
63 |
|
|
64 |
Must be called before quitting the program. |
|
65 |
|
|
66 |
""" |
|
67 |
global _http_manager |
|
68 |
|
|
69 |
if _http_manager: |
|
70 |
_http_manager.Shutdown() |
|
71 |
_http_manager = None |
|
72 |
|
|
73 |
|
|
44 | 74 |
class Client: |
45 | 75 |
"""RPC Client class. |
46 | 76 |
|
... | ... | |
103 | 133 |
@returns: List of RPC results |
104 | 134 |
|
105 | 135 |
""" |
106 |
# TODO: Shared and reused manager |
|
107 |
mgr = http.HttpClientManager() |
|
108 |
try: |
|
109 |
mgr.ExecRequests(self.nc.values()) |
|
110 |
finally: |
|
111 |
mgr.Shutdown() |
|
136 |
assert _http_manager, "RPC module not intialized" |
|
137 |
|
|
138 |
_http_manager.ExecRequests(self.nc.values()) |
|
112 | 139 |
|
113 | 140 |
results = {} |
114 | 141 |
|
b/scripts/gnt-cluster | ||
---|---|---|
36 | 36 |
from ganeti import ssh |
37 | 37 |
|
38 | 38 |
|
39 |
@UsesRPC |
|
39 | 40 |
def InitCluster(opts, args): |
40 | 41 |
"""Initialize the cluster. |
41 | 42 |
|
... | ... | |
125 | 126 |
return 0 |
126 | 127 |
|
127 | 128 |
|
129 |
@UsesRPC |
|
128 | 130 |
def DestroyCluster(opts, args): |
129 | 131 |
"""Destroy the cluster. |
130 | 132 |
|
... | ... | |
396 | 398 |
return retcode |
397 | 399 |
|
398 | 400 |
|
401 |
@UsesRPC |
|
399 | 402 |
def MasterFailover(opts, args): |
400 | 403 |
"""Failover the master node. |
401 | 404 |
|
b/scripts/gnt-node | ||
---|---|---|
42 | 42 |
] |
43 | 43 |
|
44 | 44 |
|
45 |
@UsesRPC |
|
45 | 46 |
def AddNode(opts, args): |
46 | 47 |
"""Add a node to the cluster. |
47 | 48 |
|
Also available in: Unified diff