129
130
An object oriented approach to Ceph pool creation. This base class is inherited by ReplicatedPool and ErasurePool.
130
131
Do not call create() on this base class as it will not do anything. Instantiate a child class and call create().
132
134
def __init__(self, service, name):
133
135
self.service = service
180
182
:return: int. The number of pgs to use.
182
184
validator(value=pool_size, valid_type=int)
183
osds = get_osds(self.service)
185
osd_list = get_osds(self.service)
185
187
# NOTE(james-page): Default to 200 for older ceph versions
186
188
# which don't support OSD query from cli
191
osd_list_length = len(osd_list)
189
192
# Calculate based on Ceph best practices
193
if osd_list_length < 5:
195
elif 5 < osd_list_length < 10:
197
elif 10 < osd_list_length < 50:
197
estimate = (osds * 100) / pool_size
200
estimate = (osd_list_length * 100) / pool_size
198
201
# Return the next nearest power of 2
199
202
index = bisect.bisect_right(powers_of_two, estimate)
200
203
return powers_of_two[index]
203
206
class ReplicatedPool(Pool):
204
def __init__(self, service, name, replicas=2):
207
def __init__(self, service, name, pg_num=None, replicas=2):
205
208
super(ReplicatedPool, self).__init__(service=service, name=name)
206
209
self.replicas = replicas
211
self.pg_num = self.get_pgs(self.replicas)
208
215
def create(self):
209
216
if not pool_exists(self.service, self.name):
211
pgs = self.get_pgs(self.replicas)
212
cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create', self.name, str(pgs)]
218
cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create',
219
self.name, str(self.pg_num)]
215
222
except CalledProcessError:
242
249
pgs = self.get_pgs(int(erasure_profile['k']) + int(erasure_profile['m']))
244
cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create', self.name, str(pgs),
251
cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create', self.name, str(pgs), str(pgs),
245
252
'erasure', self.erasure_code_profile]
322
329
:return: None. Can raise CalledProcessError
324
331
# Set a byte quota on a RADOS pool in ceph.
325
cmd = ['ceph', '--id', service, 'osd', 'pool', 'set-quota', pool_name, 'max_bytes', max_bytes]
332
cmd = ['ceph', '--id', service, 'osd', 'pool', 'set-quota', pool_name,
333
'max_bytes', str(max_bytes)]
328
336
except CalledProcessError:
346
def create_erasure_profile(service, profile_name, erasure_plugin_name='jerasure', failure_domain='host',
354
def remove_erasure_profile(service, profile_name):
356
Create a new erasure code profile if one does not already exist for it. Updates
357
the profile if it exists. Please see http://docs.ceph.com/docs/master/rados/operations/erasure-code-profile/
359
:param service: six.string_types. The Ceph user name to run the command under
360
:param profile_name: six.string_types
361
:return: None. Can raise CalledProcessError
363
cmd = ['ceph', '--id', service, 'osd', 'erasure-code-profile', 'rm',
367
except CalledProcessError:
371
def create_erasure_profile(service, profile_name, erasure_plugin_name='jerasure',
372
failure_domain='host',
347
373
data_chunks=2, coding_chunks=1,
348
374
locality=None, durability_estimator=None):