summaryrefslogtreecommitdiffstats
path: root/clover/controller/control/api/nginx.py
diff options
context:
space:
mode:
Diffstat (limited to 'clover/controller/control/api/nginx.py')
-rw-r--r--clover/controller/control/api/nginx.py49
1 files changed, 40 insertions, 9 deletions
diff --git a/clover/controller/control/api/nginx.py b/clover/controller/control/api/nginx.py
index ba99b94..a7d902d 100644
--- a/clover/controller/control/api/nginx.py
+++ b/clover/controller/control/api/nginx.py
@@ -15,28 +15,28 @@ import logging
nginx = Blueprint('nginx', __name__)
-@nginx.route("/nginx/slb", methods=['GET', 'POST'])
-def slblist():
+@nginx.route("/nginx/lb", methods=['GET', 'POST'])
+def modify_lb():
grpc_port = '50054'
try:
p = request.json
try:
- slb_name = p['slb_name']
- nginx_grpc = slb_name + ':' + grpc_port
+ lb_name = p['lb_name']
+ nginx_grpc = lb_name + ':' + grpc_port
channel = grpc.insecure_channel(nginx_grpc)
stub = nginx_pb2_grpc.ControllerStub(channel)
s_list = []
- for s in p['slb_list']:
+ for s in p['lb_list']:
s_list.append(s['url'])
- slb_list = pickle.dumps(s_list)
+ lb_list = pickle.dumps(s_list)
response = stub.ModifyLB(nginx_pb2.ConfigLB(
server_port=p['server_port'], server_name=p['server_name'],
- slb_list=slb_list,
- slb_group=p['slb_group'], lb_path=p['lb_path']))
+ slb_list=lb_list,
+ slb_group=p['lb_group'], lb_path=p['lb_path']))
except (KeyError, ValueError) as e:
logging.debug(e)
- return Response('Invalid value in test plan json/yaml', status=400)
+ return Response('Invalid value in LB json/yaml', status=400)
except Exception as e:
logging.debug(e)
if e.__class__.__name__ == "_Rendezvous":
@@ -46,6 +46,37 @@ def slblist():
return response.message
+@nginx.route("/nginx/server", methods=['GET', 'POST'])
+def modify_server():
+ grpc_port = '50054'
+ try:
+ p = request.json
+ try:
+ server_name = p['server_name']
+ nginx_grpc = server_name + ':' + grpc_port
+ channel = grpc.insecure_channel(nginx_grpc)
+ stub = nginx_pb2_grpc.ControllerStub(channel)
+
+ locations = pickle.dumps(p['locations'])
+ files = pickle.dumps(p['files'])
+ response = stub.ModifyServer(nginx_pb2.ConfigServer(
+ server_port=p['server_port'], server_name=p['server_name'],
+ site_root=p['site_root'], locations=locations, files=files,
+ site_index=p['site_index'],
+ upload_path_config=p['upload_path_config'],
+ upload_path_test=p['upload_path_test']))
+ except (KeyError, ValueError) as e:
+ logging.debug(e)
+ return Response('Invalid value in server json/yaml', status=400)
+ except Exception as e:
+ logging.debug(e)
+ if e.__class__.__name__ == "_Rendezvous":
+ return Response("Error connecting to server via gRPC", status=400)
+ else:
+ return Response("Error modifying server", status=400)
+ return response.message
+
+
@nginx.route("/nginx/test")
def test():
return "<h1 style='color:blue'>Nginx API Test Response</h1>"