]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import logging |
2 | ||
3 | try: | |
1911f103 | 4 | from typing import Optional, List |
9f95a23c TL |
5 | except ImportError: |
6 | pass | |
7 | ||
9f95a23c TL |
8 | from ceph.deployment.drive_selection.selector import DriveSelection |
9 | ||
10 | logger = logging.getLogger(__name__) | |
11 | ||
12 | ||
f6b5b4d7 | 13 | # TODO refactor this to a DriveSelection method |
9f95a23c TL |
14 | class 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 = "" |
20effc67 TL |
39 | if self.spec.method == 'raw': |
40 | assert self.spec.objectstore == 'bluestore' | |
41 | cmd = "raw prepare --bluestore" | |
42 | cmd += " --data {}".format(" ".join(data_devices)) | |
43 | if db_devices: | |
44 | cmd += " --block.db {}".format(" ".join(db_devices)) | |
45 | if wal_devices: | |
46 | cmd += " --block.wal {}".format(" ".join(wal_devices)) | |
47 | ||
48 | elif self.spec.objectstore == 'filestore': | |
9f95a23c TL |
49 | cmd = "lvm batch --no-auto" |
50 | ||
51 | cmd += " {}".format(" ".join(data_devices)) | |
52 | ||
53 | if self.spec.journal_size: | |
54 | cmd += " --journal-size {}".format(self.spec.journal_size) | |
55 | ||
56 | if journal_devices: | |
57 | cmd += " --journal-devices {}".format( | |
58 | ' '.join(journal_devices)) | |
59 | ||
60 | cmd += " --filestore" | |
61 | ||
20effc67 | 62 | elif self.spec.objectstore == 'bluestore': |
9f95a23c TL |
63 | |
64 | cmd = "lvm batch --no-auto {}".format(" ".join(data_devices)) | |
65 | ||
66 | if db_devices: | |
67 | cmd += " --db-devices {}".format(" ".join(db_devices)) | |
68 | ||
69 | if wal_devices: | |
70 | cmd += " --wal-devices {}".format(" ".join(wal_devices)) | |
71 | ||
72 | if self.spec.block_wal_size: | |
73 | cmd += " --block-wal-size {}".format(self.spec.block_wal_size) | |
74 | ||
75 | if self.spec.block_db_size: | |
76 | cmd += " --block-db-size {}".format(self.spec.block_db_size) | |
77 | ||
78 | if self.spec.encrypted: | |
79 | cmd += " --dmcrypt" | |
80 | ||
81 | if self.spec.osds_per_device: | |
82 | cmd += " --osds-per-device {}".format(self.spec.osds_per_device) | |
83 | ||
20effc67 TL |
84 | if self.spec.data_allocate_fraction: |
85 | cmd += " --data-allocate-fraction {}".format(self.spec.data_allocate_fraction) | |
86 | ||
1911f103 TL |
87 | if self.osd_id_claims: |
88 | cmd += " --osd-ids {}".format(" ".join(self.osd_id_claims)) | |
89 | ||
20effc67 TL |
90 | if self.spec.method != 'raw': |
91 | cmd += " --yes" | |
92 | cmd += " --no-systemd" | |
9f95a23c | 93 | |
1911f103 TL |
94 | if self.preview: |
95 | cmd += " --report" | |
96 | cmd += " --format json" | |
97 | ||
9f95a23c | 98 | return cmd |