summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster
diff options
context:
space:
mode:
authorKotresh HR <khiremat@redhat.com>2018-06-21 01:46:37 -0400
committerKotresh HR <khiremat@redhat.com>2018-06-22 07:25:20 +0000
commit0a4740373aa6aa5f4a936daf8c2858fb6a1b5401 (patch)
treed26c39bac5b2fd7a08bde3336829e42d467f4c41 /glustolibs-gluster/glustolibs/gluster
parent5a58de6d56e37fe38b8b89e9a29ae0668d648a94 (diff)
geo-rep/ops: Setup passwordless SSH
1. API to generate ssh keygen 2. API to copy ssh key on to remote node Change-Id: I0b89ce9d77d4a16eaa3ad10f646d412f1190f56e Signed-off-by: Kotresh HR <khiremat@redhat.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py b/glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py
index 0252db4ad..aa89f19de 100644
--- a/glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py
+++ b/glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py
@@ -65,6 +65,47 @@ def georep_createpem(mnode):
return g.run(mnode, cmd)
+def georep_ssh_keygen(mnode):
+ """ Creates a pair of ssh private and public key if not present
+
+ Args:
+ mnode (str): Node on which cmd is to be executed
+ Returns:
+ bool : True if ssh-keygen is successful on all servers.
+ False otherwise. It also returns True if ssh key
+ is already present
+
+ """
+ cmd = 'echo -e "n" | ssh-keygen -f ~/.ssh/id_rsa -q -N ""'
+ ret, out, _ = g.run(mnode, cmd)
+ if ret and "already exists" not in out:
+ return False
+ return True
+
+
+def georep_ssh_copyid(mnode, tonode, user, passwd):
+ """ Copies the default ssh public key onto tonode's
+ authorized_keys file
+
+ Args:
+ mnode (str): Node on which cmd is to be executed
+ tonode (str): Node to which ssh key is to be copied
+ user (str): user of tonode
+ passwd (str): passwd of the user of tonode
+ Returns:
+ bool : True if ssh-copy-id is successful to tonode.
+ False otherwise. It also returns True if ssh key
+ is already present
+
+ """
+ cmd = ('sshpass -p "%s" ssh-copy-id -o StrictHostKeyChecking=no %s@%s' %
+ (passwd, user, tonode))
+ ret, _, _ = g.run(mnode, cmd)
+ if ret:
+ return False
+ return True
+
+
def georep_groupadd(servers, groupname):
""" Creates a group in all the slave nodes where a user will be added
to set up a non-root session