]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/devices/lvm/strategies/strategies.py
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / lvm / strategies / strategies.py
1 import json
2 from ceph_volume.util.prepare import osd_id_available
3 from ceph_volume.api.lvm import get_device_vgs
4
5 class Strategy(object):
6
7 def __init__(self, args, data_devs, db_or_journal_devs=[], wal_devs=[]):
8 '''
9 Note that this ctor is used by both bluestore and filestore strategies
10 to reduce code duplication. A filestore strategy will always pass an
11 empty list for wal_devs.
12 '''
13 self.args = args
14 self.osd_ids = args.osd_ids
15 self.osds_per_device = args.osds_per_device
16 self.devices = data_devs + wal_devs + db_or_journal_devs
17 self.data_devs = data_devs
18 self.db_or_journal_devs = db_or_journal_devs
19 self.wal_devs = wal_devs
20 self.computed = {'osds': [], 'vgs': []}
21
22 @staticmethod
23 def split_devices_rotational(devices):
24 data_devs = [device for device in devices if device.rotational]
25 db_or_journal_devs = [device for device in devices if not device.rotational]
26 return data_devs, db_or_journal_devs
27
28
29 def validate_compute(self):
30 if self.devices:
31 self.validate()
32 self.compute()
33 else:
34 self.computed["changed"] = False
35
36 def report_json(self, filtered_devices):
37 # add filtered devices to report
38 report = self.computed.copy()
39 report['filtered_devices'] = filtered_devices
40 print(json.dumps(self.computed, indent=4, sort_keys=True))
41
42 def _validate_osd_ids(self):
43 unavailable_ids = [id_ for id_ in self.osd_ids if
44 not osd_id_available(id_)]
45 if unavailable_ids:
46 msg = ("Not all specfied OSD ids are available: {}"
47 "unavailable").format(",".join(unavailable_ids))
48 raise RuntimeError(msg)
49
50 @property
51 def total_osds(self):
52 return len(self.data_devs) * self.osds_per_device
53
54 # protect against base class instantiation and incomplete implementations.
55 # We could also use the abc module and implement this as an
56 # AbstractBaseClass
57 def compute(self):
58 raise NotImplementedError('compute() must be implemented in a child class')
59
60 def execute(self):
61 raise NotImplementedError('execute() must be implemented in a child class')
62
63 class MixedStrategy(Strategy):
64
65 def get_common_vg(self, devs):
66 # find all the vgs associated with the current device
67 for dev in devs:
68 vgs = get_device_vgs(dev.abspath)
69 if vgs:
70 return vgs[0]