Skip to content

Commit 87a831d

Browse files
committed
target node append on cluster json file
1 parent f80f10c commit 87a831d

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

cli/scripts/cluster.py

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,13 +1576,7 @@ def check_source_backrest_config(source_node_data):
15761576
"info"
15771577
)
15781578
else:
1579-
util.message(
1580-
f"Source node '{source_node_data['name']}' does not have a BackRest configuration.",
1581-
"info"
1582-
)
1583-
# Print the source node's path for debugging purposes
1584-
util.message(f"Source node path: {source_node_data['path']}", "info")
1585-
# Remove any leftover BackRest configuration
1579+
15861580
cmd = f"cd {source_node_data['path']}/pgedge && ./pgedge remove backrest"
15871581
run_cmd(cmd, node=source_node_data, message="Removing BackRest configuration from source node", verbose=True)
15881582

@@ -1663,7 +1657,9 @@ def add_node(
16631657
"os_user": os_user,
16641658
"ssh_key": ssh_key,
16651659
}
1666-
1660+
# If backrest settings are provided in the JSON, add them to new_node_data.
1661+
if backrest_info:
1662+
new_node_data["backrest"] = backrest_info
16671663
if "public_ip" not in new_node_data and "private_ip" not in new_node_data:
16681664
util.exit_message(
16691665
"Both public_ip and private_ip are missing in target node data."
@@ -2039,6 +2035,52 @@ def add_node(
20392035
if v4:
20402036
set_cluster_readonly(nodes, False, db[0]["db_name"], f"pg{pg}", v4, verbose)
20412037

2038+
cmd = f'cd {new_node_data["path"]}/pgedge/; ./pgedge spock node-list {db[0]["db_name"]}'
2039+
message = f"Listing spock nodes"
2040+
result = run_cmd(
2041+
cmd, node=new_node_data, message=message, verbose=verbose, capture_output=True
2042+
)
2043+
print(f"\n{result.stdout}")
2044+
2045+
sql_cmd = "select node_id,node_name from spock.node"
2046+
cmd = (
2047+
f"{source_node_data['path']}/pgedge/pgedge psql '{sql_cmd}' {db[0]['db_name']}"
2048+
)
2049+
message = f"List nodes"
2050+
result = run_cmd(
2051+
cmd,
2052+
node=source_node_data,
2053+
message=message,
2054+
verbose=verbose,
2055+
capture_output=True,
2056+
)
2057+
print(f"\n{result.stdout}")
2058+
2059+
for node in nodes:
2060+
sql_cmd = (
2061+
"select sub_id,sub_name,sub_enabled,sub_slot_name,"
2062+
"sub_replication_sets from spock.subscription"
2063+
)
2064+
cmd = f"{node['path']}/pgedge/pgedge psql '{sql_cmd}' {db[0]['db_name']}"
2065+
message = f"List subscriptions"
2066+
result = run_cmd(
2067+
cmd, node=node, message=message, verbose=verbose, capture_output=True
2068+
)
2069+
print(f"\n{result.stdout}")
2070+
2071+
sql_cmd = (
2072+
"select sub_id,sub_name,sub_enabled,sub_slot_name,"
2073+
"sub_replication_sets from spock.subscription"
2074+
)
2075+
cmd = f"{new_node_data['path']}/pgedge/pgedge psql '{sql_cmd}' {db[0]['db_name']}"
2076+
message = f"List subscriptions"
2077+
result = run_cmd(
2078+
cmd, node=new_node_data, message=message, verbose=verbose, capture_output=True
2079+
)
2080+
print(f"\n{result.stdout}")
2081+
2082+
2083+
20422084
# DEBUG: Reload the complete target JSON file and fetch repo1_path and stanza from its backrest settings.
20432085
try:
20442086
with open(target_node_file, "r") as f:
@@ -2179,7 +2221,20 @@ def add_node(
21792221
except Exception as e:
21802222
print(f"Error fetching values from target JSON file: {e}")
21812223
# NEW: Check and display BackRest configuration status in the source node
2224+
# Remove unnecessary keys before appending new node to the cluster data
2225+
new_node_data.pop("ip_address", None)
2226+
new_node_data.pop("os_user", None)
2227+
new_node_data.pop("ssh_key", None)
2228+
2229+
# Append new node data to the cluster JSON
2230+
node_group = target_node_data.get
2231+
cluster_data["node_groups"].append(new_node_data)
2232+
cluster_data["update_date"] = datetime.datetime.now().astimezone().isoformat()
2233+
2234+
write_cluster_json(cluster_name, cluster_data)
2235+
21822236
check_source_backrest_config(source_node_data)
2237+
21832238
def capture_backrest_config(cluster_name, verbose=False):
21842239
"""
21852240
Capture and clean BackRest configuration for all nodes (and sub-nodes) in the cluster

0 commit comments

Comments
 (0)