from hub import methods, Global class Command(object): @classmethod def cmd001(cls, **params): """ url: http://192.168.30.13:8892/api?module=Command&method=cmd001&version_id=d986be1 http://192.168.1.33:8892/api?module=Command&method=cmd001&version_id=d986be1 cmd: echo "版本:2021年4月13日 13:58:11" \ && version_id="2d796e9" \ && image_name="39.99.150.29:9999/aibox-component-dashboard-packer:1.0.1" \ && script_dir="/home/server/projects/taiwuict/taiwuict-aibox/developer-operation/l1" \ && sudo docker run --interactive --volume /home:/home ${image_name} /bin/bash ${script_dir}/deployer-update_by_commit.sh ${version_id} \ && sudo bash ${script_dir}/07.restart_service.sh """ version_id = params.get('version_id') ssh = SSHClient('172.18.0.1', 22, 'server', 'server') command = str() command += f"version_id=\"{version_id}\"" command += f" && " command += f"image_name=\"39.99.150.29:9999/aibox-component-dashboard-packer:1.0.1\"" command += f" && " command += f"script_dir=\"/home/server/projects/taiwuict/taiwuict-aibox/developer-operation/l1\"" command += f" && " command += r"sudo docker login -u admin -p admin http://39.99.150.29:9999" command += f" && " command += r"sudo docker run --interactive --volume /home:/home ${image_name} /bin/bash " command += r"${script_dir}/deployer-update_by_commit.sh ${version_id}" command += f" && " command += r"sudo bash ${script_dir}/07.restart_service.sh" command += f" && " command += r"sudo chmod -R 777 /home/server/projects/taiwuict/taiwuict-aibox" methods.debug_log(f"Command.cmd001", f"1: {command}") ssh.run_command(command) return dict(code=0) @classmethod def cmd002(cls, **params): """ url: http://192.168.30.14:8892/api?module=Command&method=cmd002 cmd: echo "版本:2021年4月13日 13:58:11" \ && image_name="39.99.150.29:9999/aibox-component-dashboard-packer:1.0.1" \ && script_dir="/home/server/projects/taiwuict/taiwuict-aibox/developer-operation/l1" \ && sudo docker run --interactive --volume /home:/home ${image_name} /bin/bash ${script_dir}/deployer-update_pth.sh \ && sudo docker restart node_yolo """ ssh = Global.SSHClient('172.18.0.1', 22, 'server', 'server') command = str() command += f"image_name=\"39.99.150.29:9999/aibox-component-dashboard-packer:1.0.1\"" command += f" && " command += f"script_dir=\"/home/server/projects/taiwuict/taiwuict-aibox/developer-operation/l1\"" command += f" && " command += r"sudo docker login -u admin -p admin http://39.99.150.29:9999" command += f" && " command += r"sudo docker run --interactive --volume /home:/home ${image_name} /bin/bash " command += r"${script_dir}/deployer-update_pth.sh" command += f" && " command += r"sudo docker restart node_yolo" methods.debug_log(f"Command.cmd002", f"1: {command}") ssh.run_command(command) return dict(code=0)