rpc_key_test.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import rpyc
  2. import time
  3. import schedule
  4. import traceback
  5. #s1={'ip':'192.168.192.199','names':['poi1','poi2','poi3','poi4']} #MBA_HOME
  6. s1={'ip':'192.168.192.199','names':['poi1']} #MBA_HOME
  7. #s2={'ip':'192.168.192.58','names':['poi1','poi2','poi3']} #RDP_HOME
  8. #s3={'ip':'192.168.192.146','names':['poi1','poi2']} #TOSHIBA
  9. s3={'ip':'192.168.192.146','names':['poi1']} #TOSHIBA
  10. s4={'ip':'192.168.192.45','names':['poi1','poi2','poi3']} #public1
  11. #s5={'ip':'192.168.192.156','names':['seo1','seo2']} #32g
  12. s5={'ip':'192.168.192.156','names':['poi1']} #32g
  13. #s5={'ip':'192.168.192.156','names':['poi1','poi2','poi3','poi4','poi5','poi6']} #32g
  14. #s5={'ip':'192.168.192.156','names':['hhhclick1','hhhclick2','seo1','seo2']}
  15. #s6={'ip':'192.168.192.9','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14','poi15','poi16']} #64G
  16. #s6={'ip':'192.168.192.9','names':['poi1','poi2','poi3','poi4','poi5']} #64G
  17. s6={'ip':'192.168.192.9','names':['poi1']} #64G
  18. s7={'ip':'192.168.192.139','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14','poi15','poi16']} #alston1
  19. s8={'ip':'192.168.192.43','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14','poi15','poi16']} #alston2
  20. #servers=[s1,s2,s4,s5,s6]
  21. servers=[s1,s3,s5,s6,s7,s8]
  22. #servers=[s1,s2,s3,s4,s5,s6]
  23. #conn = rpyc.ssl_connect("192.168.192.199", port = 18812, keyfile="c:/tmp/client.key",
  24. # certfile="c:/tmp/client.cer")
  25. def do_job():
  26. global servers
  27. cnt=0
  28. for srv in servers:
  29. print(srv['ip'])
  30. conn=None
  31. try:
  32. conn = rpyc.classic.connect(srv['ip'], port = 18812)
  33. except:
  34. print('exception')
  35. continue
  36. ros=conn.modules.os
  37. conn.execute('import docker')
  38. rdocker=conn.modules.docker
  39. client = rdocker.from_env()
  40. lst=client.containers.list()
  41. cur_names=[]
  42. for l in lst:
  43. cur_names.append(l.name)
  44. for n in srv['names']:
  45. if n not in cur_names:
  46. print("calling: " +n)
  47. ros.system('docker container restart '+n)
  48. else:
  49. cnt+=1
  50. print('cnt='+str(cnt))
  51. print('cnt='+str(cnt))
  52. do_job()
  53. schedule.every(3).minutes.do(do_job)
  54. while True:
  55. try:
  56. schedule.run_pending()
  57. except:
  58. traceback.print_exc()
  59. time.sleep(1)