Statistics
| Branch: | Tag: | Revision:

root / lib / utils / lvm.py @ 364c350f

History | View | Annotate | Download (2.8 kB)

1 59726e15 Bernardo Dal Seno
#
2 59726e15 Bernardo Dal Seno
#
3 59726e15 Bernardo Dal Seno
4 59726e15 Bernardo Dal Seno
# Copyright (C) 2006, 2007, 2010, 2011, 2012 Google Inc.
5 59726e15 Bernardo Dal Seno
#
6 59726e15 Bernardo Dal Seno
# This program is free software; you can redistribute it and/or modify
7 59726e15 Bernardo Dal Seno
# it under the terms of the GNU General Public License as published by
8 59726e15 Bernardo Dal Seno
# the Free Software Foundation; either version 2 of the License, or
9 59726e15 Bernardo Dal Seno
# (at your option) any later version.
10 59726e15 Bernardo Dal Seno
#
11 59726e15 Bernardo Dal Seno
# This program is distributed in the hope that it will be useful, but
12 59726e15 Bernardo Dal Seno
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 59726e15 Bernardo Dal Seno
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 59726e15 Bernardo Dal Seno
# General Public License for more details.
15 59726e15 Bernardo Dal Seno
#
16 59726e15 Bernardo Dal Seno
# You should have received a copy of the GNU General Public License
17 59726e15 Bernardo Dal Seno
# along with this program; if not, write to the Free Software
18 59726e15 Bernardo Dal Seno
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 59726e15 Bernardo Dal Seno
# 02110-1301, USA.
20 59726e15 Bernardo Dal Seno
21 59726e15 Bernardo Dal Seno
"""Utility functions for LVM.
22 59726e15 Bernardo Dal Seno

23 59726e15 Bernardo Dal Seno
"""
24 59726e15 Bernardo Dal Seno
25 63c73073 Bernardo Dal Seno
from ganeti import constants
26 63c73073 Bernardo Dal Seno
27 63c73073 Bernardo Dal Seno
28 59726e15 Bernardo Dal Seno
def CheckVolumeGroupSize(vglist, vgname, minsize):
29 59726e15 Bernardo Dal Seno
  """Checks if the volume group list is valid.
30 59726e15 Bernardo Dal Seno

31 59726e15 Bernardo Dal Seno
  The function will check if a given volume group is in the list of
32 59726e15 Bernardo Dal Seno
  volume groups and has a minimum size.
33 59726e15 Bernardo Dal Seno

34 59726e15 Bernardo Dal Seno
  @type vglist: dict
35 59726e15 Bernardo Dal Seno
  @param vglist: dictionary of volume group names and their size
36 59726e15 Bernardo Dal Seno
  @type vgname: str
37 59726e15 Bernardo Dal Seno
  @param vgname: the volume group we should check
38 59726e15 Bernardo Dal Seno
  @type minsize: int
39 59726e15 Bernardo Dal Seno
  @param minsize: the minimum size we accept
40 59726e15 Bernardo Dal Seno
  @rtype: None or str
41 59726e15 Bernardo Dal Seno
  @return: None for success, otherwise the error message
42 59726e15 Bernardo Dal Seno

43 59726e15 Bernardo Dal Seno
  """
44 59726e15 Bernardo Dal Seno
  vgsize = vglist.get(vgname, None)
45 59726e15 Bernardo Dal Seno
  if vgsize is None:
46 59726e15 Bernardo Dal Seno
    return "volume group '%s' missing" % vgname
47 59726e15 Bernardo Dal Seno
  elif vgsize < minsize:
48 59726e15 Bernardo Dal Seno
    return ("volume group '%s' too small (%s MiB required, %d MiB found)" %
49 59726e15 Bernardo Dal Seno
            (vgname, minsize, vgsize))
50 59726e15 Bernardo Dal Seno
  return None
51 63c73073 Bernardo Dal Seno
52 63c73073 Bernardo Dal Seno
53 63c73073 Bernardo Dal Seno
def LvmExclusiveCheckNodePvs(pvs_info):
54 63c73073 Bernardo Dal Seno
  """Check consistency of PV sizes in a node for exclusive storage.
55 63c73073 Bernardo Dal Seno

56 63c73073 Bernardo Dal Seno
  @type pvs_info: list
57 63c73073 Bernardo Dal Seno
  @param pvs_info: list of L{LvmPvInfo} objects
58 11064155 Bernardo Dal Seno
  @rtype: tuple
59 11064155 Bernardo Dal Seno
  @return: A pair composed of: 1. a list of error strings describing the
60 11064155 Bernardo Dal Seno
    violations found, or an empty list if everything is ok; 2. a pair
61 11064155 Bernardo Dal Seno
    containing the sizes of the smallest and biggest PVs, in MiB.
62 11064155 Bernardo Dal Seno

63 63c73073 Bernardo Dal Seno
  """
64 63c73073 Bernardo Dal Seno
  errmsgs = []
65 63c73073 Bernardo Dal Seno
  sizes = [pv.size for pv in pvs_info]
66 63c73073 Bernardo Dal Seno
  # The sizes of PVs must be the same (tolerance is constants.PART_MARGIN)
67 63c73073 Bernardo Dal Seno
  small = min(sizes)
68 63c73073 Bernardo Dal Seno
  big = max(sizes)
69 63c73073 Bernardo Dal Seno
  if LvmExclusiveTestBadPvSizes(small, big):
70 63c73073 Bernardo Dal Seno
    m = ("Sizes of PVs are too different: min=%d max=%d" % (small, big))
71 63c73073 Bernardo Dal Seno
    errmsgs.append(m)
72 11064155 Bernardo Dal Seno
  return (errmsgs, (small, big))
73 63c73073 Bernardo Dal Seno
74 63c73073 Bernardo Dal Seno
75 63c73073 Bernardo Dal Seno
def LvmExclusiveTestBadPvSizes(small, big):
76 63c73073 Bernardo Dal Seno
  """Test if the given PV sizes are permitted with exclusive storage.
77 63c73073 Bernardo Dal Seno

78 63c73073 Bernardo Dal Seno
  @param small: size of the smallest PV
79 63c73073 Bernardo Dal Seno
  @param big: size of the biggest PV
80 63c73073 Bernardo Dal Seno
  @return: True when the given sizes are bad, False otherwise
81 63c73073 Bernardo Dal Seno
  """
82 63c73073 Bernardo Dal Seno
  # Test whether no X exists such that:
83 63c73073 Bernardo Dal Seno
  #   small >= X * (1 - constants.PART_MARGIN)  and
84 63c73073 Bernardo Dal Seno
  #   big <= X * (1 + constants.PART_MARGIN)
85 63c73073 Bernardo Dal Seno
  return (small * (1 + constants.PART_MARGIN) <
86 63c73073 Bernardo Dal Seno
          big * (1 - constants.PART_MARGIN))