Revision c294f84e tools/cfgupgrade

b/tools/cfgupgrade
260 260
  UpgradeInstances(config_data)
261 261

  
262 262

  
263
def DowngradeIPolicy(ipolicy, owner):
264
  # Downgrade IPolicy to 2.7 (stable)
265
  minmax_keys = ["min", "max"]
266
  specs_is_split = any((k in ipolicy) for k in minmax_keys)
267
  if not specs_is_split:
268
    if "minmax" in ipolicy:
269
      if type(ipolicy["minmax"]) is not list:
270
        raise Error("Invalid minmax type in %s ipolicy: %s" %
271
                    (owner, type(ipolicy["minmax"])))
272
      if len(ipolicy["minmax"]) > 1:
273
        logging.warning("Discarding some limit specs values from %s policy",
274
                        owner)
275
      minmax = ipolicy["minmax"][0]
276
      del ipolicy["minmax"]
277
    else:
278
      minmax = {}
279
    for key in minmax_keys:
280
      spec = minmax.get(key, {})
281
      ipolicy[key] = spec
282
    if "std" not in ipolicy:
283
      ipolicy["std"] = {}
284

  
285

  
286
def DowngradeGroups(config_data):
287
  for group in config_data["nodegroups"].values():
288
    ipolicy = group.get("ipolicy", None)
289
    if ipolicy is not None:
290
      DowngradeIPolicy(ipolicy, "group \"%s\"" % group.get("name"))
291

  
292

  
293
def DowngradeEnabledTemplates(cluster):
294
  # Remove enabled disk templates to downgrade to 2.7
295
  edt_key = "enabled_disk_templates"
296
  if edt_key in cluster:
297
    logging.warning("Removing cluster's enabled disk templates; value = %s",
298
                    utils.CommaJoin(cluster[edt_key]))
299
    del cluster[edt_key]
300

  
301

  
302
def DowngradeCluster(config_data):
303
  cluster = config_data.get("cluster", None)
304
  if cluster is None:
305
    raise Error("Cannot find cluster")
306
  DowngradeEnabledTemplates(cluster)
307
  ipolicy = cluster.get("ipolicy", None)
308
  if ipolicy:
309
    DowngradeIPolicy(ipolicy, "cluster")
310

  
311

  
312 263
def DowngradeAll(config_data):
264
  # Unused arguments, pylint: disable=W0613
313 265
  # Any code specific to a particular version should be labeled that way, so
314 266
  # it can be removed when updating to the next version.
315
  DowngradeCluster(config_data)
316
  DowngradeGroups(config_data)
267
  pass
317 268

  
318 269

  
319 270
def main():

Also available in: Unified diff