def handle_create_cache_tier(request, service): """Create a cache tier on a cold pool. Modes supported are "writeback" and "readonly". :param request: dict of request operations and params :param service: The ceph client to run the command under. :returns: dict. exit-code and reason if not 0 """ # mode = "writeback" | "readonly" storage_pool = request.get('cold-pool') cache_pool = request.get('hot-pool') cache_mode = request.get('mode') if cache_mode is None: cache_mode = "writeback" # cache and storage pool must exist first if not pool_exists(service=service, name=storage_pool) or not pool_exists( service=service, name=cache_pool): msg = ("cold-pool: {} and hot-pool: {} must exist. Please create " "them first".format(storage_pool, cache_pool)) log(msg, level=ERROR) return {'exit-code': 1, 'stderr': msg} p = BasePool(service=service, name=storage_pool) p.add_cache_tier(cache_pool=cache_pool, mode=cache_mode)
def handle_remove_cache_tier(request, service): """Remove a cache tier from the cold pool. :param request: dict of request operations and params :param service: The ceph client to run the command under. :returns: dict. exit-code and reason if not 0 """ storage_pool = request.get('cold-pool') cache_pool = request.get('hot-pool') # cache and storage pool must exist first if not pool_exists(service=service, name=storage_pool) or not pool_exists( service=service, name=cache_pool): msg = ("cold-pool: {} or hot-pool: {} doesn't exist. Not " "deleting cache tier".format(storage_pool, cache_pool)) log(msg, level=ERROR) return {'exit-code': 1, 'stderr': msg} pool = BasePool(name=storage_pool, service=service) pool.remove_cache_tier(cache_pool=cache_pool)