]> git.proxmox.com Git - ceph.git/blame - ceph/src/ceph-volume/ceph_volume/devices/lvm/strategies/validators.py
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / lvm / strategies / validators.py
CommitLineData
1adf2230
AA
1from ceph_volume.util import disk
2from ceph_volume.api import lvm
3
4
11fdf7f2 5def minimum_device_size(devices, osds_per_device=1, min_size=5):
1adf2230
AA
6 """
7 Ensure that the minimum requirements for this type of scenario is
8 met, raise an error if the provided devices would not work
9 """
11fdf7f2 10 msg = 'Unable to use device %s %s, LVs would be smaller than {}GB'.format(min_size)
1adf2230 11 for device in devices:
11fdf7f2 12 device_size = disk.Size(b=device.lvm_size.b)
91327a77 13 lv_size = device_size / osds_per_device
11fdf7f2 14 if lv_size < disk.Size(gb=min_size):
91327a77
AA
15 raise RuntimeError(msg % (device_size, device.path))
16
17
18def minimum_device_collocated_size(devices, journal_size, osds_per_device=1):
19 """
20 Similar to ``minimum_device_size``, but take into account that the size of
21 the journal affects the size left of the device
22 """
23 msg = 'Unable to use device %s %s, LVs would be smaller than 5GB'
24 for device in devices:
11fdf7f2 25 device_size = disk.Size(b=device.lvm_size.b)
91327a77
AA
26 lv_size = (device_size / osds_per_device) - journal_size
27 if lv_size < disk.Size(gb=5):
28 raise RuntimeError(msg % (device_size, device.path))
1adf2230
AA
29
30
31def no_lvm_membership(devices):
32 """
33 Do not allow devices that are part of LVM
34 """
35 msg = 'Unable to use device, already a member of LVM: %s'
36 for device in devices:
37 if device.is_lvm_member:
38 raise RuntimeError(msg % device.abspath)
39
40
41def has_common_vg(ssd_devices):
42 """
43 Ensure that devices have a common VG between them
44 """
45 msg = 'Could not find a common VG between devices: %s'
1adf2230
AA
46 ssd_vgs = {}
47
48 for ssd_device in ssd_devices:
92f5a8d4
TL
49 vgs = lvm.get_device_vgs(ssd_device.abspath)
50 if not vgs:
51 continue
52 for vg in vgs:
1adf2230
AA
53 try:
54 ssd_vgs[vg.name].append(ssd_device.abspath)
55 except KeyError:
56 ssd_vgs[vg.name] = [ssd_device.abspath]
57 # len of 1 means they all have a common vg, and len of 0 means that these
58 # are blank
59 if len(ssd_vgs) <= 1:
60 return
61 raise RuntimeError(msg % ', '.join(ssd_vgs.keys()))