Get rid of ssconf and convert to configuration instead.
---
lib/backend.py | 2 +-
lib/bootstrap.py | 5 +++--
lib/cmdlib.py | 2 +-
lib/ssh.py | 14 +++++---------
scripts/gnt-cluster | 10 ++++++++--
test/ganeti.ssh_unittest.py | 5 ++---
test/mocks.py | 3 ---
7 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/lib/backend.py b/lib/backend.py
index 07deb20..b9ad917 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -49,7 +49,7 @@ def _GetConfig():
def _GetSshRunner():
- return ssh.SshRunner()
+ return ssh.SshRunner(_GetConfig())
def _CleanDirectory(path, exclude=[]):
diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 16ec8c9..e1fdab2 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -243,7 +243,7 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix,
def_bridge,
cfg = config.ConfigWriter()
cfg.InitConfig(constants.CONFIG_VERSION, cluster_config, master_node_config)
- ssh.WriteKnownHostsFile(cfg, ss, constants.SSH_KNOWN_HOSTS_FILE)
+ ssh.WriteKnownHostsFile(cfg, constants.SSH_KNOWN_HOSTS_FILE)
# start the master ip
# TODO: Review rpc call from bootstrap
@@ -274,8 +274,9 @@ def SetupNodeDaemon(node, ssh_key_check):
node: fully qualified domain name for the new node
"""
+ cfg = simpleconfig.SimpleConfigReader()
+ sshrunner = ssh.SshRunner(cfg)
ss = ssconf.SimpleStore()
- sshrunner = ssh.SshRunner(ss)
gntpass = ss.GetNodeDaemonPassword()
if not re.match('^[a-zA-Z0-9.]{1,64}$', gntpass):
raise errors.OpExecError("ganeti password corruption detected")
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index a8b0bcb..dc660c6 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -111,7 +111,7 @@ class LogicalUnit(object):
"""
if not self.__ssh:
- self.__ssh = ssh.SshRunner(self.sstore)
+ self.__ssh = ssh.SshRunner(self.cfg)
return self.__ssh
ssh = property(fget=__GetSSH)
diff --git a/lib/ssh.py b/lib/ssh.py
index 7d314e2..c9cc180 100644
--- a/lib/ssh.py
+++ b/lib/ssh.py
@@ -30,7 +30,6 @@ from ganeti import logger
from ganeti import utils
from ganeti import errors
from ganeti import constants
-from ganeti import ssconf
def GetUserFiles(user, mkdir=False):
@@ -72,11 +71,8 @@ class SshRunner:
"""Wrapper for SSH commands.
"""
- def __init__(self, sstore=None):
- if sstore is None:
- self.sstore = ssconf.SimpleStore()
- else:
- self.sstore = sstore
+ def __init__(self, cfg):
+ self.cfg = cfg
def _BuildSshOptions(self, batch, ask_key, use_cluster_key,
strict_host_check):
@@ -88,7 +84,7 @@ class SshRunner:
]
if use_cluster_key:
- options.append("-oHostKeyAlias=%s" % self.sstore.GetClusterName())
+ options.append("-oHostKeyAlias=%s" % self.cfg.GetClusterName())
# TODO: Too many boolean options, maybe convert them to more descriptive
# constants.
@@ -224,10 +220,10 @@ class SshRunner:
return True, "host matches"
-def WriteKnownHostsFile(cfg, sstore, file_name):
+def WriteKnownHostsFile(cfg, file_name):
"""Writes the cluster-wide equally known_hosts file.
"""
utils.WriteFile(file_name, mode=0700,
- data="%s ssh-rsa %s\n" % (sstore.GetClusterName(),
+ data="%s ssh-rsa %s\n" % (cfg.GetClusterName(),
cfg.GetHostKey()))
diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster
index 31e6425..4f11d11 100755
--- a/scripts/gnt-cluster
+++ b/scripts/gnt-cluster
@@ -31,6 +31,7 @@ from ganeti import errors
from ganeti import utils
from ganeti import bootstrap
from ganeti import ssh
+from ganeti import simpleconfig
from ganeti import ssconf
@@ -161,6 +162,8 @@ def ClusterCopyFile(opts, args):
nodes - list containing the name of target nodes; if empty, all nodes
"""
+ cfg = simpleconfig.SimpleConfigReader()
+
filename = args[0]
if not os.path.exists(filename):
raise errors.OpPrereqError("No such filename '%s'" % filename)
@@ -169,7 +172,7 @@ def ClusterCopyFile(opts, args):
op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes)
results = [row[0] for row in SubmitOpCode(op) if row[0] != myname]
- srun = ssh.SshRunner()
+ srun = ssh.SshRunner(cfg)
for node in results:
if not srun.CopyFileToNode(node, filename):
print >> sys.stderr, ("Copy of file %s to node %s failed" %
@@ -188,14 +191,17 @@ def RunClusterCommand(opts, args):
nodes: list containing the name of target nodes; if empty, all nodes
"""
+ cfg = simpleconfig.SimpleConfigReader()
+
command = " ".join(args)
op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes)
nodes = [row[0] for row in SubmitOpCode(op)]
sstore = ssconf.SimpleStore()
master_node = sstore.GetMasterNode()
- srun = ssh.SshRunner(sstore=sstore)
+ srun = ssh.SshRunner(cfg)
+ # Make sure master node is at list end
if master_node in nodes:
nodes.remove(master_node)
nodes.append(master_node)
diff --git a/test/ganeti.ssh_unittest.py b/test/ganeti.ssh_unittest.py
index ac5821e..2121355 100755
--- a/test/ganeti.ssh_unittest.py
+++ b/test/ganeti.ssh_unittest.py
@@ -41,10 +41,9 @@ class TestKnownHosts(testutils.GanetiTestCase):
def test(self):
cfg = mocks.FakeConfig()
- sstore = mocks.FakeSStore()
- ssh.WriteKnownHostsFile(cfg, sstore, self.tmpfile.name)
+ ssh.WriteKnownHostsFile(cfg, self.tmpfile.name)
self.assertFileContent(self.tmpfile.name,
- "%s ssh-rsa %s\n" % (sstore.GetClusterName(),
+ "%s ssh-rsa %s\n" % (cfg.GetClusterName(),
mocks.FAKE_CLUSTER_KEY))
diff --git a/test/mocks.py b/test/mocks.py
index c611285..dfc1b11 100644
--- a/test/mocks.py
+++ b/test/mocks.py
@@ -58,9 +58,6 @@ class FakeConfig:
class FakeSStore:
"""Fake simplestore object"""
- def GetClusterName(self):
- return "test.cluster"
-
def GetMasterNode(self):
return utils.HostInfo().name
--
1.6.0.2