1313# TODO refactor this to a DriveSelection method
1414class to_ceph_volume (object ):
1515
16- _supported_device_classes = [
17- "hdd" , "ssd" , "nvme"
18- ]
16+ NO_CRUSH = '_NO_CRUSH'
1917
2018 def __init__ (self ,
2119 selection , # type: DriveSelection
@@ -34,20 +32,6 @@ def prepare_devices(self):
3432
3533 lvcount : Dict [str , List [str ]] = dict ()
3634
37- """
38- Default entry for the global crush_device_class definition;
39- if there's no global definition at spec level, we do not want
40- to apply anything to the provided devices, hence we need to run
41- a ceph-volume command without that option, otherwise we init an
42- entry for the globally defined crush_device_class.
43- """
44- if self .spec .crush_device_class :
45- lvcount [self .spec .crush_device_class ] = []
46-
47- # entry where the drives that don't require a crush_device_class
48- # option are collected
49- lvcount ["no_crush" ] = []
50-
5135 """
5236 for each device, check if it's just a path or it has a crush_device
5337 class definition, and append an entry to the right crush_device_
@@ -57,35 +41,16 @@ class group
5741 # iterate on List[Device], containing both path and
5842 # crush_device_class
5943 path = device .path
60- crush_device_class = device .crush_device_class
44+ crush_device_class = (
45+ device .crush_device_class
46+ or self .spec .crush_device_class
47+ or self .NO_CRUSH
48+ )
6149
6250 if path is None :
6351 raise ValueError ("Device path can't be empty" )
6452
65- """
66- if crush_device_class is specified for the current Device path
67- we should either init the array for this group or append the
68- drive path to the existing entry
69- """
70- if crush_device_class :
71- if crush_device_class in lvcount .keys ():
72- lvcount [crush_device_class ].append (path )
73- else :
74- lvcount [crush_device_class ] = [path ]
75- continue
76-
77- """
78- if no crush_device_class is specified for the current path
79- but a global definition is present in the spec, so we group
80- the drives together
81- """
82- if crush_device_class is None and self .spec .crush_device_class :
83- lvcount [self .spec .crush_device_class ].append (path )
84- continue
85- else :
86- # default use case
87- lvcount ["no_crush" ].append (path )
88- continue
53+ lvcount .setdefault (crush_device_class , []).append (path )
8954
9055 return lvcount
9156
@@ -136,7 +101,7 @@ def run(self):
136101 cmd += " --block.db {}" .format (db_devices .pop ())
137102 if wal_devices :
138103 cmd += " --block.wal {}" .format (wal_devices .pop ())
139- if d in self ._supported_device_classes :
104+ if d != self .NO_CRUSH :
140105 cmd += " --crush-device-class {}" .format (d )
141106
142107 cmds .append (cmd )
@@ -159,7 +124,7 @@ def run(self):
159124 if self .spec .block_db_size :
160125 cmd += " --block-db-size {}" .format (self .spec .block_db_size )
161126
162- if d in self ._supported_device_classes :
127+ if d != self .NO_CRUSH :
163128 cmd += " --crush-device-class {}" .format (d )
164129 cmds .append (cmd )
165130
@@ -180,17 +145,6 @@ def run(self):
180145 cmds [i ] += " --yes"
181146 cmds [i ] += " --no-systemd"
182147
183- # set the --crush-device-class option when:
184- # - crush_device_class is specified at spec level (global for all the osds) # noqa E501
185- # - crush_device_class is allowed
186- # - there's no override at osd level
187- if (
188- self .spec .crush_device_class and
189- self .spec .crush_device_class in self ._supported_device_classes and # noqa E501
190- "crush-device-class" not in cmds [i ]
191- ):
192- cmds [i ] += " --crush-device-class {}" .format (self .spec .crush_device_class ) # noqa E501
193-
194148 if self .preview :
195149 cmds [i ] += " --report"
196150 cmds [i ] += " --format json"
0 commit comments