Revision 7688d0d3
b/lib/backend.py | ||
---|---|---|
49 | 49 |
|
50 | 50 |
|
51 | 51 |
def _GetSshRunner(): |
52 |
return ssh.SshRunner() |
|
52 |
return ssh.SshRunner(_GetConfig())
|
|
53 | 53 |
|
54 | 54 |
|
55 | 55 |
def _CleanDirectory(path, exclude=[]): |
b/lib/bootstrap.py | ||
---|---|---|
243 | 243 |
cfg = config.ConfigWriter() |
244 | 244 |
cfg.InitConfig(constants.CONFIG_VERSION, cluster_config, master_node_config) |
245 | 245 |
|
246 |
ssh.WriteKnownHostsFile(cfg, ss, constants.SSH_KNOWN_HOSTS_FILE)
|
|
246 |
ssh.WriteKnownHostsFile(cfg, constants.SSH_KNOWN_HOSTS_FILE) |
|
247 | 247 |
|
248 | 248 |
# start the master ip |
249 | 249 |
# TODO: Review rpc call from bootstrap |
... | ... | |
274 | 274 |
node: fully qualified domain name for the new node |
275 | 275 |
|
276 | 276 |
""" |
277 |
cfg = ssconf.SimpleConfigReader() |
|
278 |
sshrunner = ssh.SshRunner(cfg) |
|
277 | 279 |
ss = ssconf.SimpleStore() |
278 |
sshrunner = ssh.SshRunner(ss) |
|
279 | 280 |
gntpass = ss.GetNodeDaemonPassword() |
280 | 281 |
if not re.match('^[a-zA-Z0-9.]{1,64}$', gntpass): |
281 | 282 |
raise errors.OpExecError("ganeti password corruption detected") |
b/lib/cmdlib.py | ||
---|---|---|
111 | 111 |
|
112 | 112 |
""" |
113 | 113 |
if not self.__ssh: |
114 |
self.__ssh = ssh.SshRunner(self.sstore)
|
|
114 |
self.__ssh = ssh.SshRunner(self.cfg)
|
|
115 | 115 |
return self.__ssh |
116 | 116 |
|
117 | 117 |
ssh = property(fget=__GetSSH) |
b/lib/ssh.py | ||
---|---|---|
30 | 30 |
from ganeti import utils |
31 | 31 |
from ganeti import errors |
32 | 32 |
from ganeti import constants |
33 |
from ganeti import ssconf |
|
34 | 33 |
|
35 | 34 |
|
36 | 35 |
def GetUserFiles(user, mkdir=False): |
... | ... | |
72 | 71 |
"""Wrapper for SSH commands. |
73 | 72 |
|
74 | 73 |
""" |
75 |
def __init__(self, sstore=None): |
|
76 |
if sstore is None: |
|
77 |
self.sstore = ssconf.SimpleStore() |
|
78 |
else: |
|
79 |
self.sstore = sstore |
|
74 |
def __init__(self, cfg): |
|
75 |
self.cfg = cfg |
|
80 | 76 |
|
81 | 77 |
def _BuildSshOptions(self, batch, ask_key, use_cluster_key, |
82 | 78 |
strict_host_check): |
... | ... | |
88 | 84 |
] |
89 | 85 |
|
90 | 86 |
if use_cluster_key: |
91 |
options.append("-oHostKeyAlias=%s" % self.sstore.GetClusterName())
|
|
87 |
options.append("-oHostKeyAlias=%s" % self.cfg.GetClusterName())
|
|
92 | 88 |
|
93 | 89 |
# TODO: Too many boolean options, maybe convert them to more descriptive |
94 | 90 |
# constants. |
... | ... | |
224 | 220 |
return True, "host matches" |
225 | 221 |
|
226 | 222 |
|
227 |
def WriteKnownHostsFile(cfg, sstore, file_name):
|
|
223 |
def WriteKnownHostsFile(cfg, file_name): |
|
228 | 224 |
"""Writes the cluster-wide equally known_hosts file. |
229 | 225 |
|
230 | 226 |
""" |
231 | 227 |
utils.WriteFile(file_name, mode=0700, |
232 |
data="%s ssh-rsa %s\n" % (sstore.GetClusterName(),
|
|
228 |
data="%s ssh-rsa %s\n" % (cfg.GetClusterName(),
|
|
233 | 229 |
cfg.GetHostKey())) |
b/scripts/gnt-cluster | ||
---|---|---|
161 | 161 |
nodes - list containing the name of target nodes; if empty, all nodes |
162 | 162 |
|
163 | 163 |
""" |
164 |
# TODO: Query master |
|
165 |
cfg = ssconf.SimpleConfigReader() |
|
166 |
|
|
164 | 167 |
filename = args[0] |
165 | 168 |
if not os.path.exists(filename): |
166 | 169 |
raise errors.OpPrereqError("No such filename '%s'" % filename) |
... | ... | |
169 | 172 |
|
170 | 173 |
op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) |
171 | 174 |
results = [row[0] for row in SubmitOpCode(op) if row[0] != myname] |
172 |
srun = ssh.SshRunner() |
|
175 |
srun = ssh.SshRunner(cfg)
|
|
173 | 176 |
for node in results: |
174 | 177 |
if not srun.CopyFileToNode(node, filename): |
175 | 178 |
print >> sys.stderr, ("Copy of file %s to node %s failed" % |
... | ... | |
188 | 191 |
nodes: list containing the name of target nodes; if empty, all nodes |
189 | 192 |
|
190 | 193 |
""" |
194 |
# TODO: Query master |
|
195 |
cfg = ssconf.SimpleConfigReader() |
|
196 |
|
|
191 | 197 |
command = " ".join(args) |
192 | 198 |
op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) |
193 | 199 |
nodes = [row[0] for row in SubmitOpCode(op)] |
194 | 200 |
|
195 | 201 |
sstore = ssconf.SimpleStore() |
196 | 202 |
master_node = sstore.GetMasterNode() |
197 |
srun = ssh.SshRunner(sstore=sstore)
|
|
203 |
srun = ssh.SshRunner(cfg)
|
|
198 | 204 |
|
205 |
# Make sure master node is at list end |
|
199 | 206 |
if master_node in nodes: |
200 | 207 |
nodes.remove(master_node) |
201 | 208 |
nodes.append(master_node) |
b/test/ganeti.ssh_unittest.py | ||
---|---|---|
41 | 41 |
|
42 | 42 |
def test(self): |
43 | 43 |
cfg = mocks.FakeConfig() |
44 |
sstore = mocks.FakeSStore() |
|
45 |
ssh.WriteKnownHostsFile(cfg, sstore, self.tmpfile.name) |
|
44 |
ssh.WriteKnownHostsFile(cfg, self.tmpfile.name) |
|
46 | 45 |
self.assertFileContent(self.tmpfile.name, |
47 |
"%s ssh-rsa %s\n" % (sstore.GetClusterName(),
|
|
46 |
"%s ssh-rsa %s\n" % (cfg.GetClusterName(),
|
|
48 | 47 |
mocks.FAKE_CLUSTER_KEY)) |
49 | 48 |
|
50 | 49 |
|
b/test/mocks.py | ||
---|---|---|
58 | 58 |
class FakeSStore: |
59 | 59 |
"""Fake simplestore object""" |
60 | 60 |
|
61 |
def GetClusterName(self): |
|
62 |
return "test.cluster" |
|
63 |
|
|
64 | 61 |
def GetMasterNode(self): |
65 | 62 |
return utils.HostInfo().name |
66 | 63 |
|
Also available in: Unified diff