Revision 0b94cda8 tools/cfgupgrade
b/tools/cfgupgrade | ||
---|---|---|
102 | 102 |
return False |
103 | 103 |
|
104 | 104 |
|
105 |
def UpgradeIPolicy(ipolicy): |
|
106 |
minmax_keys = ["min", "max"] |
|
107 |
if any((k in ipolicy) for k in minmax_keys): |
|
108 |
minmax = {} |
|
109 |
ipolicy["minmax"] = minmax |
|
110 |
for key in minmax_keys: |
|
111 |
if key in ipolicy: |
|
112 |
minmax[key] = ipolicy[key] |
|
113 |
del ipolicy[key] |
|
114 |
else: |
|
115 |
minmax[key] = {} |
|
116 |
|
|
117 |
|
|
105 | 118 |
def UpgradeNetworks(config_data): |
106 | 119 |
networks = config_data.get("networks", None) |
107 | 120 |
if not networks: |
108 | 121 |
config_data["networks"] = {} |
109 | 122 |
|
110 | 123 |
|
124 |
def UpgradeCluster(config_data): |
|
125 |
cluster = config_data.get("cluster", None) |
|
126 |
if cluster is None: |
|
127 |
raise Error("Cannot find cluster") |
|
128 |
ipolicy = cluster.get("ipolicy", None) |
|
129 |
if ipolicy: |
|
130 |
UpgradeIPolicy(ipolicy) |
|
131 |
|
|
132 |
|
|
111 | 133 |
def UpgradeGroups(config_data): |
112 | 134 |
for group in config_data["nodegroups"].values(): |
113 | 135 |
networks = group.get("networks", None) |
114 | 136 |
if not networks: |
115 | 137 |
group["networks"] = {} |
138 |
ipolicy = group.get("ipolicy", None) |
|
139 |
if ipolicy: |
|
140 |
UpgradeIPolicy(ipolicy) |
|
116 | 141 |
|
117 | 142 |
|
118 | 143 |
def UpgradeInstances(config_data): |
... | ... | |
215 | 240 |
UpgradeWatcher() |
216 | 241 |
UpgradeFileStoragePaths(config_data) |
217 | 242 |
UpgradeNetworks(config_data) |
243 |
UpgradeCluster(config_data) |
|
218 | 244 |
UpgradeGroups(config_data) |
219 | 245 |
UpgradeInstances(config_data) |
220 | 246 |
|
221 | 247 |
|
248 |
def DowngradeIPolicy(ipolicy): |
|
249 |
# Downgrade IPolicy to 2.7 (stable) |
|
250 |
minmax_keys = ["min", "max"] |
|
251 |
specs_is_split = any((k in ipolicy) for k in minmax_keys) |
|
252 |
if not specs_is_split: |
|
253 |
if "minmax" in ipolicy: |
|
254 |
minmax = ipolicy["minmax"] |
|
255 |
del ipolicy["minmax"] |
|
256 |
else: |
|
257 |
minmax = {} |
|
258 |
for key in minmax_keys: |
|
259 |
spec = minmax.get(key, {}) |
|
260 |
ipolicy[key] = spec |
|
261 |
|
|
262 |
|
|
263 |
def DowngradeGroups(config_data): |
|
264 |
for group in config_data["nodegroups"].values(): |
|
265 |
ipolicy = group.get("ipolicy", None) |
|
266 |
if ipolicy: |
|
267 |
DowngradeIPolicy(ipolicy) |
|
268 |
|
|
269 |
|
|
222 | 270 |
def DowngradeStorageTypes(cluster): |
223 | 271 |
# Remove storage types to downgrade to 2.7 |
224 | 272 |
if "enabled_storage_types" in cluster: |
... | ... | |
232 | 280 |
if cluster is None: |
233 | 281 |
raise Error("Cannot find cluster") |
234 | 282 |
DowngradeStorageTypes(cluster) |
283 |
ipolicy = cluster.get("ipolicy", None) |
|
284 |
if ipolicy: |
|
285 |
DowngradeIPolicy(ipolicy) |
|
235 | 286 |
|
236 | 287 |
|
237 | 288 |
def DowngradeAll(config_data): |
238 | 289 |
# Any code specific to a particular version should be labeled that way, so |
239 | 290 |
# it can be removed when updating to the next version. |
240 | 291 |
DowngradeCluster(config_data) |
292 |
DowngradeGroups(config_data) |
|
241 | 293 |
|
242 | 294 |
|
243 | 295 |
def main(): |
... | ... | |
356 | 408 |
config_minor, config_revision)) |
357 | 409 |
DowngradeAll(config_data) |
358 | 410 |
|
359 |
# Upgrade from 2.{0..6} to 2.7
|
|
360 |
elif config_major == 2 and config_minor in (0, 1, 2, 3, 4, 5, 6):
|
|
411 |
# Upgrade from 2.{0..7} to 2.7
|
|
412 |
elif config_major == 2 and config_minor in range(0, 8):
|
|
361 | 413 |
if config_revision != 0: |
362 | 414 |
logging.warning("Config revision is %s, not 0", config_revision) |
363 | 415 |
UpgradeAll(config_data) |
Also available in: Unified diff