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:
|
if admin.acl.adminStatus != 1:
|
||||||
return ACLManager.loadError()
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
|
||||||
name = data['name']
|
name = data['name']
|
||||||
WPusername = data['WPusername']
|
WPusername = data['WPusername']
|
||||||
WPemail = data['WPemail']
|
WPemail = data['WPemail']
|
||||||
@@ -1211,3 +1210,55 @@ class ContainerManager(multi.Thread):
|
|||||||
data_ret = {'removeImageStatus': 0, 'error_message': str(msg)}
|
data_ret = {'removeImageStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
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)
|
||||||
|
return HttpResponse(json_data)
|
||||||
@@ -555,6 +555,38 @@ services:
|
|||||||
self.DeleteDockerApp()
|
self.DeleteDockerApp()
|
||||||
self.SubmitDockersiteCreation()
|
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
|
##### N8N Container
|
||||||
|
|
||||||
def DeployN8NContainer(self):
|
def DeployN8NContainer(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user