Skip to content

Commit

Permalink
some docker functions
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Dec 27, 2023
1 parent 2832254 commit d901b59
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
53 changes: 52 additions & 1 deletion dockerManager/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions plogical/DockerSites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d901b59

Please sign in to comment.