From a18398dfb6a5ffb021d78789eb2253259c71bfe5 Mon Sep 17 00:00:00 2001 From: zhuyj17 Date: Tue, 16 May 2017 11:15:23 +0800 Subject: [PATCH] add a script to update network in container config --- tools/update_con_network.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/update_con_network.py b/tools/update_con_network.py index 6a522b1..0400893 100644 --- a/tools/update_con_network.py +++ b/tools/update_con_network.py @@ -1,8 +1,26 @@ - - +import sys,os +sys.path.append("../src/") +import env,requests userpoint = "http://" + env.getenv('USER_IP') + ":" + str(env.getenv('USER_PORT')) G_userip = env.getenv("USER_IP") +auth_key = env.getenv('AUTH_KEY') def post_to_user(url = '/', data={}): return requests.post(userpoint+url,data=data).json() + +cons = os.listdir('/var/lib/lxc') +for con in cons: + print("Update %s..."%(con)) + namesplit = con.split('-') + user = namesplit[0] + res = post_to_user('/user/uid/',{'username':user,'auth_key':auth_key}) + configfile = open('/var/lib/lxc/'+con+'/config','r') + context = configfile.read() + configfile.close() + #print(context) + #print(res['uid']) + context = context.replace("docklet-br","docklet-br-"+str(res['uid'])) + newfile = open('/var/lib/lxc/'+con+'/config','w') + newfile.write(context) + newfile.close()