Commit 7688d0d3 authored by Michael Hanselmann's avatar Michael Hanselmann

Convert ssh.py

Get rid of ssconf and convert to configuration instead.

Reviewed-by: iustinp
parent eb1328a9
......@@ -49,7 +49,7 @@ def _GetConfig():
def _GetSshRunner():
return ssh.SshRunner()
return ssh.SshRunner(_GetConfig())
def _CleanDirectory(path, exclude=[]):
......
......@@ -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 = ssconf.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")
......
......@@ -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)
......
......@@ -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()))
......@@ -161,6 +161,9 @@ def ClusterCopyFile(opts, args):
nodes - list containing the name of target nodes; if empty, all nodes
"""
# TODO: Query master
cfg = ssconf.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,18 @@ def RunClusterCommand(opts, args):
nodes: list containing the name of target nodes; if empty, all nodes
"""
# TODO: Query master
cfg = ssconf.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)
......
......@@ -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))
......
......@@ -58,9 +58,6 @@ class FakeConfig:
class FakeSStore:
"""Fake simplestore object"""
def GetClusterName(self):
return "test.cluster"
def GetMasterNode(self):
return utils.HostInfo().name
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment