Revision b972c223
b/tools/cluster-merge | ||
---|---|---|
40 | 40 |
from ganeti import errors |
41 | 41 |
from ganeti import ssh |
42 | 42 |
from ganeti import utils |
43 |
from ganeti import netutils |
|
43 | 44 |
|
44 | 45 |
|
45 | 46 |
_GROUPS_MERGE = "merge" |
... | ... | |
109 | 110 |
"""Container class to hold data used for merger. |
110 | 111 |
|
111 | 112 |
""" |
112 |
def __init__(self, cluster, key_path, nodes, instances, config_path=None): |
|
113 |
def __init__(self, cluster, key_path, nodes, instances, master_node, |
|
114 |
master_ip, config_path=None): |
|
113 | 115 |
"""Initialize the container. |
114 | 116 |
|
115 | 117 |
@param cluster: The name of the cluster |
116 | 118 |
@param key_path: Path to the ssh private key used for authentication |
117 | 119 |
@param nodes: List of online nodes in the merging cluster |
118 | 120 |
@param instances: List of instances running on merging cluster |
121 |
@param master_node: Name of the master node |
|
122 |
@param master_ip: Cluster IP |
|
119 | 123 |
@param config_path: Path to the merging cluster config |
120 | 124 |
|
121 | 125 |
""" |
... | ... | |
123 | 127 |
self.key_path = key_path |
124 | 128 |
self.nodes = nodes |
125 | 129 |
self.instances = instances |
130 |
self.master_node = master_node |
|
131 |
self.master_ip = master_ip |
|
126 | 132 |
self.config_path = config_path |
127 | 133 |
|
128 | 134 |
|
... | ... | |
206 | 212 |
(cluster, result.fail_reason, result.output)) |
207 | 213 |
instances = result.stdout.splitlines() |
208 | 214 |
|
209 |
self.merger_data.append(MergerData(cluster, key_path, nodes, instances)) |
|
215 |
path = utils.PathJoin(constants.DATA_DIR, "ssconf_%s" % |
|
216 |
constants.SS_MASTER_NODE) |
|
217 |
result = self._RunCmd(cluster, "cat %s" % path, private_key=key_path) |
|
218 |
if result.failed: |
|
219 |
raise errors.RemoteError("Unable to retrieve the master node name from" |
|
220 |
" %s. Fail reason: %s; output: %s" % |
|
221 |
(cluster, result.fail_reason, result.output)) |
|
222 |
master_node = result.stdout.strip() |
|
223 |
|
|
224 |
path = utils.PathJoin(constants.DATA_DIR, "ssconf_%s" % |
|
225 |
constants.SS_MASTER_IP) |
|
226 |
result = self._RunCmd(cluster, "cat %s" % path, private_key=key_path) |
|
227 |
if result.failed: |
|
228 |
raise errors.RemoteError("Unable to retrieve the master IP from" |
|
229 |
" %s. Fail reason: %s; output: %s" % |
|
230 |
(cluster, result.fail_reason, result.output)) |
|
231 |
master_ip = result.stdout.strip() |
|
232 |
|
|
233 |
self.merger_data.append(MergerData(cluster, key_path, nodes, instances, |
|
234 |
master_node, master_ip)) |
|
210 | 235 |
|
211 | 236 |
def _PrepareAuthorizedKeys(self): |
212 | 237 |
"""Prepare the authorized_keys on every merging node. |
... | ... | |
289 | 314 |
" Fail reason: %s; output: %s" % |
290 | 315 |
(cluster, result.fail_reason, result.output)) |
291 | 316 |
|
317 |
def _RemoveMasterIps(self): |
|
318 |
"""Removes the master IPs from the master nodes of each cluster. |
|
319 |
|
|
320 |
""" |
|
321 |
for data in self.merger_data: |
|
322 |
master_ip_family = netutils.IPAddress.GetAddressFamily(data.master_ip) |
|
323 |
master_ip_len = netutils.IP4Address.iplen |
|
324 |
if master_ip_family == netutils.IP6Address.family: |
|
325 |
master_ip_len = netutils.IP6Address.iplen |
|
326 |
# Not using constants.IP_COMMAND_PATH because the command might run on a |
|
327 |
# machine in which the ip path is different, so it's better to rely on |
|
328 |
# $PATH. |
|
329 |
cmd = "ip address del %s/%s dev $(cat %s)" % ( |
|
330 |
data.master_ip, |
|
331 |
master_ip_len, |
|
332 |
utils.PathJoin(constants.DATA_DIR, "ssconf_%s" % |
|
333 |
constants.SS_MASTER_NETDEV)) |
|
334 |
result = self._RunCmd(data.master_node, cmd, max_attempts=3) |
|
335 |
if result.failed: |
|
336 |
raise errors.RemoteError("Unable to remove master IP on %s." |
|
337 |
" Fail reason: %s; output: %s" % |
|
338 |
(data.master_node, |
|
339 |
result.fail_reason, |
|
340 |
result.output)) |
|
341 |
|
|
292 | 342 |
def _StopDaemons(self): |
293 | 343 |
"""Stop all daemons on merging nodes. |
294 | 344 |
|
... | ... | |
693 | 743 |
self._StopDaemons() |
694 | 744 |
logging.info("Merging config") |
695 | 745 |
self._FetchRemoteConfig() |
746 |
logging.info("Removing master IPs on mergee master nodes") |
|
747 |
self._RemoveMasterIps() |
|
696 | 748 |
|
697 | 749 |
logging.info("Stopping master daemon") |
698 | 750 |
self._KillMasterDaemon() |
Also available in: Unified diff