forked from sysatrium/fabric
/
web-interface.py
354 lines (273 loc) · 12.8 KB
/
web-interface.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/usr/bin/python
#
# Author: Maxim Ivchenko
#
# description:
# This cook will be to cook some client web interfaces and some tomcat applications.
# He can deploy some client web interfaces to the web hosts.
# The default path of deploy of clients web interfaces is /var/www
from fabric.api import *
from fabric.contrib import *
from fabric.colors import *
import jinja2
import os
import glob
import sys
import MySQLdb
import time
import string
import common
# Get syntax
def syntax():
print (green("""
# Description
This cook will be to cook some client web interfaces.
He can deploy some client web interfaces to the web hosts.
The default path of deploy of clients web interfaces is /var/www
If you haven't got the ssh access to the web hosts of customer,
then you must upload clients web interfaces to 'templates/web-interfaces/interfaces_name/data'.
"""+red('For example:')+"""templates/web-interfaces/vcc/data
# Tomcat applications
"""+red('Available tomcat apps:')+""" vcc, conference, url, community, mas, massonic, cc"""))
print (blue("""
# Deploy some clients web interfaces
fab -f web-interfaces.py deploy_clients:interfaces="vcc community share conference" -H web1,web2"""))
# Get web-interfaces
# fab -f web-interfaces.py get_client_interfaces:interfaces="vcc community conference"
def get_client_interfaces(interfaces=''):
if interfaces == '':
print (red('You must give me a list of interfaces through the gap for the deploy.'))
exit()
interfaces=interfaces.split(' ')
# check share
if 'share' not in interfaces:
print (red('You must give the interface - share, too'))
exit()
# set path
templates_path=common.get_templates(path='templates/web-interfaces')
for interface in interfaces:
if os.path.exists(templates_path+'/'+interface):
local('test -d '+templates_path+'/'+interface+' && cd '+templates_path+' && rm -rf ./'+interface)
if interface == 'vcc':
local('git clone -b teligent git@git.teligent.ru:/webstroy/'+interface+'-teligent.git '+templates_path+'/'+interface+'')
else:
local('git clone git@git.teligent.ru:/webstroy/'+interface+'-teligent.git '+templates_path+'/'+interface+'')
# Put the interfaces to the web-hosts
# fab -f web-interfaces.py put_client_interfaces:interfaces="vcc community share" -H webdb1,webdb2
def put_client_interfaces(interfaces=''):
if interfaces == '':
print (red('You must give me a list of interfaces through the gap for the deploy.'))
exit()
interfaces=interfaces.split(' ')
# check share
if 'share' not in interfaces:
print (red('You must give the interface - \'share\', too'))
exit()
# set path
templates_path=common.get_templates(path='templates/web-interfaces')
install_path=common.get_install(path='/var/www')
if not files.exists(install_path):
run('mkdir -p '+install_path)
for interface in interfaces:
if not files.exists(install_path+'/'+interface):
run('mkdir '+install_path+'/'+interface)
put(templates_path+'/'+interface+'/data/*', install_path+'/'+interface)
# Deploy clients web-interfaces
# fab -f deploy_clients:interfaces="vcc community conference share" -H webdb1,webdb2
def deploy_clients(interfaces='',silent=0):
if silent:
action=1
else:
action=console.confirm('Do you have got the ssh access to the web-hosts of a customer?', default=True)
if action:
get_client_interfaces(interfaces=interfaces)
put_client_interfaces(interfaces=interfaces)
else:
put_client_interfaces(interfaces=interfaces)
# Create the url for Nexus
def set_nexus_url(g='',r='public',a='',p='war',v='',c=''):
nexus_options={
'base_url': 'http://nexus.teligent.ru/nexus/service/local/artifact/maven/redirect',
'g': g,
'r': r,
'a': a,
'p': p,
'v': v,
}
if c == '':
url=""+nexus_options['base_url']+" -dg="+g+" -dr="+r+" -da="+a+" -dp="+p+" -dv="+v+""
else:
url=""+nexus_options['base_url']+" -dg="+g+" -dr="+r+" -da="+a+" -dp="+p+" -dv="+v+" -dc="+c+""
return url
# Get tomcat7 applications
# fab -f web-interfaces.py get_tomcat_apps:apps="vcc conference url"
def get_tomcat_apps(apps='',version='release',ext='war'):
if apps == '':
print (red('You must give me a list of the tomcat apps through the gap for the deploy.'))
exit()
if (version != 'release' and version != 'snapshot'):
print(red('The available values of the version is release or snapshot.'))
version=prompt('What a version of the apps do you want - release|snapshot?', default='release')
if version == 'snapshot':
version='LATEST'
apps=apps.split(' ')
# set path
templates_path=common.get_templates(path="templates/web-interfaces/tomcat")
version=version.upper()
# Create directory
if not os.path.exists(templates_path):
local('mkdir '+templates_path)
for app in apps:
if app == 'vcc':
local('curl -s -o '+templates_path+'/'+app+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mobicom.'+app,a=app+'-web',v=version,p=ext))
if app == 'conference':
local('curl -s -o '+templates_path+'/'+app+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mobicom.'+app,a=app+'-web',v=version,p=ext))
if app == 'url':
local('curl -s -o '+templates_path+'/'+app+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mobicom.'+app,a=app+'-web',v=version,p=ext))
if app == 'community':
local('curl -s -o '+templates_path+'/'+app+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.'+app+'',a=app+'-web',v=version,p=ext))
if app == 'mas':
local('curl -s -o '+templates_path+'/'+app+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mobicom.'+app+'',a=app+'-web',v=version,p=ext))
if app == 'cc':
local('curl -s -o '+templates_path+'/'+app+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.'+app+'',a=app+'-web',v=version,p=ext))
if app == 'massonic':
local('curl -s -o '+templates_path+'/'+app+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mas',a='mas-web',v=version,p=ext))
# Put the tomcat applications to the web hosts
# fab -f web-interfaces.py put_tomcat_apps:apps="vcc conference" -H webdb1,webdb2
# fab -f web-interfaces.py put_tomcat_apps:apps="vcc conference",ext="war" -H webdb1,webdb2
def put_tomcat_apps(apps="",ext='war'):
if apps == '':
print (red('You must give me a list of the tomcat apps through the gap for the deploy.'))
exit()
apps=apps.split(' ')
# set path
templates_path=common.get_templates(path="templates/web-interfaces/tomcat")
install_path=common.get_install(path="/tmp/tomcat")
if not files.exists(install_path):
run('mkdir '+install_path)
for app in apps:
if os.path.exists(templates_path+'/'+app+'.'+ext):
put(templates_path+'/'+app+'.'+ext, install_path)
else:
print(red('The application '+app+' doesn\'t upload to the '+env.host_string+' because it not exists in '+templates_path))
# Install tomcat applications
# fab -f web-interfaces.py install_tomcat_apps:apps="vcc conference" -H webdb1,webdb2
# fab -f web-interfaces.py install_tomcat_apps:apps="vcc conference",ext="war" -H webdb1,webdb2
def install_tomcat_apps(apps='',ext='war'):
if apps == '':
print (red('You must give me a list of the tomcat apps through the gap for the deploy.'))
exit()
apps=apps.split(' ')
# set path
templates_path=common.get_templates(path='/tmp/tomcat')
install_path=common.get_install(path='/var/lib/tomcat7')
if not files.exists(templates_path):
print(red('The path '+templates_path+' to the tomcat applications on the '+env.host_string+' isn\'t exists'))
exit()
for app in apps:
if files.exists(templates_path+'/'+app+'.'+ext):
if not files.exists(install_path+'/'+app+'/webapps/'+app):
run('mkdir '+install_path+'/'+app+'/webapps/'+app)
run('cp '+templates_path+'/'+app+'.'+ext+' '+install_path+'/'+app+'/webapps/'+app)
with cd(install_path+'/'+app+'/webapps/'+app):
if files.exists('/usr/bin/unzip'):
run('unzip '+app+'.'+ext)
run('rm -f '+app+'.'+ext)
else:
print(red('You must install the unzip on the '+env.host_string))
exit()
else:
print(red('The path to the tomcat\'s application \''+app+'\' isn\'t exists'))
# Get a profile of the tomcat apps
# fab -f web-interfaces.py get_profiles_apps:apps='vcc conference',profile='flagman-web1'
def get_profile_app(apps='',version='release',profile='',ext='tar.gz'):
if apps == '':
print (red('You must give me a list of the tomcat apps through the gap for the deploy.'))
exit()
if (version != 'release' and version != 'snapshot'):
print(red('The available values of the version is release or snapshot.'))
version=prompt('What a version of the profile do you want - release|snapshot?', default='release')
if version == 'snapshot':
version='LATEST'
if not profile and profile == '':
profile=prompt('What a name of the profile of the tomcat applications do you want?', default='')
apps=apps.split(' ')
# set path
templates_path=common.get_templates(path="templates/web-interfaces/profiles")
version=version.upper()
# create directory
if not os.path.exists(templates_path):
local('mkdir '+templates_path)
for app in apps:
if app == 'vcc':
local('curl -s -o '+templates_path+'/'+profile+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mobicom.'+app,a=app+'-web',v=version,c=profile,p=ext))
if app == 'conference':
local('curl -s -o '+templates_path+'/'+profile+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mobicom.'+app,a=app+'-web',v=version,c=profile,p=ext))
if app == 'url':
local('curl -s -o '+templates_path+'/'+profile+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mobicom.'+app,a=app+'-web',v=version,c=profile,p=ext))
if app == 'community':
local('curl -s -o '+templates_path+'/'+profile+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.'+app+'',a=app+'-web',v=version,c=profile,p=ext))
if app == 'mas':
local('curl -s -o '+templates_path+'/'+profile+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mobicom.'+app+'',a=app+'-web',v=version,c=profile,p=ext))
if app == 'cc':
local('curl -s -o '+templates_path+'/'+profile+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.'+app+'',a=app+'-web',v=version,c=profile,p=ext))
if app == 'massonic':
local('curl -s -o '+templates_path+'/'+profile+'.'+ext+' -L -G '+set_nexus_url(g='se.teligent.mas',a='mas-web',v=version,c=profile,p=ext))
# Put profiles of the tomcat applications to the web hosts
# fab -f web-interfaces.py put_profiles_apps:apps="vcc conference" -H webdb1,webdb2
# fab -f web-interfaces.py put_profiles_apps:apps="vcc conference",ext="tar.gz" -H webdb1,webdb2
def put_profile_app(profiles='',ext='tar.gz'):
if not profiles and profiles == '':
profiles=prompt('What a name of the profiles of the tomcat applications do you want?', default='')
profiles=profiles.split(' ')
# set path
templates_path=common.get_templates(path="templates/web-interfaces/profiles")
install_path=common.get_install(path="/tmp/tomcat/profiles")
if not files.exists(install_path):
run('mkdir '+install_path)
for profile in profiles:
if os.path.exists(templates_path+'/'+profile+'.'+ext):
put(templates_path+'/'+profile+'.'+ext, install_path)
else:
print(red('The profile '+profile+'.'+ext+' doesn\'t upload to the '+env.host_string+' because it not exists in '+templates_path))
# Install profiles of the tomcat applications
# fab -f web-interfaces.py install_profiles_apps:apps="vcc conference" -H webdb1,webdb2
# fab -f web-interfaces.py install_profiles_apps:apps="vcc conference",ext="tar.gz" -H webdb1,webdb2
def install_profile_app(apps='',ext='tar.gz',profile=''):
if apps == '':
print (red('You must give me a list of the tomcat apps through the gap for the deploy.'))
exit()
if not profile and profile == '':
profile=prompt('What a name of the profile of the tomcat applications do you want?', default='')
apps=apps.split(' ')
# set path
templates_path=common.get_templates(path='/tmp/tomcat/profiles')
install_path=common.get_install(path='/var/lib/tomcat7')
if not files.exists(templates_path):
print(red('The path '+templates_path+' to the tomcat applications isn\'t exists'))
exit()
for app in apps:
if files.exists(templates_path+'/'+profile+'.'+ext):
run('cp '+templates_path+'/'+profile+'.'+ext+' '+install_path+'/'+app+'/webapps/'+app)
with cd(install_path+'/'+app+'/webapps/'+app+''):
with prefix('tar -xzf '+profile+'.'+ext):
run('rm -f '+profile+'.'+ext)
else:
print(red('The path to the profile \''+profile+'\' of the tomcat\'s application \''+app+'\' isn\'t exists'))
# Deploy the tomcat's applications
def deploy_tomcat_apps(apps='',ext='war',version='release',silent=1,profile=''):
get_tomcat_apps(apps=apps,version=version,ext=ext)
put_tomcat_apps(apps=apps,ext=ext)
# Formating a list of services
applications=apps.split(' ')
services=list()
for app in applications:
services.append('tomcat7-'+app)
services=' '.join(services)
common.start(services=services,silent=1)
common.stop(services=services,silent=1)
install_tomcat_apps(apps=apps,ext=ext)
get_profile_app(apps=apps,ext='tar.gz',version='',profile=profile)
put_profile_app(profiles=profile,ext='tar.gz')
install_profile_app(apps=apps,profile=profile,ext='tar.gz')
common.start(services=services,silent=1)