Revision e94fc80c tools/cfgupgrade

b/tools/cfgupgrade
102 102
  return False
103 103

  
104 104

  
105
def UpgradeIPolicy(ipolicy):
105
def _FillIPolicySpecs(default_ipolicy, ipolicy):
106
  if "minmax" in ipolicy:
107
    for (key, spec) in ipolicy["minmax"].items():
108
      for (par, val) in default_ipolicy["minmax"][key].items():
109
        if par not in spec:
110
          spec[par] = val
111

  
112

  
113
def UpgradeIPolicy(ipolicy, default_ipolicy, isgroup):
106 114
  minmax_keys = ["min", "max"]
107 115
  if any((k in ipolicy) for k in minmax_keys):
108 116
    minmax = {}
109
    ipolicy["minmax"] = minmax
110 117
    for key in minmax_keys:
111 118
      if key in ipolicy:
112
        minmax[key] = ipolicy[key]
119
        if ipolicy[key]:
120
          minmax[key] = ipolicy[key]
113 121
        del ipolicy[key]
114
      else:
115
        minmax[key] = {}
122
    if minmax:
123
      ipolicy["minmax"] = minmax
124
  if isgroup and "std" in ipolicy:
125
    del ipolicy["std"]
126
  _FillIPolicySpecs(default_ipolicy, ipolicy)
116 127

  
117 128

  
118 129
def UpgradeNetworks(config_data):
......
125 136
  cluster = config_data.get("cluster", None)
126 137
  if cluster is None:
127 138
    raise Error("Cannot find cluster")
128
  ipolicy = cluster.get("ipolicy", None)
139
  ipolicy = cluster.setdefault("ipolicy", None)
129 140
  if ipolicy:
130
    UpgradeIPolicy(ipolicy)
141
    UpgradeIPolicy(ipolicy, constants.IPOLICY_DEFAULTS, False)
131 142

  
132 143

  
133 144
def UpgradeGroups(config_data):
145
  cl_ipolicy = config_data["cluster"].get("ipolicy")
134 146
  for group in config_data["nodegroups"].values():
135 147
    networks = group.get("networks", None)
136 148
    if not networks:
137 149
      group["networks"] = {}
138 150
    ipolicy = group.get("ipolicy", None)
139 151
    if ipolicy:
140
      UpgradeIPolicy(ipolicy)
152
      if cl_ipolicy is None:
153
        raise Error("A group defines an instance policy but there is no"
154
                    " instance policy at cluster level")
155
      UpgradeIPolicy(ipolicy, cl_ipolicy, True)
141 156

  
142 157

  
143 158
def UpgradeInstances(config_data):
......
258 273
    for key in minmax_keys:
259 274
      spec = minmax.get(key, {})
260 275
      ipolicy[key] = spec
276
    if "std" not in ipolicy:
277
      ipolicy["std"] = {}
261 278

  
262 279

  
263 280
def DowngradeGroups(config_data):
264 281
  for group in config_data["nodegroups"].values():
265 282
    ipolicy = group.get("ipolicy", None)
266
    if ipolicy:
283
    if ipolicy is not None:
267 284
      DowngradeIPolicy(ipolicy)
268 285

  
269 286

  

Also available in: Unified diff