Let the system can change to non-distributed gateway smoothly.

This commit is contained in:
zhuyj17 2017-04-30 15:51:29 +08:00
parent 38854367ed
commit a680f9a0d3
4 changed files with 26 additions and 29 deletions

View File

@ -9,11 +9,8 @@ server
access_log off;
}
location ~ ^/(\d+\.\d+\.\d+\.\d+)/(.+)$ {
set $proxy_server $1;
set $other $2;
rewrite ^(.*)$ /$other break;
proxy_pass http://$1:%PROXY_PORT;
location ~ ^/(\d+\.\d+\.\d+\.\d+)/ {
proxy_pass http://%PROXY_SERVER_IP:%PROXY_PORT;
proxy_set_header Host $host:$server_port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;

View File

@ -23,7 +23,7 @@ class Container(object):
self.imgmgr = imagemgr.ImageMgr()
self.historymgr = History_Manager()
def create_container(self, lxc_name, username, setting, clustername, clusterid, containerid, hostname, ip, gateway, vlanid, image):
def create_container(self, lxc_name, proxy_server_ip, username, setting, clustername, clusterid, containerid, hostname, ip, gateway, vlanid, image):
logger.info("create container %s of %s for %s" %(lxc_name, clustername, username))
try:
setting = json.loads(setting)
@ -120,7 +120,7 @@ BASE_URL=%s
HUB_PREFIX=%s
HUB_API_URL=%s
IP=%s
""" % (username, 10000, cookiename, '/go/'+username+'/'+clustername, '/jupyter',
""" % (username, 10000, cookiename, '/'+ proxy_server_ip +'/go/'+username+'/'+clustername, '/jupyter',
authurl, ip.split('/')[0])
config.write(jconfigs)
config.close()

View File

@ -191,11 +191,11 @@ class VclusterMgr(object):
return [False, "proxy already exists"]
target = "http://" + ip + ":" + port + "/"
clusterinfo['proxy_ip'] = ip + ":" + port
if not clusterinfo['proxy_server_ip'] == self.addr:
if self.distributedgw == 'True':
worker = self.nodemgr.ip_to_rpc(clusterinfo['proxy_server_ip'])
worker.set_route("/_web/" + username + "/" + clustername, target)
worker.set_route("/"+ clusterinfo['proxy_server_ip'] + "/_web/" + username + "/" + clustername, target)
else:
proxytool.set_route("/_web/" + username + "/" + clustername, target)
proxytool.set_route("/" + clusterinfo['proxy_server_ip'] + "/_web/" + username + "/" + clustername, target)
clusterfile = open(self.fspath + "/global/users/" + username + "/clusters/" + clustername, 'w')
clusterfile.write(json.dumps(clusterinfo))
clusterfile.close()
@ -206,11 +206,11 @@ class VclusterMgr(object):
if 'proxy_ip' not in clusterinfo:
return [True, clusterinfo]
clusterinfo.pop('proxy_ip')
if not clusterinfo['proxy_server_ip'] == self.addr:
if self.distributedgw == 'True':
worker = self.nodemgr.ip_to_rpc(clusterinfo['proxy_server_ip'])
worker.delete_route("/_web/" + username + "/" + clustername)
worker.delete_route("/" + clusterinfo['proxy_server_ip'] + "/_web/" + username + "/" + clustername)
else:
proxytool.delete_route("/_web/" + username + "/" + clustername)
proxytool.delete_route("/" + clusterinfo['proxy_server_ip'] + "/_web/" + username + "/" + clustername)
clusterfile = open(self.fspath + "/global/users/" + username + "/clusters/" + clustername, 'w')
clusterfile.write(json.dumps(clusterinfo))
clusterfile.close()
@ -365,16 +365,13 @@ class VclusterMgr(object):
# so, check is necessary
self.networkmgr.check_usergw(username, self.nodemgr,self.distributedgw=='True')
# set proxy
if (not info['proxy_server_ip'] == self.addr) and (self.distributedgw == 'False'):
info['proxy_server_ip'] = self.addr
info['proxy_url'] = env.getenv("PORTAL_URL") +"/"+ self.addr +"/_web/" + username + "/" + clustername
try:
target = 'http://'+info['containers'][0]['ip'].split('/')[0]+":10000"
if not info['proxy_server_ip'] == self.addr:
if self.distributedgw == 'True':
worker = self.nodemgr.ip_to_rpc(info['proxy_server_ip'])
worker.set_route('/go/'+username+'/'+clustername, target)
worker.set_route("/" + info['proxy_server_ip'] + '/go/'+username+'/'+clustername, target)
else:
proxytool.set_route('/go/'+username+'/'+clustername, target)
proxytool.set_route("/" + info['proxy_server_ip'] + '/go/'+username+'/'+clustername, target)
except:
return [False, "start cluster failed with setting proxy failed"]
for container in info['containers']:
@ -408,17 +405,13 @@ class VclusterMgr(object):
# need to check and recover gateway of this user
self.networkmgr.check_usergw(username, self.nodemgr,self.distributedgw=='True')
# recover proxy of cluster
if (not info['proxy_server_ip'] == self.addr) and (self.distributedgw == 'False'):
info['proxy_server_ip'] = self.addr
info['proxy_url'] = env.getenv("PORTAL_URL") +"/"+ self.addr +"/_web/" + username + "/" + clustername
self.write_clusterinfo(info,clustername,username)
try:
target = 'http://'+info['containers'][0]['ip'].split('/')[0]+":10000"
if not info['proxy_server_ip'] == self.addr:
if self.distributedgw == 'True':
worker = self.nodemgr.ip_to_rpc(info['proxy_server_ip'])
worker.set_route('/go/'+username+'/'+clustername, target)
worker.set_route("/" + info['proxy_server_ip'] + '/go/'+username+'/'+clustername, target)
else:
proxytool.set_route('/go/'+username+'/'+clustername, target)
proxytool.set_route("/" + info['proxy_server_ip'] + '/go/'+username+'/'+clustername, target)
except:
return [False, "start cluster failed with setting proxy failed"]
# recover containers of this cluster
@ -436,11 +429,11 @@ class VclusterMgr(object):
return [False, "cluster not found"]
if info['status'] == 'stopped':
return [False, 'cluster is already stopped']
if not info['proxy_server_ip'] == self.addr:
if self.distributedgw == 'True':
worker = self.nodemgr.ip_to_rpc(info['proxy_server_ip'])
worker.delete_route('/go/'+username+'/'+clustername)
worker.delete_route("/" + info['proxy_server_ip'] + '/go/'+username+'/'+clustername)
else:
proxytool.delete_route('/go/'+username+'/'+clustername)
proxytool.delete_route("/" + info['proxy_server_ip'] + '/go/'+username+'/'+clustername)
for container in info['containers']:
worker = self.nodemgr.ip_to_rpc(container['host'])
if worker is None:

View File

@ -15,6 +15,13 @@ echo "copy nginx_docklet.conf to nginx config path..."
cp ../conf/nginx_docklet.conf ${NGINX_CONF}/
sed -i "s/%MASTER_IP/${MASTER_IP}/g" ${NGINX_CONF}/nginx_docklet.conf
sed -i "s/%NGINX_PORT/${NGINX_PORT}/g" ${NGINX_CONF}/nginx_docklet.conf
if [ "${DISTRIBUTED_GATEWAY}" = "True" ]
then
sed -i "s/%PROXY_SERVER_IP/\$1/g" ${NGINX_CONF}/nginx_docklet.conf
else
sed -i "s/%PROXY_SERVER_IP/${MASTER_IP}/g" ${NGINX_CONF}/nginx_docklet.conf
fi
sed -i "s/%PROXY_PORT/${PROXY_PORT}/g" ${NGINX_CONF}/nginx_docklet.conf
sed -i "s/%WEB_PORT/${WEB_PORT}/g" ${NGINX_CONF}/nginx_docklet.conf