From 3b7c1adf71f5b158ad9f0623abcdfc242ed4e931 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 23 Aug 2019 14:12:15 -0400 Subject: [PATCH] Implement configurable replcfg (client-side) Implements administrator-selectable replication configurations for new pools in PVC clusters, overriding the default of copies=3,mincopies=2. --- client-api/api_lib/pvcapi.py | 4 ++-- client-api/pvc-api.py | 7 +++++++ client-cli/pvc.py | 13 +++++++++++-- client-common/ceph.py | 6 +++--- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/client-api/api_lib/pvcapi.py b/client-api/api_lib/pvcapi.py index c00c098e..a5d512b2 100755 --- a/client-api/api_lib/pvcapi.py +++ b/client-api/api_lib/pvcapi.py @@ -870,12 +870,12 @@ def ceph_pool_list(limit=None): pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode -def ceph_pool_add(name, pgs): +def ceph_pool_add(name, pgs, replcfg): """ Add a Ceph RBD pool to the PVC Ceph storage cluster. """ zk_conn = pvc_common.startZKConnection(config['coordinators']) - retflag, retdata = pvc_ceph.add_pool(zk_conn, name, pgs) + retflag, retdata = pvc_ceph.add_pool(zk_conn, name, pgs, replcfg) if retflag: retcode = 200 else: diff --git a/client-api/pvc-api.py b/client-api/pvc-api.py index 38fd0d05..51e3dde1 100755 --- a/client-api/pvc-api.py +++ b/client-api/pvc-api.py @@ -755,6 +755,13 @@ def api_ceph_pool_root(): # We default to a very small number; DOCUMENT THIS pgs = 128 + # Get replication configuration + if 'replcfg' in flask.request.values: + replcfg = flask.request.values['replcfg'] + else: + # We default to copies=3,mincopies=2 + replcfg = 'copies=3,mincopies=2' + return pvcapi.ceph_pool_add(pool, pgs) @api.route('/api/v1/storage/ceph/pool/', methods=['GET', 'DELETE']) diff --git a/client-cli/pvc.py b/client-cli/pvc.py index 01fdfe3a..bcac4291 100755 --- a/client-cli/pvc.py +++ b/client-cli/pvc.py @@ -1380,13 +1380,22 @@ def ceph_pool(): @click.argument( 'pgs' ) -def ceph_pool_add(name, pgs): +@click.option( + '--replcfg', 'replcfg', + default='copies=3,mincopies=2', show_default=True, required=False, + help=""" + The replication configuration, specifying both a "copies" and "mincopies" value, separated by a + comma, e.g. "copies=3,mincopies=2". The "copies" value specifies the total number of replicas and should not exceed the total number of nodes; the "mincopies" value specifies the minimum number of available copies to allow writes. For additional details please see the Cluster Architecture documentation. + """ +) +def ceph_pool_add(name, pgs, replcfg): """ Add a new Ceph RBD pool with name NAME and PGS placement groups. + """ zk_conn = pvc_common.startZKConnection(zk_host) - retcode, retmsg = pvc_ceph.add_pool(zk_conn, name, pgs) + retcode, retmsg = pvc_ceph.add_pool(zk_conn, name, pgs, replcfg) cleanup(retcode, retmsg, zk_conn) ############################################################################### diff --git a/client-common/ceph.py b/client-common/ceph.py index 463127c1..68848445 100644 --- a/client-common/ceph.py +++ b/client-common/ceph.py @@ -658,9 +658,9 @@ def getPoolInformation(zk_conn, pool): } return pool_information -def add_pool(zk_conn, name, pgs): +def add_pool(zk_conn, name, pgs, replcfg): # Tell the cluster to create a new pool - add_pool_string = 'pool_add {},{}'.format(name, pgs) + add_pool_string = 'pool_add {},{},{}'.format(name, pgs, replcfg) zkhandler.writedata(zk_conn, {'/cmd/ceph': add_pool_string}) # Wait 1/2 second for the cluster to get the message and start working time.sleep(0.5) @@ -670,7 +670,7 @@ def add_pool(zk_conn, name, pgs): try: result = zkhandler.readdata(zk_conn, '/cmd/ceph').split()[0] if result == 'success-pool_add': - message = 'Created new RBD pool "{}" with "{}" PGs.'.format(name, pgs) + message = 'Created new RBD pool "{}" with "{}" PGs and replication configuration {}.'.format(name, pgs, replcfg) success = True else: message = 'ERROR: Failed to create new pool; check node logs for details.'