1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import rpyc
- import time
- import schedule
- import traceback
- #s1={'ip':'192.168.192.199','names':['poi1','poi2','poi3','poi4']} #MBA_HOME
- s1={'ip':'192.168.192.199','names':['poi1']} #MBA_HOME
- #s2={'ip':'192.168.192.58','names':['poi1','poi2','poi3']} #RDP_HOME
- #s3={'ip':'192.168.192.146','names':['poi1','poi2']} #TOSHIBA
- s3={'ip':'192.168.192.146','names':['poi1']} #TOSHIBA
- s4={'ip':'192.168.192.45','names':['poi1','poi2','poi3']} #public1
- #s5={'ip':'192.168.192.156','names':['seo1','seo2']} #32g
- s5={'ip':'192.168.192.156','names':['poi1']} #32g
- #s5={'ip':'192.168.192.156','names':['poi1','poi2','poi3','poi4','poi5','poi6']} #32g
- #s5={'ip':'192.168.192.156','names':['hhhclick1','hhhclick2','seo1','seo2']}
- #s6={'ip':'192.168.192.9','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14','poi15','poi16']} #64G
- #s6={'ip':'192.168.192.9','names':['poi1','poi2','poi3','poi4','poi5']} #64G
- s6={'ip':'192.168.192.9','names':['poi1']} #64G
- s7={'ip':'192.168.192.139','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14','poi15','poi16']} #alston1
- s8={'ip':'192.168.192.43','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14','poi15','poi16']} #alston2
- #servers=[s1,s2,s4,s5,s6]
- servers=[s1,s3,s5,s6,s7,s8]
- #servers=[s1,s2,s3,s4,s5,s6]
- #conn = rpyc.ssl_connect("192.168.192.199", port = 18812, keyfile="c:/tmp/client.key",
- # certfile="c:/tmp/client.cer")
- def do_job():
- global servers
- cnt=0
- for srv in servers:
- print(srv['ip'])
- conn=None
- try:
- conn = rpyc.classic.connect(srv['ip'], port = 18812)
- except:
- print('exception')
- continue
- ros=conn.modules.os
- conn.execute('import docker')
- rdocker=conn.modules.docker
- client = rdocker.from_env()
- lst=client.containers.list()
- cur_names=[]
- for l in lst:
- cur_names.append(l.name)
- for n in srv['names']:
- if n not in cur_names:
- print("calling: " +n)
- ros.system('docker container restart '+n)
- else:
- cnt+=1
- print('cnt='+str(cnt))
- print('cnt='+str(cnt))
- do_job()
- schedule.every(3).minutes.do(do_job)
- while True:
- try:
- schedule.run_pending()
- except:
- traceback.print_exc()
- time.sleep(1)
|