mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 21:35:55 +01:00
some docker functions
This commit is contained in:
@@ -1175,7 +1175,6 @@ class ContainerManager(multi.Thread):
|
||||
if admin.acl.adminStatus != 1:
|
||||
return ACLManager.loadError()
|
||||
|
||||
|
||||
name = data['name']
|
||||
WPusername = data['WPusername']
|
||||
WPemail = data['WPemail']
|
||||
@@ -1207,6 +1206,58 @@ class ContainerManager(multi.Thread):
|
||||
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)
|
||||
|
||||
@@ -555,6 +555,38 @@ services:
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user