Revision b1b6ea87 lib/backend.py
b/lib/backend.py | ||
---|---|---|
47 | 47 |
return ssh.SshRunner() |
48 | 48 |
|
49 | 49 |
|
50 |
def _GetMasterInfo(): |
|
51 |
"""Return the master ip and netdev. |
|
52 |
|
|
53 |
""" |
|
54 |
try: |
|
55 |
ss = ssconf.SimpleStore() |
|
56 |
master_netdev = ss.GetMasterNetdev() |
|
57 |
master_ip = ss.GetMasterIP() |
|
58 |
except errors.ConfigurationError, err: |
|
59 |
logging.exception("Cluster configuration incomplete") |
|
60 |
return (None, None) |
|
61 |
return (master_netdev, master_ip) |
|
62 |
|
|
63 |
|
|
50 | 64 |
def StartMaster(start_daemons): |
51 | 65 |
"""Activate local node as master node. |
52 | 66 |
|
... | ... | |
56 | 70 |
(ganet-masterd and ganeti-rapi). |
57 | 71 |
|
58 | 72 |
""" |
59 |
result = utils.RunCmd([constants.MASTER_SCRIPT, "-d", "start"]) |
|
60 |
|
|
61 |
if result.failed: |
|
62 |
logging.error("could not activate cluster interface with command %s," |
|
63 |
" error: '%s'", result.cmd, result.output) |
|
73 |
ok = True |
|
74 |
master_netdev, master_ip = _GetMasterInfo() |
|
75 |
if not master_netdev: |
|
64 | 76 |
return False |
65 | 77 |
|
66 |
return True |
|
78 |
if utils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT): |
|
79 |
if utils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT, |
|
80 |
source=constants.LOCALHOST_IP_ADDRESS): |
|
81 |
# we already have the ip: |
|
82 |
logging.debug("Already started") |
|
83 |
else: |
|
84 |
logging.error("Someone else has the master ip, not activating") |
|
85 |
ok = False |
|
86 |
else: |
|
87 |
result = utils.RunCmd(["ip", "address", "add", "%s/32" % master_ip, |
|
88 |
"dev", master_netdev, "label", |
|
89 |
"%s:0" % master_netdev]) |
|
90 |
if result.failed: |
|
91 |
logging.error("Can't activate master IP: %s", result.output) |
|
92 |
ok = False |
|
93 |
|
|
94 |
result = utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_netdev, |
|
95 |
"-s", master_ip, master_ip]) |
|
96 |
# we'll ignore the exit code of arping |
|
97 |
|
|
98 |
# and now start the master and rapi daemons |
|
99 |
if start_daemons: |
|
100 |
for daemon in 'ganeti-masterd', 'ganeti-rapi': |
|
101 |
result = utils.RunCmd([daemon]) |
|
102 |
if result.failed: |
|
103 |
logging.error("Can't start daemon %s: %s", daemon, result.output) |
|
104 |
ok = False |
|
105 |
return ok |
|
67 | 106 |
|
68 | 107 |
|
69 | 108 |
def StopMaster(stop_daemons): |
... | ... | |
74 | 113 |
stop the master daemons (ganet-masterd and ganeti-rapi). |
75 | 114 |
|
76 | 115 |
""" |
77 |
result = utils.RunCmd([constants.MASTER_SCRIPT, "-d", "stop"]) |
|
116 |
master_netdev, master_ip = _GetMasterInfo() |
|
117 |
if not master_netdev: |
|
118 |
return False |
|
78 | 119 |
|
120 |
result = utils.RunCmd(["ip", "address", "del", "%s/32" % master_ip, |
|
121 |
"dev", master_netdev]) |
|
79 | 122 |
if result.failed: |
80 |
logging.error("could not deactivate cluster interface with command %s," |
|
81 |
" error: '%s'", result.cmd, result.output) |
|
82 |
return False |
|
123 |
logger.error("Can't remove the master IP, error: %s", result.output) |
|
124 |
# but otherwise ignore the failure |
|
125 |
|
|
126 |
if stop_daemons: |
|
127 |
# stop/kill the rapi and the master daemon |
|
128 |
for daemon in constants.RAPI_PID, constants.MASTERD_PID: |
|
129 |
utils.KillProcess(utils.ReadPidFile(utils.DaemonPidFileName(daemon))) |
|
83 | 130 |
|
84 | 131 |
return True |
85 | 132 |
|
Also available in: Unified diff