-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.py
82 lines (71 loc) · 2.45 KB
/
master.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
# -*- coding: utf-8 -*-
'''
This runner is used only for test purposes and servers no production purpose
'''
from __future__ import absolute_import
from __future__ import print_function
# Import python libs
import salt.config
import re
import os
import sys
import time
def view_directory(filename=""):
result = os.popen('ls /home/%s' % filename).readlines()
return result
def group(path='/etc/salt/master'):
opts = salt.config.client_config(path)
return opts["nodegroups"]
def get_group(path='/etc/salt/master.d/group.conf'):
f = open(path)
group = f.readlines()
f.close()
return group[1:]
def update_group(gruop, newip, path='/etc/salt/master.d/group.conf'):
bakpath = path + '.bak'
f = open(path)
substance = f.readlines()
f.close()
if os.path.isfile(bakpath):
os.remove(bakpath)
os.rename(path, bakpath)
for i in substance:
if i.find(gruop + ":") >= 0:
oldgruop = i
c = i.split("'")
c.insert(len(c) - 1, newip)
d = ",".join(c[1:-1])
newgroup = "'".join([c[0], d, c[-1]])
substance[substance.index(oldgruop)] = newgroup
f = open(path, "w")
f.writelines(substance)
f.close()
def buildproject(project, buildtype, buildcommand, svnurl):
username = 'admin'
password = '123456'
svnbase = '/home/data/svnbase/'
saltbase = '/home/data/salt/upload'
projecturl = svnurl
project = project
buildtype = buildtype
buildcommand = buildcommand
projectfile = svnbase + project
if not os.path.exists(projectfile):
os.mkdir(projectfile)
svnresult = os.system('cd %s && svn co --username %s --password %s %s' % (projectfile, username, password, projecturl))
result = {}
if svnresult == 0:
projectpath = svnbase + project + '/' + svnurl.split('/')[-1]
mvnresult = os.system('cd %s && %s' % (projectpath, buildcommand))
if buildtype == 'war':
mvto = os.system('mv %s/target/%s.war %s/%s.war' % (projectpath, project, saltbase, project))
elif buildtype == 'jar':
mvto = os.system('mv %s/target/%s.jar %s/%s.jar' % (projectpath, project, saltbase, project))
if mvto == 0:
result['master'] = 'project building successful'
else:
result['master'] = 'project building failed'
return result
else:
result['master'] = 'svn checkout failed'
return result