diff --git a/zun_ui/api/client.py b/zun_ui/api/client.py index 844df52..115ae0a 100644 --- a/zun_ui/api/client.py +++ b/zun_ui/api/client.py @@ -97,3 +97,15 @@ def container_start(request, id): def container_stop(request, id): return zunclient(request).containers.stop(id) + + +def container_reboot(request, id): + return zunclient(request).containers.reboot(id) + + +def container_pause(request, id): + return zunclient(request).containers.pause(id) + + +def container_unpause(request, id): + return zunclient(request).containers.unpause(id) diff --git a/zun_ui/api/rest_api.py b/zun_ui/api/rest_api.py index 78b88a9..7d448f6 100644 --- a/zun_ui/api/rest_api.py +++ b/zun_ui/api/rest_api.py @@ -57,6 +57,12 @@ class ContainerActions(generic.View): return client.container_start(request, id) elif action == 'stop': return client.container_stop(request, id) + elif action == 'reboot': + return client.container_reboot(request, id) + elif action == 'pause': + return client.container_pause(request, id) + elif action == 'unpause': + return client.container_unpause(request, id) @urls.register diff --git a/zun_ui/static/dashboard/container/containers/actions.module.js b/zun_ui/static/dashboard/container/containers/actions.module.js index 8dbe078..8ad1098 100644 --- a/zun_ui/static/dashboard/container/containers/actions.module.js +++ b/zun_ui/static/dashboard/container/containers/actions.module.js @@ -32,6 +32,9 @@ 'horizon.dashboard.container.containers.delete.service', 'horizon.dashboard.container.containers.start.service', 'horizon.dashboard.container.containers.stop.service', + 'horizon.dashboard.container.containers.reboot.service', + 'horizon.dashboard.container.containers.pause.service', + 'horizon.dashboard.container.containers.unpause.service', 'horizon.dashboard.container.containers.resourceType', ]; @@ -42,6 +45,9 @@ deleteContainerService, startContainerService, stopContainerService, + rebootContainerService, + pauseContainerService, + unpauseContainerService, resourceType) { var containersResourceType = registry.getResourceType(resourceType); @@ -60,6 +66,27 @@ text: gettext('Stop Container') } }) + .append({ + id: 'rebootContainerAction', + service: rebootContainerService, + template: { + text: gettext('Reboot Container') + } + }) + .append({ + id: 'pauseContainerAction', + service: pauseContainerService, + template: { + text: gettext('Pause Container') + } + }) + .append({ + id: 'unpauseContainerAction', + service: unpauseContainerService, + template: { + text: gettext('Unpause Container') + } + }) .append({ id: 'deleteContainerAction', service: deleteContainerService, diff --git a/zun_ui/static/dashboard/container/containers/operations/pause.service.js b/zun_ui/static/dashboard/container/containers/operations/pause.service.js new file mode 100644 index 0000000..637c597 --- /dev/null +++ b/zun_ui/static/dashboard/container/containers/operations/pause.service.js @@ -0,0 +1,69 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use self file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +(function() { + 'use strict'; + + angular + .module('horizon.dashboard.container.containers') + .factory('horizon.dashboard.container.containers.pause.service', pauseService); + + pauseService.$inject = [ + 'horizon.framework.util.q.extensions', + 'horizon.framework.widgets.toast.service', + 'horizon.app.core.openstack-service-api.zun', + 'horizon.framework.widgets.modal-wait-spinner.service' + ]; + + /** + * @ngDoc factory + * @name horizon.dashboard.container.containers.pause.service + * @Description + * pause container. + */ + function pauseService($qExtensions, toast, zun, modalWaitSpinnerService) { + + var message = { + success: gettext('Container %s was successfully paused.') + }; + + var service = { + initScope: initScope, + allowed: allowed, + perform: perform + }; + + return service; + + ////////////// + + // include this function in your service + // if you plan to emit events to the parent controller + function initScope() { + } + + function allowed() { + return $qExtensions.booleanAsPromise(true); + } + + function perform(selected) { + // pause selected container + return zun.pauseContainer(selected.id).then(success); + + function success(response) { + toast.add('success', interpolate(message.success, [selected.name])); + }; + } + } +})(); diff --git a/zun_ui/static/dashboard/container/containers/operations/reboot.service.js b/zun_ui/static/dashboard/container/containers/operations/reboot.service.js new file mode 100644 index 0000000..e9ea40d --- /dev/null +++ b/zun_ui/static/dashboard/container/containers/operations/reboot.service.js @@ -0,0 +1,68 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use self file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +(function() { + 'use strict'; + + angular + .module('horizon.dashboard.container.containers') + .factory('horizon.dashboard.container.containers.reboot.service', rebootService); + + rebootService.$inject = [ + 'horizon.framework.util.q.extensions', + 'horizon.framework.widgets.toast.service', + 'horizon.app.core.openstack-service-api.zun' + ]; + + /** + * @ngDoc factory + * @name horizon.dashboard.container.containers.reboot.service + * @Description + * reboot container. + */ + function rebootService( + $qExtensions, toast, zun + ) { + + var message = { + success: gettext('Container %s was successfully rebooted.') + }; + + var service = { + initScope: initScope, + allowed: allowed, + perform: perform + }; + + return service; + + ////////////// + + // include this function in your service + // if you plan to emit events to the parent controller + function initScope() { + } + + function allowed() { + return $qExtensions.booleanAsPromise(true); + } + + function perform(selected) { + // reboot selected container + return zun.rebootContainer(selected.id).success(function(response) { + toast.add('success', interpolate(message.success, [selected.name])); + }); + } + } +})(); diff --git a/zun_ui/static/dashboard/container/containers/operations/unpause.service.js b/zun_ui/static/dashboard/container/containers/operations/unpause.service.js new file mode 100644 index 0000000..42cff41 --- /dev/null +++ b/zun_ui/static/dashboard/container/containers/operations/unpause.service.js @@ -0,0 +1,68 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use self file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +(function() { + 'use strict'; + + angular + .module('horizon.dashboard.container.containers') + .factory('horizon.dashboard.container.containers.unpause.service', unpauseService); + + unpauseService.$inject = [ + 'horizon.framework.util.q.extensions', + 'horizon.framework.widgets.toast.service', + 'horizon.app.core.openstack-service-api.zun' + ]; + + /** + * @ngDoc factory + * @name horizon.dashboard.container.containers.unpause.service + * @Description + * unpause container. + */ + function unpauseService( + $qExtensions, toast, zun + ) { + + var message = { + success: gettext('Container %s was successfully unpaused.') + }; + + var service = { + initScope: initScope, + allowed: allowed, + perform: perform + }; + + return service; + + ////////////// + + // include this function in your service + // if you plan to emit events to the parent controller + function initScope() { + } + + function allowed() { + return $qExtensions.booleanAsPromise(true); + } + + function perform(selected) { + // unpause selected container + return zun.unpauseContainer(selected.id).success(function(response) { + toast.add('success', interpolate(message.success, [selected.name])); + }); + } + } +})(); diff --git a/zun_ui/static/dashboard/container/zun.service.js b/zun_ui/static/dashboard/container/zun.service.js index 8a355fa..e0d19a4 100644 --- a/zun_ui/static/dashboard/container/zun.service.js +++ b/zun_ui/static/dashboard/container/zun.service.js @@ -34,6 +34,9 @@ startContainer: startContainer, stopContainer: stopContainer, logsContainer: logsContainer, + rebootContainer: rebootContainer, + pauseContainer: pauseContainer, + unpauseContainer: unpauseContainer }; return service; @@ -128,5 +131,26 @@ } } } + + function rebootContainer(id) { + return apiService.post('/api/zun/containers/' + id + '/reboot') + .error(function() { + toastService.add('error', gettext('Unable to reboot Container')); + }); + } + + function pauseContainer(id) { + return apiService.post('/api/zun/containers/' + id + '/pause') + .error(function() { + toastService.add('error', gettext('Unable to pause Container')); + }); + } + + function unpauseContainer(id) { + return apiService.post('/api/zun/containers/' + id + '/unpause') + .error(function() { + toastService.add('error', gettext('Unable to unpause of Container')); + }); + } } }());