Skip to content

Commit 85c10e5

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
sambacc: add cluster_meta_to_nodes function
Add the cluster_meta_to_nodes function that will simply take a clustermeta object as an input and write out a corresponding nodes file for ctdb. Signed-off-by: John Mulligan <[email protected]>
1 parent bc34f14 commit 85c10e5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sambacc/ctdb.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,26 @@ def _node_update(cmeta: ClusterMeta, real_path: str) -> bool:
483483
return True
484484

485485

486+
def cluster_meta_to_nodes(cmeta: ClusterMeta, real_path: str) -> None:
487+
"""Write a nodes file based on the current content of the cluster
488+
metadata."""
489+
with cmeta.open(locked=True) as cmo:
490+
json_data = cmo.load()
491+
nodes = json_data.get("nodes", [])
492+
_logger.info("Found node metadata: %r", nodes)
493+
pnn_max = max(n["pnn"] for n in nodes) + 1 # pnn is zero indexed
494+
ctdb_nodes: list[str] = [""] * pnn_max
495+
for entry in nodes:
496+
pnn = entry["pnn"]
497+
expected_line = _entry_to_node(ctdb_nodes, entry)
498+
ctdb_nodes[pnn] = expected_line
499+
_logger.info("Will write nodes: %s", ctdb_nodes)
500+
with open(real_path, "w") as nffh:
501+
write_nodes_file(nffh, ctdb_nodes)
502+
nffh.flush()
503+
os.fsync(nffh)
504+
505+
486506
def ensure_ctdbd_etc_files(
487507
etc_path: str = ETC_DIR, src_path: str = SHARE_DIR
488508
) -> None:

0 commit comments

Comments
 (0)