Package ganeti :: Package utils :: Module lvm
[hide private]
[frames] | no frames]

Source Code for Module ganeti.utils.lvm

 1  # 
 2  # 
 3   
 4  # Copyright (C) 2006, 2007, 2010, 2011, 2012 Google Inc. 
 5  # All rights reserved. 
 6  # 
 7  # Redistribution and use in source and binary forms, with or without 
 8  # modification, are permitted provided that the following conditions are 
 9  # met: 
10  # 
11  # 1. Redistributions of source code must retain the above copyright notice, 
12  # this list of conditions and the following disclaimer. 
13  # 
14  # 2. Redistributions in binary form must reproduce the above copyright 
15  # notice, this list of conditions and the following disclaimer in the 
16  # documentation and/or other materials provided with the distribution. 
17  # 
18  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
19  # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
20  # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
21  # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
22  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
23  # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
24  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
25  # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
26  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
27  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
28  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
29   
30  """Utility functions for LVM. 
31   
32  """ 
33   
34  from ganeti import constants 
35   
36   
37 -def CheckVolumeGroupSize(vglist, vgname, minsize):
38 """Checks if the volume group list is valid. 39 40 The function will check if a given volume group is in the list of 41 volume groups and has a minimum size. 42 43 @type vglist: dict 44 @param vglist: dictionary of volume group names and their size 45 @type vgname: str 46 @param vgname: the volume group we should check 47 @type minsize: int 48 @param minsize: the minimum size we accept 49 @rtype: None or str 50 @return: None for success, otherwise the error message 51 52 """ 53 vgsize = vglist.get(vgname, None) 54 if vgsize is None: 55 return "volume group '%s' missing" % vgname 56 elif vgsize < minsize: 57 return ("volume group '%s' too small (%s MiB required, %d MiB found)" % 58 (vgname, minsize, vgsize)) 59 return None
60 61
62 -def LvmExclusiveCheckNodePvs(pvs_info):
63 """Check consistency of PV sizes in a node for exclusive storage. 64 65 @type pvs_info: list 66 @param pvs_info: list of L{LvmPvInfo} objects 67 @rtype: tuple 68 @return: A pair composed of: 1. a list of error strings describing the 69 violations found, or an empty list if everything is ok; 2. a pair 70 containing the sizes of the smallest and biggest PVs, in MiB. 71 72 """ 73 errmsgs = [] 74 sizes = [pv.size for pv in pvs_info] 75 # The sizes of PVs must be the same (tolerance is constants.PART_MARGIN) 76 small = min(sizes) 77 big = max(sizes) 78 if LvmExclusiveTestBadPvSizes(small, big): 79 m = ("Sizes of PVs are too different: min=%d max=%d" % (small, big)) 80 errmsgs.append(m) 81 return (errmsgs, (small, big))
82 83
84 -def LvmExclusiveTestBadPvSizes(small, big):
85 """Test if the given PV sizes are permitted with exclusive storage. 86 87 @param small: size of the smallest PV 88 @param big: size of the biggest PV 89 @return: True when the given sizes are bad, False otherwise 90 """ 91 # Test whether no X exists such that: 92 # small >= X * (1 - constants.PART_MARGIN) and 93 # big <= X * (1 + constants.PART_MARGIN) 94 return (small * (1 + constants.PART_MARGIN) < 95 big * (1 - constants.PART_MARGIN))
96