From 0a4740373aa6aa5f4a936daf8c2858fb6a1b5401 Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Thu, 21 Jun 2018 01:46:37 -0400 Subject: 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 --- .../glustolibs/gluster/geo_rep_ops.py | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py') 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 -- cgit