Skip to content

Commit

Permalink
refactor(manager): refactor ScyllaManagerTool.add_cluster function
Browse files Browse the repository at this point in the history
Changes:
- Updated docstring to contain relevant information about cluster add
command `sctool cluster add`. Removed the part that describes command
flags which can be retrieved from official docs (links attached).
- Removed useless or added some extra empty lines to improve code
readability.
- Removed `client_encrypt` condition from client encryption 'if-else'
block since its duplication.
  • Loading branch information
mikliapko authored and soyacz committed Jan 31, 2025
1 parent e3e5fe3 commit 9518705
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions sdcm/mgmt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,33 +1053,19 @@ def add_cluster(self, name, host=None, db_cluster=None, client_encrypt=None, dis
Add a cluster to manager
Usage:
sctool cluster add [flags]
Flags:
-h, --help help for add
--host string hostname or IP of one of the cluster nodes
-n, --name alias alias you can give to your cluster
--ssl-user-cert-file path path to client certificate when using client/server encryption with require_client_auth enabled
--ssl-user-key-file path path to key associated with ssl-user-cert-file
Global Flags:
--api-url URL URL of Scylla Manager server (default "https://127.0.0.1:5443/api/v1")
-c, --cluster name target cluster name or ID
sctool cluster add --host <IP> [--name <alias>] [--auth-token <token>] [flags]
Scylla Docs:
https://docs.scylladb.com/operating-scylla/manager/1.4/add-a-cluster/
https://docs.scylladb.com/operating-scylla/manager/1.4/sctool/#cluster-add
https://manager.docs.scylladb.com/stable/add-a-cluster.html
https://manager.docs.scylladb.com/stable/sctool#cluster-add
"""
# pylint: disable=too-many-locals

if not any([host, db_cluster]):
raise ScyllaManagerError("Neither host or db_cluster parameter were given to Manager add_cluster")

host = host or self.get_cluster_hosts_ip(db_cluster=db_cluster)[0]
# FIXME: if cluster already added, print a warning, but not fail
cmd = 'cluster add --host={} --name={} --auth-token {}'.format(
host, name, auth_token)

cmd = 'cluster add --host {} --name {} --auth-token {}'.format(host, name, auth_token)

if force_non_ssl_session_port:
cmd += " --force-non-ssl-session-port"
Expand All @@ -1091,17 +1077,20 @@ def add_cluster(self, name, host=None, db_cluster=None, client_encrypt=None, dis
"fail since not using client-encryption parameters.")
else: # check if scylla-node has client-encrypt
db_node, _ip = self.get_cluster_hosts_with_ips(db_cluster=db_cluster)[0]
if client_encrypt or db_node.is_client_encrypt:
if db_node.is_client_encrypt:
cmd += " --ssl-user-cert-file {} --ssl-user-key-file {}".format(SSL_USER_CERT_FILE,
SSL_USER_KEY_FILE)

if credentials:
username, password = credentials
cmd += f" --username {username} --password {password}"

res_cluster_add = self.sctool.run(cmd, parse_table_res=False)
if not res_cluster_add or 'Cluster added' not in res_cluster_add.stderr:
raise ScyllaManagerError("Encountered an error on 'sctool cluster add' command response: {}".format(
res_cluster_add))
cluster_id = res_cluster_add.stdout.split('\n')[0]

# return ManagerCluster instance with the manager's new cluster-id
manager_cluster = self.clusterClass(manager_node=self.manager_node, cluster_id=cluster_id,
client_encrypt=client_encrypt)
Expand Down

0 comments on commit 9518705

Please sign in to comment.