add a script to update network in container config

This commit is contained in:
zhuyj17 2017-05-16 11:15:23 +08:00
parent 08c5c780c0
commit a18398dfb6
1 changed files with 20 additions and 2 deletions

View File

@ -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()