Skip to content

Commit

Permalink
restart fun and stop function added
Browse files Browse the repository at this point in the history
  • Loading branch information
hassanhashmey committed Dec 28, 2023
1 parent 854798a commit 8c2a2f5
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 4 deletions.
2 changes: 2 additions & 0 deletions dockerManager/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
path('getContainerAppinfo', views.getContainerAppinfo, name='getContainerAppinfo'),
path('getContainerApplog', views.getContainerApplog, name='getContainerApplog'),
path('recreateappcontainer', views.recreateappcontainer, name='recreateappcontainer'),
path('RestartContainerAPP', views.RestartContainerAPP, name='RestartContainerAPP'),
path('StopContainerAPP', views.StopContainerAPP, name='StopContainerAPP'),
]
38 changes: 38 additions & 0 deletions dockerManager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,44 @@ def recreateappcontainer(request):
cm = ContainerManager()
coreResult = cm.recreateappcontainer(userID, json.loads(request.body))

return coreResult
except KeyError:
return redirect(loadLoginPage)


@preDockerRun
def RestartContainerAPP(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)

if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson()

cm = ContainerManager()
coreResult = cm.RestartContainerAPP(userID, json.loads(request.body))

return coreResult
except KeyError:
return redirect(loadLoginPage)


@preDockerRun
def StopContainerAPP(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)

if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson()

cm = ContainerManager()
coreResult = cm.StopContainerAPP(userID, json.loads(request.body))

return coreResult
except KeyError:
return redirect(loadLoginPage)
111 changes: 109 additions & 2 deletions websiteFunctions/static/websiteFunctions/websiteFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10587,8 +10587,6 @@ app.controller('ListDockersitecontainer', function ($scope, $http) {
$scope.cyberPanelLoading = true;




$scope.Lunchcontainer = function (containerid) {
// $scope.listcontainerview = true
$scope.cyberpanelLoading = false
Expand Down Expand Up @@ -10759,7 +10757,9 @@ app.controller('ListDockersitecontainer', function ($scope, $http) {
}
}


$scope.refreshStatus = function () {
$('#actionLoading').show();
url = "/docker/getContainerStatus";
var data = {name: $scope.cName};
var config = {
Expand All @@ -10771,6 +10771,7 @@ app.controller('ListDockersitecontainer', function ($scope, $http) {
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);

function ListInitialData(response) {
$('#actionLoading').hide();
if (response.data.containerStatus === 1) {
console.log(response.data.status);
$scope.status = response.data.status;
Expand All @@ -10785,6 +10786,112 @@ app.controller('ListDockersitecontainer', function ($scope, $http) {
}

function cantLoadInitialData(response) {
$('#actionLoading').hide();
PNotify.error({
title: 'Unable to complete request',
text: "Problem in connecting to server"
});
}

};

$scope.restarthStatus = function () {
$('#actionLoading').show();
url = "/docker/RestartContainerAPP";
var data = {
name: $scope.cName,
id: $scope.cid
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};

$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);

function ListInitialData(response) {
$('#actionLoading').hide();
if (response.data.status === 1) {
if (response.data.data[0] === 1) {
new PNotify({
title: 'Success!',
text: 'Action completed',
type: 'success'
});
$scope.Lunchcontainer($scope.cid);
} else {
new PNotify({
title: 'Error!',
text: response.data.data[1],
type: 'error'
});
}
} else {
new PNotify({
title: 'Unable to complete request',
text: response.data.error_message,
type: 'error'
});

}
}

function cantLoadInitialData(response) {
$('#actionLoading').hide();
PNotify.error({
title: 'Unable to complete request',
text: "Problem in connecting to server"
});
}

};
$scope.StopContainerAPP = function () {
$('#actionLoading').show();
url = "/docker/StopContainerAPP";
var data = {
name: $scope.cName,
id: $scope.cid
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};

$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);

function ListInitialData(response) {
$('#actionLoading').hide();
if (response.data.status === 1) {
console.log(response.data.status);
if (response.data.data[0] === 1) {
new PNotify({
title: 'Success!',
text: 'Action completed',
type: 'success'
});
$scope.Lunchcontainer($scope.cid);
} else {
new PNotify({
title: 'Error!',
text: response.data.data[1],
type: 'error'
});
}
} else {
new PNotify({
title: 'Unable to complete request',
text: response.data.error_message,
type: 'error'
});

}
}

function cantLoadInitialData(response) {
$('#actionLoading').hide();

PNotify.error({
title: 'Unable to complete request',
text: "Problem in connecting to server"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ <h3 class="title-hero" >Main Actions
class="fa fa-play btn-icon"></i> Start
</button>
<button ng-disabled="status!='running'" class="btn btn-primary"
ng-click="cAction('restart')"><i
ng-click="restarthStatus()"><i
class="fa fa-refresh btn-icon"></i>
Restart
</button>
<button ng-disabled="status!='running'" class="btn btn-primary"
ng-click="cAction('stop')"><i
ng-click="StopContainerAPP()"><i
class="fa fa-stop btn-icon"></i> Stop
</button>

Expand Down

0 comments on commit 8c2a2f5

Please sign in to comment.