rpc_key_test.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import rpyc
  2. import time
  3. import schedule
  4. #s1={'ip':'192.168.192.199','names':['poi1','poi2']}
  5. s2={'ip':'192.168.192.58','names':['poi1','poi2']}
  6. s3={'ip':'192.168.192.146','names':['poi1','poi2']}
  7. s4={'ip':'192.168.192.45','names':['poi1','poi2']}
  8. s5={'ip':'192.168.192.156','names':['hhhclick1','hhhclick2','seo1','seo2']}
  9. s6={'ip':'192.168.192.9','names':['poi1','poi2','poi3']}
  10. servers=[s2,s3,s4,s5,s6]
  11. #servers=[s1,s2,s3,s4,s5,s6]
  12. #conn = rpyc.ssl_connect("192.168.192.199", port = 18812, keyfile="c:/tmp/client.key",
  13. # certfile="c:/tmp/client.cer")
  14. def do_job():
  15. global servers
  16. for srv in servers:
  17. print(srv['ip'])
  18. conn = rpyc.classic.connect(srv['ip'], port = 18812)
  19. ros=conn.modules.os
  20. conn.execute('import docker')
  21. rdocker=conn.modules.docker
  22. client = rdocker.from_env()
  23. lst=client.containers.list()
  24. cur_names=[]
  25. for l in lst:
  26. cur_names.append(l.name)
  27. for n in srv['names']:
  28. if n not in cur_names:
  29. print("calling: " +n)
  30. ros.system('docker container restart '+n)
  31. do_job()
  32. schedule.every(3).minutes.do(do_job)
  33. while True:
  34. schedule.run_pending()
  35. time.sleep(1)