Revision 7187a877 tools/cfgupgrade

b/tools/cfgupgrade
58 58
#: Target minor version for downgrade
59 59
DOWNGRADE_MINOR = 8
60 60

  
61
# map of legacy device types
62
# (mapping differing old LD_* constants to new DT_* constants)
63
DEV_TYPE_OLD_NEW = {"lvm": constants.DT_PLAIN, "drbd8": constants.DT_DRBD8}
64
# (mapping differing new DT_* constants to old LD_* constants)
65
DEV_TYPE_NEW_OLD = {v:k for k,v in DEV_TYPE_OLD_NEW.items()}
66

  
61 67

  
62 68
class Error(Exception):
63 69
  """Generic exception"""
......
173 179
  return ret
174 180

  
175 181

  
182
def ChangeDiskDevType(disk, dev_type_map):
183
  """Replaces disk's dev_type attributes according to the given map.
184

  
185
  This can be used for both, up or downgrading the disks.
186
  """
187
  if disk["dev_type"] in dev_type_map:
188
    disk["dev_type"] = dev_type_map[disk["dev_type"]]
189
  if "children" in disk:
190
    for child in disk["children"]:
191
      ChangeDiskDevType(child, dev_type_map)
192

  
193

  
194
def UpgradeDiskDevType(disk):
195
  """Upgrades the disks' device type."""
196
  ChangeDiskDevType(disk, DEV_TYPE_OLD_NEW)
197

  
198

  
176 199
def UpgradeInstances(config_data):
200
  """Upgrades the instances' configuration."""
201

  
177 202
  network2uuid = dict((n["name"], n["uuid"])
178 203
                      for n in config_data["networks"].values())
179 204
  if "instances" not in config_data:
......
201 226
                        " from '%s' to '%s'",
202 227
                        instance, idx, current, expected)
203 228
        dobj["iv_name"] = expected
229

  
230
      if "dev_type" in dobj:
231
        UpgradeDiskDevType(dobj)
232

  
204 233
      if not "spindles" in dobj:
205 234
        missing_spindles = True
206 235

  
......
288 317

  
289 318
def ChangeNodeIndices(config_data, old_key_field, new_key_field):
290 319
  def ChangeDiskNodeIndices(disk):
291
    if disk["dev_type"] in constants.LDS_DRBD:
320
    # Note: 'drbd8' is a legacy device type from pre 2.9 and needs to be
321
    # considered when up/downgrading from/to any versions touching 2.9 on the
322
    # way.
323
    drbd_disk_types = set(["drbd8"]) | constants.DTS_DRBD
324
    if disk["dev_type"] in drbd_disk_types:
292 325
      for i in range(0, 2):
293 326
        disk["logical_id"][i] = GetNewNodeIndex(nodes_by_old_key,
294 327
                                                disk["logical_id"][i],
......
350 383
  UpgradeInstanceIndices(config_data)
351 384

  
352 385

  
386
def DowngradeDiskDevType(disk):
387
  """Downgrades the disks' device type."""
388
  ChangeDiskDevType(disk, DEV_TYPE_NEW_OLD)
389

  
353 390
def DowngradeDisks(disks, owner):
354 391
  for disk in disks:
355 392
    # Remove spindles to downgrade to 2.8
......
358 395
                      " instance %s",
359 396
                      disk["spindles"], disk["iv_name"], disk["uuid"], owner)
360 397
      del disk["spindles"]
398
    if "dev_type" in disk:
399
      DowngradeDiskDevType(disk)
361 400

  
362 401

  
363 402
def DowngradeInstances(config_data):

Also available in: Unified diff