LGTM
On Tue, Sep 02, 2014 at 04:19:27PM +0200, 'Helga Velroyen' via ganeti-devel
wrote:
Since the generation of SSH keys will no longer only
happen at cluster init, but every time a node is added,
we move the "InitSSH" method from bootstrap to the
ssh module to be able to reuse it. No functional
changes otherwise.
Signed-off-by: Helga Velroyen <[email protected]>
---
lib/bootstrap.py | 26 +-------------------------
lib/ssh.py | 26 +++++++++++++++++++++++++-
2 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 88ae71e..e8c5a4c 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -58,30 +58,6 @@ _INITCONF_ECID = "initconfig-ecid"
_DAEMON_READY_TIMEOUT = 10.0
-def _InitSSHSetup():
- """Setup the SSH configuration for the cluster.
-
- This generates a dsa keypair for root, adds the pub key to the
- permitted hosts and adds the hostkey to its own known hosts.
-
- """
- priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.SSH_LOGIN_USER)
-
- for name in priv_key, pub_key:
- if os.path.exists(name):
- utils.CreateBackup(name)
- utils.RemoveFile(name)
-
- result = utils.RunCmd(["ssh-keygen", "-t", "dsa",
- "-f", priv_key,
- "-q", "-N", ""])
- if result.failed:
- raise errors.OpExecError("Could not generate ssh keypair, error %s" %
- result.output)
-
- utils.AddAuthorizedKey(auth_keys, utils.ReadFile(pub_key))
-
-
def GenerateHmacKey(file_name):
"""Writes a new HMAC key.
@@ -781,7 +757,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint:
disable=R0913, R0914
utils.AddHostToEtcHosts(hostname.name, hostname.ip)
if modify_ssh_setup:
- _InitSSHSetup()
+ ssh.InitSSHSetup()
if default_iallocator is not None:
alloc_script = utils.FindFile(default_iallocator,
diff --git a/lib/ssh.py b/lib/ssh.py
index 481f680..677c2e4 100644
--- a/lib/ssh.py
+++ b/lib/ssh.py
@@ -106,7 +106,31 @@ def GetAllUserFiles(user, mkdir=False, dircheck=True,
_homedir_fn=None):
for (kind, (privkey, pubkey, _)) in result))
-class SshRunner(object):
+def InitSSHSetup(error_fn=errors.OpPrereqError):
+ """Setup the SSH configuration for the node.
+
+ This generates a dsa keypair for root, adds the pub key to the
+ permitted hosts and adds the hostkey to its own known hosts.
+
+ """
+ priv_key, pub_key, auth_keys = GetUserFiles(constants.SSH_LOGIN_USER)
+
+ for name in priv_key, pub_key:
+ if os.path.exists(name):
+ utils.CreateBackup(name)
+ utils.RemoveFile(name)
+
+ result = utils.RunCmd(["ssh-keygen", "-t", "dsa",
+ "-f", priv_key,
+ "-q", "-N", ""])
+ if result.failed:
+ raise error_fn("Could not generate ssh keypair, error %s" %
+ result.output)
+
+ utils.AddAuthorizedKey(auth_keys, utils.ReadFile(pub_key))
+
+
+class SshRunner:
"""Wrapper for SSH commands.
"""
--
2.1.0.rc2.206.gedb03e5