]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/devices/lvm/strategies/validators.py
update sources to 12.2.8
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / lvm / strategies / validators.py
1 from ceph_volume.util import disk
2 from ceph_volume.api import lvm
3
4
5 def minimum_device_size(devices):
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 """
10 msg = 'Unable to use device smaller than 5GB: %s (%s)'
11 for device in devices:
12 device_size = disk.Size(b=device.sys_api['size'])
13 if device_size < disk.Size(gb=5):
14 raise RuntimeError(msg % (device, device_size))
15
16
17 def no_lvm_membership(devices):
18 """
19 Do not allow devices that are part of LVM
20 """
21 msg = 'Unable to use device, already a member of LVM: %s'
22 for device in devices:
23 if device.is_lvm_member:
24 raise RuntimeError(msg % device.abspath)
25
26
27 def has_common_vg(ssd_devices):
28 """
29 Ensure that devices have a common VG between them
30 """
31 msg = 'Could not find a common VG between devices: %s'
32 system_vgs = lvm.VolumeGroups()
33 ssd_vgs = {}
34
35 for ssd_device in ssd_devices:
36 for pv in ssd_device.pvs_api:
37 vg = system_vgs.get(vg_name=pv.vg_name)
38 if not vg:
39 continue
40 try:
41 ssd_vgs[vg.name].append(ssd_device.abspath)
42 except KeyError:
43 ssd_vgs[vg.name] = [ssd_device.abspath]
44 # len of 1 means they all have a common vg, and len of 0 means that these
45 # are blank
46 if len(ssd_vgs) <= 1:
47 return
48 raise RuntimeError(msg % ', '.join(ssd_vgs.keys()))