Skip to content

Commit 0586eb0

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
sambacc: add ability to write to an open file to cluster_meta_to_nodes
Add the ability to write to an already open file to cluster_meta_to_nodes. This will allow the function to be reused later to emit the nodes list to the stdout. Signed-off-by: John Mulligan <[email protected]>
1 parent 61497ce commit 0586eb0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

sambacc/commands/ctdb.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,7 @@ def ctdb_must_have_node(ctx: Context) -> None:
394394
waiter.wait()
395395
if ctx.cli.write_nodes:
396396
_logger.info("Writing nodes file")
397-
ctdb.cluster_meta_to_nodes(
398-
np.cluster_meta(), real_path=np.persistent_path
399-
)
397+
ctdb.cluster_meta_to_nodes(np.cluster_meta(), dest=np.persistent_path)
400398

401399

402400
def _ctdb_rados_mutex_args(parser: argparse.ArgumentParser) -> None:

sambacc/ctdb.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,16 +481,21 @@ def _node_update(cmeta: ClusterMeta, real_path: str) -> bool:
481481
return True
482482

483483

484-
def cluster_meta_to_nodes(cmeta: ClusterMeta, real_path: str) -> None:
484+
def cluster_meta_to_nodes(
485+
cmeta: ClusterMeta, dest: typing.Union[str, typing.IO]
486+
) -> None:
485487
"""Write a nodes file based on the current content of the cluster
486488
metadata."""
487489
with cmeta.open(locked=True) as cmo:
488490
json_data = cmo.load()
489491
nodes = json_data.get("nodes", [])
490492
_logger.info("Found node metadata: %r", nodes)
491493
ctdb_nodes = _cluster_meta_to_ctdb_nodes(nodes)
492-
_logger.info("Will write nodes: %s", ctdb_nodes)
493-
_save_nodes(real_path, ctdb_nodes)
494+
if isinstance(dest, str):
495+
_logger.info("Will write nodes: %s", ctdb_nodes)
496+
_save_nodes(dest, ctdb_nodes)
497+
else:
498+
write_nodes_file(dest, ctdb_nodes)
494499

495500

496501
def _cluster_meta_to_ctdb_nodes(nodes: list[dict]) -> list[str]:

0 commit comments

Comments
 (0)