Skip to content

Commit 0f220bc

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
commands: add ctdb-rados-mutex sambacc subcommand
This command is meant to serve as a direct wrapper around the `ctdb_mutex_ceph_rados_helper` command that "understands" some of the indended container workflow and argument style AND prevent issues in ctdb configuration where the cephx entity names are going to vary. Signed-off-by: John Mulligan <[email protected]>
1 parent 353849a commit 0f220bc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

sambacc/commands/ctdb.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from sambacc import ctdb
2626
from sambacc import jfile
2727
from sambacc import rados_opener
28+
from sambacc import samba_cmds
2829
from sambacc.simple_waiter import Sleeper, Waiter
2930

3031
from .cli import best_waiter, commands, Context, Fail
@@ -366,3 +367,47 @@ def ctdb_must_have_node(ctx: Context) -> None:
366367
ctdb.cluster_meta_to_nodes(
367368
np.cluster_meta(), real_path=np.persistent_path
368369
)
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

Comments
 (0)