save usrgw in etcd
This commit is contained in:
parent
84b12317a1
commit
468adef76a
|
@ -391,6 +391,14 @@ class NetworkMgr(object):
|
|||
def dump_user(self, username):
|
||||
self.etcd.setkey("network/users/"+username, json.dumps({'info':self.users[username].info, 'vlanid':self.users[username].vlanid, 'gateway':self.users[username].gateway, 'pool':self.users[username].pool}))
|
||||
|
||||
def load_usrgw(self,username):
|
||||
[status, data] = self.etcd.getkey("network/usergws/"+username)
|
||||
if status:
|
||||
self.usergws[username] = data
|
||||
|
||||
def dump_usrgw(self, username):
|
||||
self.etcd.setkey("network/usrgws/"+username, self.usrgws[username])
|
||||
|
||||
def printpools(self):
|
||||
print ("<Center>")
|
||||
self.center.printpool()
|
||||
|
@ -439,11 +447,13 @@ class NetworkMgr(object):
|
|||
return [True, "Release VLAN ID success"]
|
||||
|
||||
def has_usrgw(self, username):
|
||||
self.load_usrgw(username)
|
||||
return username in self.usrgws.keys()
|
||||
|
||||
def setup_usrgw(self, username, nodemgr, worker=None):
|
||||
if not self.has_user(username):
|
||||
return [False,"user doesn't exist."]
|
||||
self.load_usrgw(username)
|
||||
if username in self.usrgws.keys():
|
||||
return [False,"user's gateway has been set up."]
|
||||
self.load_user(username)
|
||||
|
@ -452,10 +462,12 @@ class NetworkMgr(object):
|
|||
ip = nodemgr.rpc_to_ip(worker)
|
||||
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)
|
||||
worker.setup_gw('docklet-br', username, usrpools.get_gateway_cidr(), str(usrpools.vlanid))
|
||||
else:
|
||||
logger.info("setup gateway for %s with %s and vlan=%s on master" % (username, usrpools.get_gateway_cidr(), str(usrpools.vlanid)))
|
||||
self.usrgws[username] = self.masterip
|
||||
self.dump_usrgw(username)
|
||||
netcontrol.setup_gw('docklet-br', username, usrpools.get_gateway_cidr(), str(usrpools.vlanid))
|
||||
self.dump_user(username)
|
||||
del self.users[username]
|
||||
|
@ -493,6 +505,7 @@ class NetworkMgr(object):
|
|||
worker = nodemgr.ip_to_rpc(ip)
|
||||
worker.del_gw('docklet-br', username)
|
||||
del self.usrgws[username]
|
||||
self.etcd.delkey("network/usrgws/"+username)
|
||||
return [True, 'delete user\' gateway success']
|
||||
|
||||
def del_user(self, username, isshared = False):
|
||||
|
@ -511,6 +524,7 @@ class NetworkMgr(object):
|
|||
return [True, 'delete user success']
|
||||
|
||||
def check_usergw(self, username, nodemgr):
|
||||
self.load_usrgw(username)
|
||||
if username not in self.usrgws.keys():
|
||||
return [False, 'user does not exist.']
|
||||
ip = self.usrgws[username]
|
||||
|
|
|
@ -120,6 +120,7 @@ class VclusterMgr(object):
|
|||
if not success:
|
||||
return [False, message]
|
||||
if i == 0:
|
||||
self.networkmgr.load_usrgw(username)
|
||||
proxy_server_ip = self.networkmgr.usrgws[username]
|
||||
lxc_name = username + "-" + str(clusterid) + "-" + str(i)
|
||||
hostname = "host-"+str(i)
|
||||
|
@ -391,7 +392,7 @@ class VclusterMgr(object):
|
|||
try:
|
||||
target = 'http://'+info['containers'][0]['ip'].split('/')[0]+":10000"
|
||||
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)
|
||||
except:
|
||||
return [False, "start cluster failed with setting proxy failed"]
|
||||
# recover containers of this cluster
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block script_src %}
|
||||
|
||||
<script src="//cdn.bootcss.com/jquery/2.2.1/jquery.min.js"></script>
|
||||
<script src="http://cdn.bootcss.com/datatables/1.10.11/js/jquery.dataTables.js"></script>
|
||||
<script src="http://cdn.bootcss.com/datatables/1.10.11/js/dataTables.bootstrap.js"></script>
|
||||
<script src="http://cdn.bootcss.com/datatables-tabletools/2.1.5/js/TableTools.min.js"></script>
|
||||
|
|
Loading…
Reference in New Issue