From 5edaa385abddbee40f4f1fd048a8e692d9dd405f Mon Sep 17 00:00:00 2001 From: Martin Magr Date: Thu, 17 Jan 2013 20:34:00 +0100 Subject: [PATCH] Solved second use case of bug #890822 bug/890822 Change-Id: If8ac4dd7540400b38a65fcb0419beab70ff55029 --- packstack/installer/engine_processors.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packstack/installer/engine_processors.py b/packstack/installer/engine_processors.py index 61615ec7b..8c696aac0 100644 --- a/packstack/installer/engine_processors.py +++ b/packstack/installer/engine_processors.py @@ -22,12 +22,22 @@ def processHost(param, process_args=None): raise ParamProcessingError(str(ex)) def processSSHKey(param, process_args=None): + """ + Generates SSH key if given key in param doesn't exist. In case param + is an empty string it generates default SSH key ($HOME/.ssh/id_rsa). + """ + def create_key(path): + local = ScriptRunner() + # create new ssh key + local.append('ssh-keygen -f %s -N ""' % path) + local.execute() + if not param: key_file = '%s/.ssh/id_rsa' % os.environ["HOME"] param = '%s.pub' % key_file if not os.path.isfile(param): - local = ScriptRunner() - # create new ssh key - local.append('ssh-keygen -f %s -N ""' % key_file) - local.execute() + create_key(key_file) + elif not os.path.isfile(param): + key_file = param.endswith('.pub') and param[:-4] or param + create_key(key_file) return param