-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfabfile.py
194 lines (175 loc) · 7.29 KB
/
fabfile.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import os
from fabric.api import local, run, env
from fabric.context_managers import lcd
from fabric.operations import prompt
from fabric.context_managers import settings
from setupTool import setupGenie, getSetupHdl
env.use_ssh_config = True
gAnchorDir = ''
gGitUsrName = ''
gRole = ''
def setupHandler():
global gAnchorDir, gGitUsrName, gRole
return getSetupHdl('setupInfo.json', gAnchorDir, gGitUsrName, gRole)
def setupExternals (comp=None):
print 'Installing all External dependencies....'
info = setupHandler().getExternalInstalls(comp)
for comp, deps in info.iteritems():
print 'Installing dependencies for %s' %(comp)
for dep in deps:
cmd = 'sudo apt-get install ' + dep
with settings(prompts={'Do you want to continue [Y/n]? ': 'Y'}):
local(cmd)
def setupGoDeps(comp=None, gitProto='http'):
print 'Fetching external Golang repos ....'
info = setupHandler().getGoDeps(comp)
extSrcDir = setupHandler().getExtSrcDir()
org = setupHandler().getOrg()
for rp in info:
with lcd(extSrcDir):
if gitProto == "ssh":
repoUrl = '[email protected]:%s/%s' %(org , rp['repo'])
else:
repoUrl = 'https://github.com/%s/%s' %(org , rp['repo'])
dstDir = rp['renamedst'] if rp.has_key('renamedst') else ''
dirToMake = dstDir
if dstDir == '' or (dstDir != '' and not (os.path.exists(extSrcDir+ dstDir + '/' + rp['repo']))):
cmd = 'git clone '+ repoUrl
local(cmd)
if rp.has_key('reltag'):
cmd = 'git checkout tags/'+ rp['reltag']
with lcd(extSrcDir+rp['repo']):
local(cmd)
if not dstDir.endswith('/'):
dirToMake = dstDir[0:dstDir.rfind('/')]
if dirToMake:
cmd = 'mkdir -p ' + dirToMake
local(cmd)
if rp.has_key('renamesrc'):
cmd = 'mv ' + extSrcDir+ rp['renamesrc']+ ' ' + extSrcDir+ rp['renamedst']
local(cmd)
def setupSRRepos( gitProto = 'http' , comp = None):
print 'Fetching Snaproute repositories dependencies....'
srRepos = setupHandler().getSRRepos()
org = setupHandler().getOrg()
internalUser = setupHandler().getUsrRole()
usrName = setupHandler().getUsrName()
srcDir = setupHandler().getSRSrcDir()
anchorDir = setupHandler().getAnchorDir()
if not os.path.isfile(srcDir+'/Makefile' ):
cmd = 'ln -s ' + anchorDir+ '/reltools/Makefile '+ srcDir + 'Makefile'
local(cmd)
if gitProto == "ssh":
if not internalUser:
userRepoPrefix = '[email protected]:%s/' %(org)
remoteRepoPrefix = None
else:
userRepoPrefix = '[email protected]:%s/' %(usrName)
remoteRepoPrefix = '[email protected]:%s/' %(org)
else:
if not internalUser:
userRepoPrefix = 'https://github.com/%s/' %(org)
remoteRepoPrefix = None
else:
userRepoPrefix = 'https://github.com/%s/' % (usrName)
remoteRepoPrefix = 'https://github.com/%s/' % (org)
for repo in srRepos:
with lcd(srcDir):
if not (os.path.exists(srcDir + repo) and os.path.isdir(srcDir+ repo)):
cmd = 'git clone '+ userRepoPrefix + repo
local(cmd)
if remoteRepoPrefix:
with lcd(srcDir +repo):
cmd = 'git remote add upstream ' + remoteRepoPrefix + repo + '.git'
local(cmd)
commandsToSync = ['git fetch upstream',
'git checkout master',
'git merge upstream/master']
for cmd in commandsToSync:
local(cmd)
def installThrift():
TMP_DIR = ".tmp"
thriftVersion = '0.9.3'
thriftPkgName = 'thrift-'+thriftVersion
if _verifyThriftInstallation(thriftVersion):
print 'Thrift Already installed. Skipping installation'
return
thrift_tar = thriftPkgName +'.tar.gz'
local('mkdir -p '+TMP_DIR)
local('wget -O '+ TMP_DIR + '/' +thrift_tar+ ' '+ 'http://www-us.apache.org/dist/thrift/0.9.3/thrift-0.9.3.tar.gz')
with lcd(TMP_DIR):
local('tar -xvf '+ thrift_tar)
with lcd (thriftPkgName):
local ('./configure --with-java=false')
local ('make')
local ('sudo make install')
def installNanoMsgLib ():
srcDir = setupHandler().getGoDepDirFor('nanomsg')
with lcd(srcDir):
cmdList = ['sudo apt-get install libtool',
'libtoolize',
'./autogen.sh',
'./configure',
'make',
'sudo make install',
]
for cmd in cmdList:
local(cmd)
def installIpTables():
extSrcDir = setupHandler().getExtSrcDir()
nfLoc = extSrcDir + 'github.com/netfilter/'
libipDir = 'libiptables'
allLibs = ['libmnl', 'libnftnl', 'iptables']
prefixDir = nfLoc + libipDir
cflagsDir = nfLoc + libipDir + "/include"
ldflagsDir = nfLoc + libipDir + "/lib"
for lib in allLibs:
with lcd(nfLoc + lib):
cmdList = []
cmdList.append('./autogen.sh')
if lib == 'libmnl':
cmdList.append('./configure --prefix=\"' + prefixDir + '\"')
elif lib == 'libnftnl':
os.environ["LIBMNL_CFLAGS"]= nfLoc + libipDir + "/include/libmnl"
os.environ["LIBMNL_LIBS"]= nfLoc + libipDir + "/lib/pkgconfig"
cmdList.append('./configure --prefix="' + prefixDir + '" CFLAGS="-I' + cflagsDir + '" LDFLAGS="-L' + ldflagsDir +'"')
elif lib == 'iptables':
cmdList.append('./configure --prefix="' + prefixDir + '" CFLAGS="-I' + cflagsDir + '" LDFLAGS="-L' + ldflagsDir +'" LIBS=\"-lmnl -lnftnl\"')
cmdList.append('make')
cmdList.append('make install')
for cmd in cmdList:
local(cmd)
def _createDirectoryStructure() :
dirs = setupHandler().getAllSrcDir()
for everydir in dirs:
local('mkdir -p '+ everydir)
def _verifyThriftInstallation(thriftVersion='0.9.3'):
with settings(warn_only=True):
ret = local('which thrift', capture=True)
if ret.failed:
return False
resp = local('thrift -version', capture=True)
return thriftVersion in resp
def printInstruction():
print "###########################"
print "Please add the following lines in your ~/.bashrc file"
print "###########################"
print "export PATH=$PATH:/usr/local/go/bin"
print "export SR_CODE_BASE=$HOME/git"
print "export GOPATH=$SR_CODE_BASE/snaproute/:$SR_CODE_BASE/external/:$SR_CODE_BASE/generated/"
print "###########################"
def setupDevEnv() :
global gAnchorDir, gGitUsrName, gRole
gAnchorDir = prompt('Host directory:', default='git')
gGitUsrName = prompt('Git username:')
gRole = prompt('SnapRoute Employee (y/n):', default='n')
local('git config --global credential.helper \"cache --timeout=3600\"')
_createDirectoryStructure()
setupHandler()
setupExternals()
setupGoDeps()
installThrift()
installNanoMsgLib()
installIpTables()
setupSRRepos()
printInstruction()