Updates ODL Pipeline scripts for CSIT
[sdnvpn.git] / odl-pipeline / lib / utils / ssh_util.py
1 #
2 # Copyright (c) 2015 All rights reserved
3 # This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #
10 import os
11 home = os.getenv("HOME")
12 SSH_CONFIG = {'TMP_SSH_CONFIG': "./tmp/ssh_config",
13               'ID_RSA_PATH': "%s/.ssh/id_rsa" % home}
14
15
16 class SshUtil(object):
17
18     @staticmethod
19     def gen_ssh_config(node_list):
20         config = ["UserKnownHostsFile=/dev/null",
21                   "StrictHostKeyChecking=no",
22                   "ForwardAgent yes",
23                   "GSSAPIAuthentication=no",
24                   "LogLevel ERROR"]
25         for node in node_list:
26             config.append(node.to_ssh_config())
27         with open(SSH_CONFIG['TMP_SSH_CONFIG'], 'w') as f:
28             f.write('\n'.join(config))
29
30     @staticmethod
31     def get_config_file_path():
32         return SSH_CONFIG['TMP_SSH_CONFIG']
33
34     @staticmethod
35     def get_id_rsa():
36         return SSH_CONFIG['ID_RSA_PATH']