|
25 | 25 | from sambacc import ctdb |
26 | 26 | from sambacc import jfile |
27 | 27 | from sambacc import rados_opener |
| 28 | +from sambacc import samba_cmds |
28 | 29 | from sambacc.simple_waiter import Sleeper, Waiter |
29 | 30 |
|
30 | 31 | from .cli import best_waiter, commands, Context, Fail |
@@ -366,3 +367,47 @@ def ctdb_must_have_node(ctx: Context) -> None: |
366 | 367 | ctdb.cluster_meta_to_nodes( |
367 | 368 | np.cluster_meta(), real_path=np.persistent_path |
368 | 369 | ) |
| 370 | + |
| 371 | + |
| 372 | +def _ctdb_rados_mutex_args(parser: argparse.ArgumentParser) -> None: |
| 373 | + parser.add_argument( |
| 374 | + "--cluster-name", |
| 375 | + default="ceph", |
| 376 | + help="Cluster name to pass to mutex lock helper", |
| 377 | + ) |
| 378 | + parser.add_argument( |
| 379 | + "mutex_uri", |
| 380 | + help="RADOS (pesudo) URI value for the object to use as a mutex", |
| 381 | + ) |
| 382 | + |
| 383 | + |
| 384 | +@commands.command(name="ctdb-rados-mutex", arg_func=_ctdb_rados_mutex_args) |
| 385 | +def ctdb_rados_mutex(ctx: Context) -> None: |
| 386 | + """A command to wrap the rados ctdb_mutex_ceph_rados_helper and wrap |
| 387 | + & translate the container's ceph configuration into something |
| 388 | + the helper can understand. |
| 389 | + N.B. Another reason for this command is that ctdb requires the |
| 390 | + `cluster lock` value to be the same on all nodes. |
| 391 | + """ |
| 392 | + if not rados_opener.is_rados_uri(ctx.cli.mutex_uri): |
| 393 | + raise ValueError(f"{ctx.cli.mutex_uri} is not a valid RADOS URI value") |
| 394 | + rinfo = rados_opener.parse_rados_uri(ctx.cli.mutex_uri) |
| 395 | + if rinfo["subtype"] != "object": |
| 396 | + raise ValueError( |
| 397 | + f"{ctx.cli.mutex_uri} is not a RADOS object URI value" |
| 398 | + ) |
| 399 | + pool, namespace, objname = rinfo["pool"], rinfo["ns"], rinfo["key"] |
| 400 | + entity = ctx.cli.ceph_id["client_name"] |
| 401 | + if not entity: |
| 402 | + raise ValueError("a ceph authentication entity name is required") |
| 403 | + if not ctx.cli.ceph_id["full_name"]: |
| 404 | + entity = f"client.{entity}" |
| 405 | + # required arguments |
| 406 | + cmd = samba_cmds.ctdb_mutex_ceph_rados_helper[ |
| 407 | + ctx.cli.cluster_name, entity, pool, objname # cephx entity |
| 408 | + ] |
| 409 | + # optional namespace argument |
| 410 | + if namespace: |
| 411 | + cmd = cmd["-n", namespace] |
| 412 | + _logger.debug("executing command: %r", cmd) |
| 413 | + samba_cmds.execute(cmd) # replaces process |
0 commit comments