-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup_server.py
114 lines (90 loc) · 4.33 KB
/
setup_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/python
import requests,json
import sys, os, re
from pprint import pprint
#import paramiko
import traceback, logging
import ssh_apis
import pexpect
#Global data
gUserInputData = ""
gOvsSetupFile = "clean_install_ovs.sh"
gServerSetupFile = "clean_start_server.sh"
gOdlExpectTimeout = 330
def validate_and_load_input(input_file):
global gUserInputData
try:
with open(input_file) as data_fp:
gUserInputData = json.load(data_fp)
#print gUserInputData
except ValueError, e:
print "Fix following error in input JSON file=" + input_file + "."
print e
print
return False
return True
#=======================================================================================
#****************************************************
gLogFd = logging.getLogger(__name__)
#****************************************************
if len(sys.argv) < 2 :
print ""
print "Usage: " + sys.argv[0] + " <full path to file containing host config in JSON format>"
exit(0)
#check if input file exists
if not os.path.exists(sys.argv[1]):
print ""
print "Configuration files or path does not exists - " + sys.argv[1]
print ""
print "Usage: " + sys.argv[0] + " <input file in JSON format>"
exit(0)
#check if input file data correctness
return_code = validate_and_load_input(sys.argv[1])
if return_code == False :
print "____________________________________________"
else:
print "Generating setup files ..."
#print gUserInputData['odl-configuration']['service-function-forwarders'][1]['ip-address']
#create outpur file name as script_folder + output.py
exec_dirname = os.path.dirname(os.path.realpath(sys.argv[0]))
#create file for Service Node configuration
ovsFilename = exec_dirname + "/" + gOvsSetupFile
if not os.path.exists(ovsFilename):
print ""
print "OVS installation script - "+ gOvsSetupFile + " does not exists in - " + exec_dirname + "\n"
print "Get file from - https://github.com/yyang13/ovs_nsh_patches/blob/master/start-ovs-deb.sh\n"
exit(0)
srvFilename = exec_dirname + "/" + gServerSetupFile
if not os.path.exists(srvFilename):
print ""
print "OVS installation script - "+ gServerSetupFile + " does not exists in - " + exec_dirname + "\n"
exit(0)
ssh_session = ssh_apis.ssh_login(gUserInputData['server']['ip'],gUserInputData['server']['user'],gUserInputData['server']['password'])
print "starting installation of required packages.."
ssh_session.sendline ("sudo apt-get install -y python-pip")
i = ssh_session.expect (ssh_apis.COMMAND_PROMPT)
outdata = ssh_session.before
ssh_session.sendline ("sudo apt-get install -y git")
i = ssh_session.expect (ssh_apis.COMMAND_PROMPT)
outdata = ssh_session.before
ssh_session.sendline ("sudo ovs-vsctl show")
ssh_session.expect (ssh_apis.COMMAND_PROMPT)
outdata = ssh_session.before
if 'ovs_version:' in outdata or 'ovs-vsctl:' in outdata:
print "Ovs installed on end host. Doing clean and config"
ssh_apis.ssh_sftp(gUserInputData['server']['ip'],gUserInputData['server']['user'],gUserInputData['server']['password'], srvFilename, "/tmp/"+gServerSetupFile)
ssh_session.sendline ("sudo sh /tmp/"+gServerSetupFile + " " + gUserInputData['server']['overlay_ip'] + " " + gUserInputData['client']['overlay_ip'] + " " + gUserInputData['controller']['ip'])
i = ssh_session.expect (ssh_apis.COMMAND_PROMPT)
outdata = ssh_session.before
else:
print "Ovs not installed on end host. Doing install and config"
ssh_apis.ssh_sftp(gUserInputData['server']['ip'],gUserInputData['server']['user'],gUserInputData['server']['password'], ovsFilename, "/tmp/"+gOvsSetupFile)
ssh_apis.ssh_sftp(gUserInputData['server']['ip'],gUserInputData['server']['user'],gUserInputData['server']['password'], srvFilename, "/tmp/"+gServerSetupFile)
ssh_session.sendline ("sudo sh /tmp/"+gOvsSetupFile)
#i = ssh_session.expect (ssh_apis.COMMAND_PROMPT)
i = ssh_session.expect (ssh_apis.COMMAND_PROMPT, timeout=gOdlExpectTimeout)
outdata = ssh_session.before
ssh_session.sendline ("sudo sh /tmp/"+gServerSetupFile + " " + gUserInputData['server']['overlay_ip'] + " " + gUserInputData['client']['overlay_ip'] + " " + gUserInputData['controller']['ip'])
i = ssh_session.expect (ssh_apis.COMMAND_PROMPT)
outdata = ssh_session.before
ssh_apis.ssh_logout(ssh_session)