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

Convert ssh.py

Get rid of ssconf and convert to configuration instead.

Reviewed-by: iustinp
parent eb1328a9
...@@ -49,7 +49,7 @@ def _GetConfig(): ...@@ -49,7 +49,7 @@ def _GetConfig():
def _GetSshRunner(): def _GetSshRunner():
return ssh.SshRunner() return ssh.SshRunner(_GetConfig())
def _CleanDirectory(path, exclude=[]): def _CleanDirectory(path, exclude=[]):
......
...@@ -243,7 +243,7 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge, ...@@ -243,7 +243,7 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge,
cfg = config.ConfigWriter() cfg = config.ConfigWriter()
cfg.InitConfig(constants.CONFIG_VERSION, cluster_config, master_node_config) 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 # start the master ip
# TODO: Review rpc call from bootstrap # TODO: Review rpc call from bootstrap
...@@ -274,8 +274,9 @@ def SetupNodeDaemon(node, ssh_key_check): ...@@ -274,8 +274,9 @@ def SetupNodeDaemon(node, ssh_key_check):
node: fully qualified domain name for the new node node: fully qualified domain name for the new node
""" """
cfg = ssconf.SimpleConfigReader()
sshrunner = ssh.SshRunner(cfg)
ss = ssconf.SimpleStore() ss = ssconf.SimpleStore()
sshrunner = ssh.SshRunner(ss)
gntpass = ss.GetNodeDaemonPassword() gntpass = ss.GetNodeDaemonPassword()
if not re.match('^[a-zA-Z0-9.]{1,64}$', gntpass): if not re.match('^[a-zA-Z0-9.]{1,64}$', gntpass):
raise errors.OpExecError("ganeti password corruption detected") raise errors.OpExecError("ganeti password corruption detected")
......
...@@ -111,7 +111,7 @@ class LogicalUnit(object): ...@@ -111,7 +111,7 @@ class LogicalUnit(object):
""" """
if not self.__ssh: if not self.__ssh:
self.__ssh = ssh.SshRunner(self.sstore) self.__ssh = ssh.SshRunner(self.cfg)
return self.__ssh return self.__ssh
ssh = property(fget=__GetSSH) ssh = property(fget=__GetSSH)
......
...@@ -30,7 +30,6 @@ from ganeti import logger ...@@ -30,7 +30,6 @@ from ganeti import logger
from ganeti import utils from ganeti import utils
from ganeti import errors from ganeti import errors
from ganeti import constants from ganeti import constants
from ganeti import ssconf
def GetUserFiles(user, mkdir=False): def GetUserFiles(user, mkdir=False):
...@@ -72,11 +71,8 @@ class SshRunner: ...@@ -72,11 +71,8 @@ class SshRunner:
"""Wrapper for SSH commands. """Wrapper for SSH commands.
""" """
def __init__(self, sstore=None): def __init__(self, cfg):
if sstore is None: self.cfg = cfg
self.sstore = ssconf.SimpleStore()
else:
self.sstore = sstore
def _BuildSshOptions(self, batch, ask_key, use_cluster_key, def _BuildSshOptions(self, batch, ask_key, use_cluster_key,
strict_host_check): strict_host_check):
...@@ -88,7 +84,7 @@ class SshRunner: ...@@ -88,7 +84,7 @@ class SshRunner:
] ]
if use_cluster_key: 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 # TODO: Too many boolean options, maybe convert them to more descriptive
# constants. # constants.
...@@ -224,10 +220,10 @@ class SshRunner: ...@@ -224,10 +220,10 @@ class SshRunner:
return True, "host matches" return True, "host matches"
def WriteKnownHostsFile(cfg, sstore, file_name): def WriteKnownHostsFile(cfg, file_name):
"""Writes the cluster-wide equally known_hosts file. """Writes the cluster-wide equally known_hosts file.
""" """
utils.WriteFile(file_name, mode=0700, utils.WriteFile(file_name, mode=0700,
data="%s ssh-rsa %s\n" % (sstore.GetClusterName(), data="%s ssh-rsa %s\n" % (cfg.GetClusterName(),
cfg.GetHostKey())) cfg.GetHostKey()))
...@@ -161,6 +161,9 @@ def ClusterCopyFile(opts, args): ...@@ -161,6 +161,9 @@ def ClusterCopyFile(opts, args):
nodes - list containing the name of target nodes; if empty, all nodes nodes - list containing the name of target nodes; if empty, all nodes
""" """
# TODO: Query master
cfg = ssconf.SimpleConfigReader()
filename = args[0] filename = args[0]
if not os.path.exists(filename): if not os.path.exists(filename):
raise errors.OpPrereqError("No such filename '%s'" % filename) raise errors.OpPrereqError("No such filename '%s'" % filename)
...@@ -169,7 +172,7 @@ def ClusterCopyFile(opts, args): ...@@ -169,7 +172,7 @@ def ClusterCopyFile(opts, args):
op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes)
results = [row[0] for row in SubmitOpCode(op) if row[0] != myname] results = [row[0] for row in SubmitOpCode(op) if row[0] != myname]
srun = ssh.SshRunner() srun = ssh.SshRunner(cfg)
for node in results: for node in results:
if not srun.CopyFileToNode(node, filename): if not srun.CopyFileToNode(node, filename):
print >> sys.stderr, ("Copy of file %s to node %s failed" % print >> sys.stderr, ("Copy of file %s to node %s failed" %
...@@ -188,14 +191,18 @@ def RunClusterCommand(opts, args): ...@@ -188,14 +191,18 @@ def RunClusterCommand(opts, args):
nodes: list containing the name of target nodes; if empty, all nodes nodes: list containing the name of target nodes; if empty, all nodes
""" """
# TODO: Query master
cfg = ssconf.SimpleConfigReader()
command = " ".join(args) command = " ".join(args)
op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes)
nodes = [row[0] for row in SubmitOpCode(op)] nodes = [row[0] for row in SubmitOpCode(op)]
sstore = ssconf.SimpleStore() sstore = ssconf.SimpleStore()
master_node = sstore.GetMasterNode() 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: if master_node in nodes:
nodes.remove(master_node) nodes.remove(master_node)
nodes.append(master_node) nodes.append(master_node)
......
...@@ -41,10 +41,9 @@ class TestKnownHosts(testutils.GanetiTestCase): ...@@ -41,10 +41,9 @@ class TestKnownHosts(testutils.GanetiTestCase):
def test(self): def test(self):
cfg = mocks.FakeConfig() cfg = mocks.FakeConfig()
sstore = mocks.FakeSStore() ssh.WriteKnownHostsFile(cfg, self.tmpfile.name)
ssh.WriteKnownHostsFile(cfg, sstore, self.tmpfile.name)
self.assertFileContent(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)) mocks.FAKE_CLUSTER_KEY))
......
...@@ -58,9 +58,6 @@ class FakeConfig: ...@@ -58,9 +58,6 @@ class FakeConfig:
class FakeSStore: class FakeSStore:
"""Fake simplestore object""" """Fake simplestore object"""
def GetClusterName(self):
return "test.cluster"
def GetMasterNode(self): def GetMasterNode(self):
return utils.HostInfo().name 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