def process_requests_v1(reqs): """Process v1 requests. Takes a list of requests (dicts) and processes each one. If an error is found, processing stops and the client is notified in the response. Returns a response dict containing the exit code (non-zero if any operation failed along with an explanation). """ log("Processing %s ceph broker requests" % (len(reqs)), level=INFO) for req in reqs: op = req.get('op') log("Processing op='%s'" % op, level=DEBUG) # Use admin client since we do not have other client key locations # setup to use them for these operations. svc = 'admin' if op == "create-pool": pool_type = req.get('pool-type') # "replicated" | "erasure" # Default to replicated if pool_type isn't given if pool_type == 'erasure': handle_erasure_pool(request=req, service=svc) else: handle_replicated_pool(request=req, service=svc) elif op == "create-cache-tier": handle_create_cache_tier(request=req, service=svc) elif op == "remove-cache-tier": handle_remove_cache_tier(request=req, service=svc) elif op == "create-erasure-profile": handle_create_erasure_profile(request=req, service=svc) elif op == "delete-pool": pool = req.get('name') delete_pool(service=svc, name=pool) elif op == "rename-pool": old_name = req.get('name') new_name = req.get('new-name') rename_pool(service=svc, old_name=old_name, new_name=new_name) elif op == "snapshot-pool": pool = req.get('name') snapshot_name = req.get('snapshot-name') snapshot_pool(service=svc, pool_name=pool, snapshot_name=snapshot_name) elif op == "remove-pool-snapshot": pool = req.get('name') snapshot_name = req.get('snapshot-name') remove_pool_snapshot(service=svc, pool_name=pool, snapshot_name=snapshot_name) elif op == "set-pool-value": handle_set_pool_value(request=req, service=svc) else: msg = "Unknown operation '%s'" % op log(msg, level=ERROR) return {'exit-code': 1, 'stderr': msg} return {'exit-code': 0}
def snapshot_ceph_pool(): """ Snapshots a Ceph pool. Snapshots the pool provided in action parameter 'name' and uses the parameter provided in the action parameter 'snapshot-name' as the name for the snapshot. """ pool_name = action_get("name") snapshot_name = action_get("snapshot-name") snapshot_pool(service='ceph', pool_name=pool_name, snapshot_name=snapshot_name)
def process_requests_v1(reqs): """Process v1 requests. Takes a list of requests (dicts) and processes each one. If an error is found, processing stops and the client is notified in the response. Returns a response dict containing the exit code (non-zero if any operation failed along with an explanation). """ ret = None log("Processing {} ceph broker requests".format(len(reqs)), level=INFO) for req in reqs: op = req.get('op') log("Processing op='{}'".format(op), level=DEBUG) # Use admin client since we do not have other client key locations # setup to use them for these operations. svc = 'admin' if op == "create-pool": pool_type = req.get('pool-type') # "replicated" | "erasure" # Default to replicated if pool_type isn't given if pool_type == 'erasure': ret = handle_erasure_pool(request=req, service=svc) else: ret = handle_replicated_pool(request=req, service=svc) elif op == "create-cephfs": ret = handle_create_cephfs(request=req, service=svc) elif op == "create-cache-tier": ret = handle_create_cache_tier(request=req, service=svc) elif op == "remove-cache-tier": ret = handle_remove_cache_tier(request=req, service=svc) elif op == "create-erasure-profile": ret = handle_create_erasure_profile(request=req, service=svc) elif op == "delete-pool": pool = req.get('name') ret = delete_pool(service=svc, name=pool) elif op == "rename-pool": old_name = req.get('name') new_name = req.get('new-name') ret = rename_pool(service=svc, old_name=old_name, new_name=new_name) elif op == "snapshot-pool": pool = req.get('name') snapshot_name = req.get('snapshot-name') ret = snapshot_pool(service=svc, pool_name=pool, snapshot_name=snapshot_name) elif op == "remove-pool-snapshot": pool = req.get('name') snapshot_name = req.get('snapshot-name') ret = remove_pool_snapshot(service=svc, pool_name=pool, snapshot_name=snapshot_name) elif op == "set-pool-value": ret = handle_set_pool_value(request=req, service=svc) elif op == "rgw-region-set": ret = handle_rgw_region_set(request=req, service=svc) elif op == "rgw-zone-set": ret = handle_rgw_zone_set(request=req, service=svc) elif op == "rgw-regionmap-update": ret = handle_rgw_regionmap_update(request=req, service=svc) elif op == "rgw-regionmap-default": ret = handle_rgw_regionmap_default(request=req, service=svc) elif op == "rgw-create-user": ret = handle_rgw_create_user(request=req, service=svc) elif op == "move-osd-to-bucket": ret = handle_put_osd_in_bucket(request=req, service=svc) elif op == "add-permissions-to-key": ret = handle_add_permissions_to_key(request=req, service=svc) else: msg = "Unknown operation '{}'".format(op) log(msg, level=ERROR) return {'exit-code': 1, 'stderr': msg} if type(ret) == dict and 'exit-code' in ret: return ret return {'exit-code': 0}
# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import sys sys.path.append('hooks') from subprocess import CalledProcessError from charmhelpers.core.hookenv import action_get, log, action_fail from charmhelpers.contrib.storage.linux.ceph import snapshot_pool if __name__ == '__main__': name = action_get("pool-name") snapname = action_get("snapshot-name") try: snapshot_pool(service='admin', pool_name=name, snapshot_name=snapname) except CalledProcessError as e: log(e) action_fail("Snapshot pool failed with message: {}".format(e.message))
# # Copyright 2016 Canonical Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import sys sys.path.append('hooks') from subprocess import CalledProcessError from charmhelpers.core.hookenv import action_get, log, action_fail from charmhelpers.contrib.storage.linux.ceph import snapshot_pool if __name__ == '__main__': name = action_get("pool-name") snapname = action_get("snapshot-name") try: snapshot_pool(service='admin', pool_name=name, snapshot_name=snapname) except CalledProcessError as e: log(e) action_fail("Snapshot pool failed with message: {}".format(str(e)))
def snapshot_ceph_pool(): pool_name = action_get("pool-name") snapshot_name = action_get("snapshot-name") snapshot_pool(service='ceph', pool_name=pool_name, snapshot_name=snapshot_name)