-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd.py
130 lines (115 loc) · 3.75 KB
/
d.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
#coding=utf8
#参数一:domain
#参数二:serviceEntityName
#参数三:tag
#参数四:配置文件(file map)
#参数五:flag
import httplib
import urllib
import json
import ConfigParser
import os
import sys
#ag = "10.0.1.1"
ag = "dev.agplat"
port = "80"
class HttpClient():
def get(self, server, port, location, value={}):
self.server = server
self.port = port
self.location = location
self.value = value
data = urllib.urlencode(self.value)
if data: url = self.location + '?' + data
else: url = self.location
try:
httpclient = httplib.HTTPConnection(self.server, self.port,timeout=5)
httpclient.request('GET', url)
response = httpclient.getresponse()
if int(response.status) == 200:
return response.read()
except Exception as e:
return e
finally:
if httpclient:
httpclient.close()
def post(self, server, port, location, value):
self.server = server
self.port = port
self.location = location
self.value = value
headers = {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}
params = urllib.urlencode(self.value)
try:
httpclient = httplib.HTTPConnection(self.server, self.port, timeout=5)
httpclient.request('POST', self.location, params, headers=headers)
response = httpclient.getresponse()
if int(response.status) == 200:
return response.read()
except Exception as e:
print e
finally:
if httpclient:
httpclient.close()
def getInstanceFromdomain(domain,serviceEntityName=''):
value = {}
value['domain'] = domain
if serviceEntityName: value['serviceEntityName'] = serviceEntityName
httpclient = HttpClient()
res_json = httpclient.get(ag,port,"/serviceinstance/serviceentity/list/get",value)
instance = json.loads(res_json)
if instance['status'] == 'ok':
#return instance
if serviceEntityName: return instance['content'][serviceEntityName]
else: return instance['content']
elif instance['status'] == 'error':
return "参数错误!域名?"
def setInstancnDownOrUp(domain,serviceEntityName,instance, status):
params = {}
params['domain'] = domain
params['serviceEntityName'] = serviceEntityName
params['server'] = instance
params['upOrDown'] = status
httpclient = HttpClient()
res_json = httpclient.post(ag, port, "/serviceinstance/serviceentity/server/put", params)
if json.loads(res_json)['status'] == 'ok':
return 0
else:
return 1
def getRunConfig(serviceEntityName):
#返回json
httpclient = HttpClient()
location = '/' + serviceEntityName
release_host = 'dev.release.56qq.cn'
release_port = '80'
try:
runconf = httpclient.get(release_host,release_port, location)
runconf_dict = eval(runconf)
return runconf_dict
except Exception as e:
return
print getInstanceFromdomain('dev.shieldin', 'shield-manager')
print setInstancnDownOrUp('dev.shieldin', 'shield-manager', '10.0.2.7:405', 'down')
print getInstanceFromdomain('dev.shieldin')
print getRunConfig('shield-manager')
class DockerClient():
def __init__(self, ip, port):
self.ip = ip
self.port = port
_url = "tcp://" + self.ip + ":" + self.port
def dockerRun(self):
pass
def dockerStop(self, containerName):
pass
def dockerPs(self):
pass
def dockerPull(self, imageName):
pass
def dockerRm(self, containerName):
pass
def preRelease():
pass
def Release(tag, runConf):
pass
def aftRelease():
pass