Command.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from hub import methods, Global
  2. class Command(object):
  3. @classmethod
  4. def cmd001(cls, **params):
  5. """
  6. url:
  7. http://192.168.30.13:8892/api?module=Command&method=cmd001&version_id=d986be1
  8. http://192.168.1.33:8892/api?module=Command&method=cmd001&version_id=d986be1
  9. cmd:
  10. echo "版本:2021年4月13日 13:58:11" \
  11. && version_id="2d796e9" \
  12. && image_name="39.99.150.29:9999/aibox-component-dashboard-packer:1.0.1" \
  13. && script_dir="/home/server/projects/taiwuict/taiwuict-aibox/developer-operation/l1" \
  14. && sudo docker run --interactive --volume /home:/home ${image_name} /bin/bash ${script_dir}/deployer-update_by_commit.sh ${version_id} \
  15. && sudo bash ${script_dir}/07.restart_service.sh
  16. """
  17. version_id = params.get('version_id')
  18. ssh = SSHClient('172.18.0.1', 22, 'server', 'server')
  19. command = str()
  20. command += f"version_id=\"{version_id}\""
  21. command += f" && "
  22. command += f"image_name=\"39.99.150.29:9999/aibox-component-dashboard-packer:1.0.1\""
  23. command += f" && "
  24. command += f"script_dir=\"/home/server/projects/taiwuict/taiwuict-aibox/developer-operation/l1\""
  25. command += f" && "
  26. command += r"sudo docker login -u admin -p admin http://39.99.150.29:9999"
  27. command += f" && "
  28. command += r"sudo docker run --interactive --volume /home:/home ${image_name} /bin/bash "
  29. command += r"${script_dir}/deployer-update_by_commit.sh ${version_id}"
  30. command += f" && "
  31. command += r"sudo bash ${script_dir}/07.restart_service.sh"
  32. command += f" && "
  33. command += r"sudo chmod -R 777 /home/server/projects/taiwuict/taiwuict-aibox"
  34. methods.debug_log(f"Command.cmd001", f"1: {command}")
  35. ssh.run_command(command)
  36. return dict(code=0)
  37. @classmethod
  38. def cmd002(cls, **params):
  39. """
  40. url:
  41. http://192.168.30.14:8892/api?module=Command&method=cmd002
  42. cmd:
  43. echo "版本:2021年4月13日 13:58:11" \
  44. && image_name="39.99.150.29:9999/aibox-component-dashboard-packer:1.0.1" \
  45. && script_dir="/home/server/projects/taiwuict/taiwuict-aibox/developer-operation/l1" \
  46. && sudo docker run --interactive --volume /home:/home ${image_name} /bin/bash ${script_dir}/deployer-update_pth.sh \
  47. && sudo docker restart node_yolo
  48. """
  49. ssh = Global.SSHClient('172.18.0.1', 22, 'server', 'server')
  50. command = str()
  51. command += f"image_name=\"39.99.150.29:9999/aibox-component-dashboard-packer:1.0.1\""
  52. command += f" && "
  53. command += f"script_dir=\"/home/server/projects/taiwuict/taiwuict-aibox/developer-operation/l1\""
  54. command += f" && "
  55. command += r"sudo docker login -u admin -p admin http://39.99.150.29:9999"
  56. command += f" && "
  57. command += r"sudo docker run --interactive --volume /home:/home ${image_name} /bin/bash "
  58. command += r"${script_dir}/deployer-update_pth.sh"
  59. command += f" && "
  60. command += r"sudo docker restart node_yolo"
  61. methods.debug_log(f"Command.cmd002", f"1: {command}")
  62. ssh.run_command(command)
  63. return dict(code=0)