github.com/annchain/OG@v0.0.9/scripts/deploy/broadcast_file.py (about) 1 import datetime 2 import json 3 import subprocess 4 import time 5 6 import requests 7 8 from common import hosts 9 10 LOCAL_ROOT_FOLDER = '/ws/go/src/github.com/annchain/OG/build/' 11 REMOTE_ROOT_FOLDER = '/home/admin/sync/' 12 files = ['og'] 13 USER = 'admin' 14 ROOT_IP = '172.28.152.12' 15 MGMT_PORT = 45000 16 17 target_hosts = hosts.hosts('data/hosts') 18 # target_hosts = [ 19 # '172.28.152.25' 20 # ] 21 22 s = requests.Session() 23 s.trust_env = False 24 s.auth = ('gofd', 'gofd') 25 26 27 def wait_done(tid): 28 while True: 29 resp = s.get('http://%s:%d/api/v1/server/tasks/' % (ROOT_IP, MGMT_PORT) + tid) 30 j = json.loads(resp.text) 31 if j['status'] == 'COMPLETED': 32 print('Completed') 33 break 34 for host, status in j['dispatchInfos'].items(): 35 print(host, status['status'], status['percentComplete']) 36 print() 37 time.sleep(1) 38 39 40 def announce_task(): 41 j = {"id": datetime.datetime.now().strftime('%Y%m%d%H%M%S'), 42 "dispatchFiles": [REMOTE_ROOT_FOLDER + x for x in files], 43 "destIPs": target_hosts 44 } 45 46 resp = s.post('http://%s:%d/api/v1/server/tasks' % (ROOT_IP, MGMT_PORT), data=json.dumps(j), 47 headers={"Content-type": "application/json"}) 48 49 print(resp.status_code, j['id']) 50 return j['id'] 51 52 53 if __name__ == '__main__': 54 for file in files: 55 p = "rsync -aP %s %s@%s:%s" % (LOCAL_ROOT_FOLDER + file, USER, ROOT_IP, REMOTE_ROOT_FOLDER) 56 print(subprocess.run(p, shell=True, check=True)) 57 print('Seed ready') 58 59 tid = announce_task() 60 wait_done(tid)