root / lib / utils / lvm.py @ 63c73073
History  View  Annotate  Download (2.7 kB)
1 
#


2 
#

3  
4 
# Copyright (C) 2006, 2007, 2010, 2011, 2012 Google Inc.

5 
#

6 
# This program is free software; you can redistribute it and/or modify

7 
# it under the terms of the GNU General Public License as published by

8 
# the Free Software Foundation; either version 2 of the License, or

9 
# (at your option) any later version.

10 
#

11 
# This program is distributed in the hope that it will be useful, but

12 
# WITHOUT ANY WARRANTY; without even the implied warranty of

13 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

14 
# General Public License for more details.

15 
#

16 
# You should have received a copy of the GNU General Public License

17 
# along with this program; if not, write to the Free Software

18 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA

19 
# 021101301, USA.

20  
21 
"""Utility functions for LVM.

22 

23 
"""

24  
25 
from ganeti import constants 
26  
27  
28 
def CheckVolumeGroupSize(vglist, vgname, minsize): 
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  
53 
def LvmExclusiveCheckNodePvs(pvs_info): 
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: list

59 
@return: A list of error strings described the violation found, or an empty

60 
list if everything is ok

61 
"""

62 
errmsgs = [] 
63 
sizes = [pv.size for pv in pvs_info] 
64 
# The sizes of PVs must be the same (tolerance is constants.PART_MARGIN)

65 
small = min(sizes)

66 
big = max(sizes)

67 
if LvmExclusiveTestBadPvSizes(small, big):

68 
m = ("Sizes of PVs are too different: min=%d max=%d" % (small, big))

69 
errmsgs.append(m) 
70 
return errmsgs

71  
72  
73 
def LvmExclusiveTestBadPvSizes(small, big): 
74 
"""Test if the given PV sizes are permitted with exclusive storage.

75 

76 
@param small: size of the smallest PV

77 
@param big: size of the biggest PV

78 
@return: True when the given sizes are bad, False otherwise

79 
"""

80 
# Test whether no X exists such that:

81 
# small >= X * (1  constants.PART_MARGIN) and

82 
# big <= X * (1 + constants.PART_MARGIN)

83 
return (small * (1 + constants.PART_MARGIN) < 
84 
big * (1  constants.PART_MARGIN))
