Revision b555101c tools/cfgupgrade
b/tools/cfgupgrade | ||
---|---|---|
278 | 278 |
backup=True) |
279 | 279 |
|
280 | 280 |
|
281 |
def GetNewNodeIndex(nodes_by_old_key, old_key, new_key_field): |
|
282 |
if old_key not in nodes_by_old_key: |
|
283 |
logging.warning("Can't find node '%s' in configuration, assuming that it's" |
|
284 |
" already up-to-date", old_key) |
|
285 |
return old_key |
|
286 |
return nodes_by_old_key[old_key][new_key_field] |
|
287 |
|
|
288 |
|
|
289 |
def ChangeNodeIndices(config_data, old_key_field, new_key_field): |
|
290 |
def ChangeDiskNodeIndices(disk): |
|
291 |
if disk["dev_type"] in constants.LDS_DRBD: |
|
292 |
for i in range(0, 2): |
|
293 |
disk["logical_id"][i] = GetNewNodeIndex(nodes_by_old_key, |
|
294 |
disk["logical_id"][i], |
|
295 |
new_key_field) |
|
296 |
if "children" in disk: |
|
297 |
for child in disk["children"]: |
|
298 |
ChangeDiskNodeIndices(child) |
|
299 |
|
|
300 |
nodes_by_old_key = {} |
|
301 |
nodes_by_new_key = {} |
|
302 |
for (_, node) in config_data["nodes"].items(): |
|
303 |
nodes_by_old_key[node[old_key_field]] = node |
|
304 |
nodes_by_new_key[node[new_key_field]] = node |
|
305 |
|
|
306 |
config_data["nodes"] = nodes_by_new_key |
|
307 |
|
|
308 |
cluster = config_data["cluster"] |
|
309 |
cluster["master_node"] = GetNewNodeIndex(nodes_by_old_key, |
|
310 |
cluster["master_node"], |
|
311 |
new_key_field) |
|
312 |
|
|
313 |
for inst in config_data["instances"].values(): |
|
314 |
inst["primary_node"] = GetNewNodeIndex(nodes_by_old_key, |
|
315 |
inst["primary_node"], |
|
316 |
new_key_field) |
|
317 |
for disk in inst["disks"]: |
|
318 |
ChangeDiskNodeIndices(disk) |
|
319 |
|
|
320 |
|
|
321 |
def UpgradeNodeIndices(config_data): |
|
322 |
ChangeNodeIndices(config_data, "name", "uuid") |
|
323 |
|
|
324 |
|
|
281 | 325 |
def UpgradeAll(config_data): |
282 | 326 |
config_data["version"] = constants.BuildVersion(TARGET_MAJOR, |
283 | 327 |
TARGET_MINOR, 0) |
... | ... | |
288 | 332 |
UpgradeCluster(config_data) |
289 | 333 |
UpgradeGroups(config_data) |
290 | 334 |
UpgradeInstances(config_data) |
335 |
UpgradeNodeIndices(config_data) |
|
291 | 336 |
|
292 | 337 |
|
293 | 338 |
def DowngradeDisks(disks, owner): |
... | ... | |
309 | 354 |
DowngradeDisks(iobj["disks"], iname) |
310 | 355 |
|
311 | 356 |
|
357 |
def DowngradeNodeIndices(config_data): |
|
358 |
ChangeNodeIndices(config_data, "uuid", "name") |
|
359 |
|
|
360 |
|
|
312 | 361 |
def DowngradeAll(config_data): |
313 | 362 |
# Any code specific to a particular version should be labeled that way, so |
314 | 363 |
# it can be removed when updating to the next version. |
315 | 364 |
DowngradeInstances(config_data) |
365 |
DowngradeNodeIndices(config_data) |
|
316 | 366 |
|
317 | 367 |
|
318 | 368 |
def main(): |
Also available in: Unified diff