]> git.proxmox.com Git - ceph.git/blame - ceph/src/python-common/ceph/deployment/translate.py
import 15.2.5
[ceph.git] / ceph / src / python-common / ceph / deployment / translate.py
CommitLineData
9f95a23c
TL
1import logging
2
3try:
1911f103 4 from typing import Optional, List
9f95a23c
TL
5except ImportError:
6 pass
7
9f95a23c
TL
8from ceph.deployment.drive_selection.selector import DriveSelection
9
10logger = logging.getLogger(__name__)
11
12
f6b5b4d7 13# TODO refactor this to a DriveSelection method
9f95a23c
TL
14class to_ceph_volume(object):
15
16 def __init__(self,
1911f103
TL
17 selection, # type: DriveSelection
18 osd_id_claims=None, # type: Optional[List[str]]
19 preview=False # type: bool
9f95a23c
TL
20 ):
21
9f95a23c 22 self.selection = selection
f6b5b4d7 23 self.spec = selection.spec
1911f103
TL
24 self.preview = preview
25 self.osd_id_claims = osd_id_claims
9f95a23c
TL
26
27 def run(self):
28 # type: () -> Optional[str]
29 """ Generate ceph-volume commands based on the DriveGroup filters """
30 data_devices = [x.path for x in self.selection.data_devices()]
31 db_devices = [x.path for x in self.selection.db_devices()]
32 wal_devices = [x.path for x in self.selection.wal_devices()]
33 journal_devices = [x.path for x in self.selection.journal_devices()]
34
35 if not data_devices:
36 return None
37
1911f103 38 cmd = ""
9f95a23c
TL
39 if self.spec.objectstore == 'filestore':
40 cmd = "lvm batch --no-auto"
41
42 cmd += " {}".format(" ".join(data_devices))
43
44 if self.spec.journal_size:
45 cmd += " --journal-size {}".format(self.spec.journal_size)
46
47 if journal_devices:
48 cmd += " --journal-devices {}".format(
49 ' '.join(journal_devices))
50
51 cmd += " --filestore"
52
53 # HORRIBLE HACK
54 if self.spec.objectstore == 'bluestore' and \
55 not self.spec.encrypted and \
56 not self.spec.osds_per_device and \
57 len(data_devices) == 1 and \
58 not db_devices and \
59 not wal_devices:
60 cmd = "lvm prepare --bluestore --data %s --no-systemd" % (' '.join(data_devices))
1911f103
TL
61 if self.osd_id_claims:
62 cmd += " --osd-id {}".format(str(self.osd_id_claims[0]))
63 if self.preview:
64 # Like every horrible hack, this has sideffects on other features.
65 # In this case, 'lvm prepare' has neither a '--report' nor a '--format json' option
66 # which essentially doesn't allow for a proper previews here.
67 # Fall back to lvm batch in order to get a preview.
68 return f"lvm batch --no-auto {' '.join(data_devices)} --report --format json"
9f95a23c
TL
69 return cmd
70
71 if self.spec.objectstore == 'bluestore':
72
73 cmd = "lvm batch --no-auto {}".format(" ".join(data_devices))
74
75 if db_devices:
76 cmd += " --db-devices {}".format(" ".join(db_devices))
77
78 if wal_devices:
79 cmd += " --wal-devices {}".format(" ".join(wal_devices))
80
81 if self.spec.block_wal_size:
82 cmd += " --block-wal-size {}".format(self.spec.block_wal_size)
83
84 if self.spec.block_db_size:
85 cmd += " --block-db-size {}".format(self.spec.block_db_size)
86
87 if self.spec.encrypted:
88 cmd += " --dmcrypt"
89
90 if self.spec.osds_per_device:
91 cmd += " --osds-per-device {}".format(self.spec.osds_per_device)
92
1911f103
TL
93 if self.osd_id_claims:
94 cmd += " --osd-ids {}".format(" ".join(self.osd_id_claims))
95
9f95a23c
TL
96 cmd += " --yes"
97 cmd += " --no-systemd"
98
1911f103
TL
99 if self.preview:
100 cmd += " --report"
101 cmd += " --format json"
102
9f95a23c 103 return cmd