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