From d901b59b648e6b1131deaa0ba496df7a9e81ad1c Mon Sep 17 00:00:00 2001 From: usmannasir Date: Wed, 27 Dec 2023 18:41:53 +0500 Subject: [PATCH] some docker functions --- dockerManager/container.py | 53 +++++++++++++++++++++++++++++++++++++- plogical/DockerSites.py | 32 +++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/dockerManager/container.py b/dockerManager/container.py index 71ddacc26..b03feeda7 100755 --- a/dockerManager/container.py +++ b/dockerManager/container.py @@ -1175,7 +1175,6 @@ def recreateappcontainer(self, userID=None, data=None): if admin.acl.adminStatus != 1: return ACLManager.loadError() - name = data['name'] WPusername = data['WPusername'] WPemail = data['WPemail'] @@ -1207,6 +1206,58 @@ def recreateappcontainer(self, userID=None, data=None): json_data = json.dumps(data_ret) return HttpResponse(json_data) + except BaseException as msg: + data_ret = {'removeImageStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + def RestartContainerAPP(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + + if admin.acl.adminStatus != 1: + return ACLManager.loadError() + + name = data['name'] + containerID = data['id'] + + passdata = {} + passdata['containerID'] = containerID + + da = Docker_Sites(None, passdata) + retdata = da.RestartContainer() + + + data_ret = {'status': 1, 'error_message': 'None', 'data':retdata} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException as msg: + data_ret = {'removeImageStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + def StopContainerAPP(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + + if admin.acl.adminStatus != 1: + return ACLManager.loadError() + + name = data['name'] + containerID = data['id'] + + passdata = {} + passdata['containerID'] = containerID + + da = Docker_Sites(None, passdata) + retdata = da.StopContainer() + + + data_ret = {'status': 1, 'error_message': 'None', 'data':retdata} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException as msg: data_ret = {'removeImageStatus': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) diff --git a/plogical/DockerSites.py b/plogical/DockerSites.py index 0fd816b88..2e4106184 100644 --- a/plogical/DockerSites.py +++ b/plogical/DockerSites.py @@ -555,6 +555,38 @@ def RebuildApp(self): self.DeleteDockerApp() self.SubmitDockersiteCreation() + def RestartContainer(self): + try: + import docker + # Create a Docker client + client = docker.from_env() + + # Get the container by ID + container = client.containers.get(self.data['containerID']) + + container.restart() + + return 1, None + except BaseException as msg: + logging.writeToFile("List Container ....... %s" % str(msg)) + return 0, str(msg) + + def StopContainer(self): + try: + import docker + # Create a Docker client + client = docker.from_env() + + # Get the container by ID + container = client.containers.get(self.data['containerID']) + + container.stop() + + return 1, None + except BaseException as msg: + logging.writeToFile("List Container ....... %s" % str(msg)) + return 0, str(msg) + ##### N8N Container def DeployN8NContainer(self):