1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """Utility functions for LVM.
22
23 """
24
25 from ganeti import constants
26
27
29 """Checks if the volume group list is valid.
30
31 The function will check if a given volume group is in the list of
32 volume groups and has a minimum size.
33
34 @type vglist: dict
35 @param vglist: dictionary of volume group names and their size
36 @type vgname: str
37 @param vgname: the volume group we should check
38 @type minsize: int
39 @param minsize: the minimum size we accept
40 @rtype: None or str
41 @return: None for success, otherwise the error message
42
43 """
44 vgsize = vglist.get(vgname, None)
45 if vgsize is None:
46 return "volume group '%s' missing" % vgname
47 elif vgsize < minsize:
48 return ("volume group '%s' too small (%s MiB required, %d MiB found)" %
49 (vgname, minsize, vgsize))
50 return None
51
52
54 """Check consistency of PV sizes in a node for exclusive storage.
55
56 @type pvs_info: list
57 @param pvs_info: list of L{LvmPvInfo} objects
58 @rtype: tuple
59 @return: A pair composed of: 1. a list of error strings describing the
60 violations found, or an empty list if everything is ok; 2. a pair
61 containing the sizes of the smallest and biggest PVs, in MiB.
62
63 """
64 errmsgs = []
65 sizes = [pv.size for pv in pvs_info]
66
67 small = min(sizes)
68 big = max(sizes)
69 if LvmExclusiveTestBadPvSizes(small, big):
70 m = ("Sizes of PVs are too different: min=%d max=%d" % (small, big))
71 errmsgs.append(m)
72 return (errmsgs, (small, big))
73
74
76 """Test if the given PV sizes are permitted with exclusive storage.
77
78 @param small: size of the smallest PV
79 @param big: size of the biggest PV
80 @return: True when the given sizes are bad, False otherwise
81 """
82
83
84
85 return (small * (1 + constants.PART_MARGIN) <
86 big * (1 - constants.PART_MARGIN))
87