7
from charmhelpers.contrib.storage.linux.ceph import validator, \
8
erasure_profile_exists, ErasurePool, set_pool_quota, \
9
pool_set, snapshot_pool, remove_pool_snapshot, create_erasure_profile, \
10
ReplicatedPool, rename_pool, Pool, get_osds, pool_exists, delete_pool
12
7
from charmhelpers.core.hookenv import (
13
from charmhelpers.contrib.storage.linux.ceph import (
14
create_erasure_profile,
16
erasure_profile_exists,
19
30
# This comes from http://docs.ceph.com/docs/master/rados/operations/pools/
20
31
# This should do a decent job of preventing people from passing in bad values.
141
153
# TODO: Default to 3/2 erasure coding. I believe this requires min 5 osds
142
154
if not erasure_profile_exists(service=service, name=erasure_profile):
143
155
# TODO: Fail and tell them to create the profile or default
144
msg = "erasure-profile {} does not exist. Please create it with: " \
145
"create-erasure-profile".format(erasure_profile)
156
msg = ("erasure-profile {} does not exist. Please create it with: "
157
"create-erasure-profile".format(erasure_profile))
146
158
log(msg, level=ERROR)
147
159
return {'exit-code': 1, 'stderr': msg}
149
161
pool = ErasurePool(service=service, name=pool_name,
150
162
erasure_code_profile=erasure_profile)
151
163
# Ok make the erasure pool
152
164
if not pool_exists(service=service, name=pool_name):
153
log("Creating pool '%s' (erasure_profile=%s)" % (pool,
165
log("Creating pool '%s' (erasure_profile=%s)" % (pool.name,
154
166
erasure_profile),
184
196
replicas=replicas,
186
198
if not pool_exists(service=service, name=pool_name):
187
log("Creating pool '%s' (replicas=%s)" % (pool, replicas),
199
log("Creating pool '%s' (replicas=%s)" % (pool.name, replicas),
191
log("Pool '%s' already exists - skipping create" % pool,
203
log("Pool '%s' already exists - skipping create" % pool.name,
194
206
# Set a quota if requested
208
220
# cache and storage pool must exist first
209
221
if not pool_exists(service=service, name=storage_pool) or not pool_exists(
210
222
service=service, name=cache_pool):
211
msg = "cold-pool: {} and hot-pool: {} must exist. Please create " \
212
"them first".format(storage_pool, cache_pool)
223
msg = ("cold-pool: {} and hot-pool: {} must exist. Please create "
224
"them first".format(storage_pool, cache_pool))
213
225
log(msg, level=ERROR)
214
226
return {'exit-code': 1, 'stderr': msg}
215
228
p = Pool(service=service, name=storage_pool)
216
229
p.add_cache_tier(cache_pool=cache_pool, mode=cache_mode)
222
235
# cache and storage pool must exist first
223
236
if not pool_exists(service=service, name=storage_pool) or not pool_exists(
224
237
service=service, name=cache_pool):
225
msg = "cold-pool: {} or hot-pool: {} doesn't exist. Not " \
226
"deleting cache tier".format(storage_pool, cache_pool)
238
msg = ("cold-pool: {} or hot-pool: {} doesn't exist. Not "
239
"deleting cache tier".format(storage_pool, cache_pool))
227
240
log(msg, level=ERROR)
228
241
return {'exit-code': 1, 'stderr': msg}
276
291
# Default to replicated if pool_type isn't given
277
292
if pool_type == 'erasure':
278
handle_erasure_pool(request=req, service=svc)
293
ret = handle_erasure_pool(request=req, service=svc)
280
handle_replicated_pool(request=req, service=svc)
295
ret = handle_replicated_pool(request=req, service=svc)
281
297
elif op == "create-cache-tier":
282
handle_create_cache_tier(request=req, service=svc)
298
ret = handle_create_cache_tier(request=req, service=svc)
283
299
elif op == "remove-cache-tier":
284
handle_remove_cache_tier(request=req, service=svc)
300
ret = handle_remove_cache_tier(request=req, service=svc)
285
301
elif op == "create-erasure-profile":
286
handle_create_erasure_profile(request=req, service=svc)
302
ret = handle_create_erasure_profile(request=req, service=svc)
287
303
elif op == "delete-pool":
288
304
pool = req.get('name')
289
delete_pool(service=svc, name=pool)
305
ret = delete_pool(service=svc, name=pool)
290
306
elif op == "rename-pool":
291
307
old_name = req.get('name')
292
308
new_name = req.get('new-name')
293
rename_pool(service=svc, old_name=old_name, new_name=new_name)
309
ret = rename_pool(service=svc, old_name=old_name,
294
311
elif op == "snapshot-pool":
295
312
pool = req.get('name')
296
313
snapshot_name = req.get('snapshot-name')
297
snapshot_pool(service=svc, pool_name=pool,
298
snapshot_name=snapshot_name)
314
ret = snapshot_pool(service=svc, pool_name=pool,
315
snapshot_name=snapshot_name)
299
316
elif op == "remove-pool-snapshot":
300
317
pool = req.get('name')
301
318
snapshot_name = req.get('snapshot-name')
302
remove_pool_snapshot(service=svc, pool_name=pool,
303
snapshot_name=snapshot_name)
319
ret = remove_pool_snapshot(service=svc, pool_name=pool,
320
snapshot_name=snapshot_name)
304
321
elif op == "set-pool-value":
305
handle_set_pool_value(request=req, service=svc)
322
ret = handle_set_pool_value(request=req, service=svc)
307
324
msg = "Unknown operation '%s'" % op
308
325
log(msg, level=ERROR)
309
326
return {'exit-code': 1, 'stderr': msg}
328
if type(ret) == dict and 'exit-code' in ret:
311
331
return {'exit-code': 0}