Merge branch 'master' of https://github.com/unias/docklet into network

This commit is contained in:
zhuyj17 2017-05-08 16:40:13 +08:00
commit 76dc8754e2
3 changed files with 11 additions and 6 deletions

View File

@ -450,7 +450,7 @@ class NetworkMgr(object):
self.load_usrgw(username)
return username in self.usrgws.keys()
def setup_usrgw(self, username, nodemgr, worker=None):
def setup_usrgw(self, username, nodemgr, workerip=None):
if not self.has_user(username):
return [False,"user doesn't exist."]
self.load_usrgw(username)
@ -458,8 +458,9 @@ class NetworkMgr(object):
return [False,"user's gateway has been set up."]
self.load_user(username)
usrpools = self.users[username]
if(worker is not None):
ip = nodemgr.rpc_to_ip(worker)
if(workerip is not None):
ip = workerip
worker = nodemgr.ip_to_rpc(workerip)
logger.info("setup gateway for %s with %s and vlan=%s on %s" % (username, usrpools.get_gateway_cidr(), str(usrpools.vlanid), ip))
self.usrgws[username] = ip
self.dump_usrgw(username)

View File

@ -145,3 +145,7 @@ class NodeMgr(object):
def get_allnodes(self):
return self.allnodes
def ip_to_rpc(self,ip):
return xmlrpc.client.ServerProxy("http://%s:%s" % (ip, env.getenv("WORKER_PORT")))

View File

@ -115,8 +115,10 @@ class VclusterMgr(object):
proxy_server_ip = ""
containers = []
for i in range(0, clustersize):
workerip = workers[random.randint(0, len(workers)-1)]
oneworker = xmlrpc.client.ServerProxy("http://%s:%s" % (workerip, env.getenv("WORKER_PORT")))
if self.distributedgw == "True" and i == 0 and not self.networkmgr.has_usrgw(username):
[success,message] = self.networkmgr.setup_usrgw(username, self.nodemgr, onework)
[success,message] = self.networkmgr.setup_usrgw(username, self.nodemgr, workerip)
if not success:
return [False, message]
if i == 0:
@ -125,8 +127,6 @@ class VclusterMgr(object):
lxc_name = username + "-" + str(clusterid) + "-" + str(i)
hostname = "host-"+str(i)
logger.info ("create container with : name-%s, username-%s, clustername-%s, clusterid-%s, hostname-%s, ip-%s, gateway-%s, image-%s" % (lxc_name, username, clustername, str(clusterid), hostname, ips[i], gateway, image_json))
workerip = workers[random.randint(0, len(workers)-1)]
oneworker = xmlrpc.client.ServerProxy("http://%s:%s" % (workerip, env.getenv("WORKER_PORT")))
[success,message] = oneworker.create_container(lxc_name, proxy_server_ip, username, json.dumps(setting) , clustername, str(clusterid), str(i), hostname, ips[i], gateway, str(vlanid), image_json)
if success is False:
logger.info("container create failed, so vcluster create failed")