2017-05-16 11:15:23 +08:00
|
|
|
import sys,os
|
|
|
|
sys.path.append("../src/")
|
|
|
|
import env,requests
|
2017-05-16 10:10:09 +08:00
|
|
|
|
2017-05-19 22:11:00 +08:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print("Please enter USER_IP")
|
|
|
|
exit()
|
|
|
|
|
|
|
|
userpoint = "http://" + sys.argv[1] + ":" + str(env.getenv('USER_PORT'))
|
2017-05-16 11:15:23 +08:00
|
|
|
auth_key = env.getenv('AUTH_KEY')
|
2017-05-16 10:10:09 +08:00
|
|
|
|
|
|
|
def post_to_user(url = '/', data={}):
|
|
|
|
return requests.post(userpoint+url,data=data).json()
|
2017-05-16 11:15:23 +08:00
|
|
|
|
|
|
|
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})
|
2017-05-19 22:11:00 +08:00
|
|
|
try:
|
|
|
|
configfile = open('/var/lib/lxc/'+con+'/config','r')
|
|
|
|
except:
|
|
|
|
continue
|
2017-05-16 11:15:23 +08:00
|
|
|
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()
|