Merge tag '0.10.2'
[ganeti_webmgr.git] / ganeti_web / caps.py
blob1328f4f27a65e4f6f10a3cfd94f09e405ab70093
1 """
2 Capabilities for clusters.
4 This module can classify clusters into a capability group, and provides some
5 helpful utility functions for determining what clusters are capable of doing.
7 Versions recognized by this module (and GWM at large):
9 * ANCIENT: Ganeti from before the dawn of time. Ganeti 2.1 and earlier, as
10 well as any unrecognized versions.
11 * GANETI22: Ganeti 2.2.x
12 * GANETI23: Ganeti 2.3.x
13 * GANETI24: Ganeti 2.4.x prior to 2.4.2
14 * GANETI242: Ganeti 2.4.2 and newer in the 2.4.x series
15 * GANETI25: Ganeti 2.5.x
16 * GANETI26: Ganeti 2.6.x
17 * FUTURE: Ganeti which probably is newer than, and somewhat
18 backwards-compatible with, the newest version of Ganeti which GWM
19 officially supports.
21 Note that all bets are off if the cluster's version doesn't correspond to the
22 x.y.z (major.minor.patch) versioning pattern.
23 """
26 ANCIENT,
27 GANETI22,
28 GANETI23,
29 GANETI24,
30 GANETI242,
31 GANETI25,
32 GANETI26,
33 FUTURE,
34 ) = range(8)
37 def classify(cluster):
38 """
39 Determine the class of a cluster by examining its version.
40 """
42 # Extract the version string from the cluster.
43 s = cluster.info["software_version"]
45 # First, try the whole splitting thing. If we can't do it that way, assume
46 # it's ancient.
47 try:
48 version = tuple(int(x) for x in s.split("."))
49 except ValueError:
50 return ANCIENT
52 if version >= (2, 7, 0):
53 return FUTURE
54 if version >= (2, 6, 0):
55 return GANETI26
56 elif version >= (2, 5, 0):
57 return GANETI25
58 elif version >= (2, 4, 2):
59 return GANETI242
60 elif version >= (2, 4, 0):
61 return GANETI24
62 elif version >= (2, 3, 0):
63 return GANETI23
64 elif version >= (2, 2, 0):
65 return GANETI22
66 else:
67 return ANCIENT
70 def has_shutdown_timeout(cluster):
71 """
72 Determine whether a cluster supports timeouts for shutting down VMs.
73 """
75 return classify(cluster) >= GANETI25
78 def has_cdrom2(cluster):
79 """
80 Determine whether a cluster supports a second CDROM device.
81 """
83 return classify(cluster) >= GANETI242
86 def has_balloonmem(cluster):
87 """
88 Determine whether a cluster requires min/maxmem rather than
89 just memory.
90 """
92 return classify(cluster) >= GANETI26
95 def has_sharedfile(cluster):
96 """
97 Determine whether a cluster supports the sharedfile disk template.
98 """
100 return classify(cluster) >= GANETI25