Revision 0890e0d1 lib/utils/version.py

b/lib/utils/version.py
23 23

  
24 24
import re
25 25

  
26
from ganeti import constants
27

  
26 28
_FULL_VERSION_RE = re.compile(r"(\d+)\.(\d+)\.(\d+)")
27 29
_SHORT_VERSION_RE = re.compile(r"(\d+)\.(\d+)")
28 30

  
31
# The first Ganeti version that supports automatic upgrades
32
FIRST_UPGRADE_VERSION = (2, 10, 0)
33

  
34
CURRENT_VERSION = (constants.VERSION_MAJOR, constants.VERSION_MINOR,
35
                   constants.VERSION_REVISION)
36

  
29 37
# Format for CONFIG_VERSION:
30 38
#   01 03 0123 = 01030123
31 39
#   ^^ ^^ ^^^^
......
87 95
    return (int(m.group(1)), int(m.group(2)), 0)
88 96

  
89 97
  return None
98

  
99

  
100
def UpgradeRange(target, current=CURRENT_VERSION):
101
  """Verify whether a version is within the range of automatic upgrades.
102

  
103
  @param target: The version to upgrade to as (major, minor, revision)
104
  @type target: tuple
105
  @param current: The version to upgrade from as (major, minor, revision)
106
  @type current: tuple
107
  @rtype: string or None
108
  @return: None, if within the range, and a human-readable error message
109
      otherwise
110

  
111
  """
112
  if target < FIRST_UPGRADE_VERSION or current < FIRST_UPGRADE_VERSION:
113
    return "automatic upgrades only supported from 2.10 onwards"
114

  
115
  if target[0] != current[0]:
116
    return "different major versions"
117

  
118
  if target[1] < current[1] - 1:
119
    return "can only downgrade one minor version at a time"
120

  
121
  return None

Also available in: Unified diff