-
Notifications
You must be signed in to change notification settings - Fork 7
/
nginx_proxy_add.py
35 lines (30 loc) · 1.26 KB
/
nginx_proxy_add.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
#coding = utf-8
import argparse
import sys
import etcd
import json
parser = argparse.ArgumentParser(description="nginx 转发添加")
parser.add_argument('--namespace', help='项目所在命名空间', type=str, default='default')
parser.add_argument('--name', help='项目名字', type=str, default='default')
parser.add_argument('--location_pass', help='代理路径', type=str, default='default')
def main():
etcd_client = etcd.Client(host='172.21.133.1', port=4001)
args = parser.parse_args()
print(args.namespace)
print(add_web_app_location_pass(etcd_client, args.namespace, args.name, args.location_pass))
return 0
def add_web_app_location_pass(etcd_client, namespace, name, location_pass):
app_info = get_web_app(etcd_client, namespace, name)
app_info = app_info.replace("'", "\"")
app_info = json.loads(app_info)
if app_info.has_key('location_pass'):
app_info['location_pass'].append(location_pass)
else:
app_info['location_pass'] = []
app_info['location_pass'].append(location_pass)
#etcd_client.set(app, json.dumps(app_info))
def get_web_app(etcd_client, namespace, name):
app = "devnginx/{}/{}".format(namespace, name)
return etcd_client.get(app).value
if __name__ == "__main__":
sys.exit(main())