From 409fdec238f80d34019fde9f41404d1d66e88216 Mon Sep 17 00:00:00 2001 From: Peter Piela Date: Wed, 23 Mar 2016 10:20:44 -0400 Subject: [PATCH] Add support for specifying a maintenance reason Co-Authored-By: Beth Elwell Change-Id: Ie2eaf309ffbb9055afaf837c751d7898b0d9d9ee --- .../maintenance/maintenance.controller.js | 48 ++++++++ .../admin/ironic/maintenance/maintenance.html | 30 +++++ .../ironic/maintenance/maintenance.service.js | 106 ++++++++++++++++++ .../admin/ironic/node-actions.service.js | 36 ++++-- .../node-details/node-details.controller.js | 20 +++- .../ironic/node-details/node-details.html | 6 +- .../ironic/node-list/node-list.controller.js | 30 ++++- .../admin/ironic/node-list/node-list.html | 8 +- 8 files changed, 260 insertions(+), 24 deletions(-) create mode 100644 ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.controller.js create mode 100644 ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.html create mode 100644 ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.service.js diff --git a/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.controller.js b/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.controller.js new file mode 100644 index 00000000..2a51eda0 --- /dev/null +++ b/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.controller.js @@ -0,0 +1,48 @@ +/* + * Copyright 2016 Cray Inc. + * Copyright (c) 2016 Hewlett Packard Enterprise Development Company LP + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this 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'; + + /** + * @ngdoc controller + * @name horizon.dashboard.admin.ironic:MaintenanceController + * @ngController + * + * @description + * Controller used to prompt the user for information associated with + * putting one or more nodes into maintenance mode + */ + angular + .module('horizon.dashboard.admin.ironic') + .controller('MaintenanceController', MaintenanceController); + + MaintenanceController.$inject = [ + '$modalInstance' + ]; + + function MaintenanceController($modalInstance) { + var ctrl = this; + + ctrl.cancel = function() { + $modalInstance.dismiss('cancel'); + }; + + ctrl.putInMaintenanceMode = function(maintReason) { + $modalInstance.close(maintReason); + }; + } +})(); diff --git a/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.html b/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.html new file mode 100644 index 00000000..e7a85b17 --- /dev/null +++ b/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.html @@ -0,0 +1,30 @@ + + + diff --git a/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.service.js b/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.service.js new file mode 100644 index 00000000..482ee039 --- /dev/null +++ b/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.service.js @@ -0,0 +1,106 @@ +/* + * Copyright 2016 Cray Inc. + * Copyright (c) 2016 Hewlett Packard Enterprise Development Company LP + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this 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'; + + /* + * @ngdoc service + * @name horizon.dashboard.admin.ironic.maintenance.service + * @description Service for putting nodes in, and removing them from + * maintenance mode + */ + angular + .module('horizon.dashboard.admin.ironic') + .factory('horizon.dashboard.admin.ironic.maintenance.service', + maintenanceService); + + maintenanceService.$inject = [ + '$modal', + 'horizon.dashboard.admin.basePath', + 'horizon.dashboard.admin.ironic.actions' + ]; + + function maintenanceService($modal, basePath, actions) { + var service = { + putNodeInMaintenanceMode: putNodeInMaintenanceMode, + putNodesInMaintenanceMode: putNodesInMaintenanceMode, + removeNodeFromMaintenanceMode: removeNodeFromMaintenanceMode, + removeNodesFromMaintenanceMode: removeNodesFromMaintenanceMode + }; + return service; + + /* + * @name horizon.dashboard.admin.ironic.maintenance.service. + * putNodeInMaintenanceMode + * @description Put a specified node in maintenance mode + * @param {object} - Node + * + * @return {void} + */ + function putNodeInMaintenanceMode(node) { + var options = { + controller: "MaintenanceController as ctrl", + templateUrl: basePath + '/ironic/maintenance/maintenance.html' + }; + $modal.open(options).result.then(function(maintReason) { + actions.putNodeInMaintenanceMode(node, maintReason); + }); + } + + /* + * @name horizon.dashboard.admin.ironic.maintenance.service. + * putNodesInMaintenanceMode + * @description Put the specified nodes in maintenance mode + * @param {Array} - Nodes + * + * @return {void} + */ + function putNodesInMaintenanceMode(nodes) { + var options = { + controller: "MaintenanceController as ctrl", + templateUrl: basePath + '/ironic/maintenance/maintenance.html' + }; + $modal.open(options).result.then(function(maintReason) { + actions.putAllInMaintenanceMode(nodes, maintReason); + }); + } + + /* + * @name horizon.dashboard.admin.ironic.maintenance.service. + * removeNodeInMaintenanceMode + * @description Remove a specified node from maintenance mode + * @param {object} - Node + * + * @return {void} + */ + function removeNodeFromMaintenanceMode(node) { + actions.removeNodeFromMaintenanceMode(node); + } + + /* + * @name horizon.dashboard.admin.ironic.maintenance.service. + * removeNodesFromMaintenanceMode + * @description Remove the specified nodes from maintenance mode + * @param {Array} - Nodes + * + * @return {void} + */ + function removeNodesFromMaintenanceMode(nodes) { + actions.removeAllFromMaintenanceMode(nodes); + } + } +})(); diff --git a/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js b/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js index 4f9bf571..540337b4 100755 --- a/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js +++ b/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js @@ -56,7 +56,7 @@ node.power_state = null; }, function(reason) { - toastService.add('error', gettext(reason)); + toastService.add('error', reason); }); } @@ -70,7 +70,7 @@ node.power_state = null; }, function(reason) { - toastService.add('error', gettext(reason)); + toastService.add('error', reason); } ); } @@ -85,16 +85,17 @@ // maintenance - function putInMaintenanceMode(node) { + function putInMaintenanceMode(node, maintReason) { if (node.maintenance !== false) { return $q.reject(gettext("Node is already in maintenance mode.")); } - return ironic.putNodeInMaintenanceMode(node.uuid, "").then( + return ironic.putNodeInMaintenanceMode(node.uuid, maintReason).then( function () { node.maintenance = true; + node.maintenance_reason = maintReason; }, function(reason) { - toastService.add('error', gettext(reason)); + toastService.add('error', reason); } ); } @@ -106,26 +107,41 @@ return ironic.removeNodeFromMaintenanceMode(node.uuid).then( function () { node.maintenance = false; + node.maintenance_reason = ""; }, function (reason) { - toastService.add('error', gettext(reason)); + toastService.add('error', reason); } ); } - function putNodesInMaintenanceMode(nodes) { - return applyFuncToNodes(putInMaintenanceMode, nodes); + function putNodesInMaintenanceMode(nodes, maintReason) { + return applyFuncToNodes(putInMaintenanceMode, nodes, maintReason); } function removeNodesFromMaintenanceMode(nodes) { return applyFuncToNodes(removeFromMaintenanceMode, nodes); } - function applyFuncToNodes(fn, nodes) { + /* + * @name horizon.dashboard.admin.ironic.actions.applyFuncToNodes + * @description Apply a specified function to each member of a + * collection of nodes + * + * @param {function} fn – Function to be applied. + * The function should accept a node as the first argument. An optional + * second argument can be used to provide additional information. + * @param {Array} nodes - Collection of nodes + * @param {object} extra - Additional argument passed to the function + * @return {promise} - Single promise that represents the combined + * return status from all function invocations. The promise is rejected + * if any individual call fails. + */ + function applyFuncToNodes(fn, nodes, extra) { var promises = []; angular.forEach(nodes, function(node) { - promises.push(fn(node)); + promises.push(fn(node, extra)); }); return $q.all(promises); } diff --git a/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.js b/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.js index 7aa06646..bc51d404 100755 --- a/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.js +++ b/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.js @@ -26,10 +26,15 @@ '$location', 'horizon.app.core.openstack-service-api.ironic', 'horizon.dashboard.admin.ironic.actions', - 'horizon.dashboard.admin.basePath' + 'horizon.dashboard.admin.basePath', + 'horizon.dashboard.admin.ironic.maintenance.service' ]; - function IronicNodeDetailsController($location, ironic, actions, basePath) { + function IronicNodeDetailsController($location, + ironic, + actions, + basePath, + maintenanceService) { var ctrl = this; var path = basePath + 'ironic/node-details/sections/'; @@ -50,6 +55,8 @@ ctrl.re_uuid = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/; ctrl.isUuid = isUuid; ctrl.getVifPortId = getVifPortId; + ctrl.putNodeInMaintenanceMode = putNodeInMaintenanceMode; + ctrl.removeNodeFromMaintenanceMode = removeNodeFromMaintenanceMode; init(); @@ -120,6 +127,13 @@ angular.isDefined(port.extra.vif_port_id) ? port.extra.vif_port_id : ""; } - } + function putNodeInMaintenanceMode() { + maintenanceService.putNodeInMaintenanceMode(ctrl.node); + } + + function removeNodeFromMaintenanceMode() { + maintenanceService.removeNodeFromMaintenanceMode(ctrl.node); + } + } })(); diff --git a/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.html b/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.html index ca0d525f..02f1fb9b 100644 --- a/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.html +++ b/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.html @@ -18,14 +18,12 @@ {$ 'Power off' | translate $} {$ 'Maintenance on' | translate $} {$ 'Maintenance off' | translate $} diff --git a/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.controller.js b/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.controller.js index b9c863ad..72d8b482 100755 --- a/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.controller.js +++ b/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.controller.js @@ -22,13 +22,16 @@ .controller('IronicNodeListController', IronicNodeListController); IronicNodeListController.$inject = [ - '$scope', 'horizon.app.core.openstack-service-api.ironic', 'horizon.dashboard.admin.ironic.actions', - 'horizon.dashboard.admin.basePath' + 'horizon.dashboard.admin.basePath', + 'horizon.dashboard.admin.ironic.maintenance.service' ]; - function IronicNodeListController($scope, ironic, actions, basePath) { + function IronicNodeListController(ironic, + actions, + basePath, + maintenanceService) { var ctrl = this; ctrl.nodes = []; @@ -36,6 +39,11 @@ ctrl.basePath = basePath; ctrl.actions = actions; + ctrl.putNodeInMaintenanceMode = putNodeInMaintenanceMode; + ctrl.putNodesInMaintenanceMode = putNodesInMaintenanceMode; + ctrl.removeNodeFromMaintenanceMode = removeNodeFromMaintenanceMode; + ctrl.removeNodesFromMaintenanceMode = removeNodesFromMaintenanceMode; + /** * Filtering - client-side MagicSearch * all facets for node table @@ -100,6 +108,22 @@ } ); } + + function putNodeInMaintenanceMode(node) { + maintenanceService.putNodeInMaintenanceMode(node); + } + + function putNodesInMaintenanceMode(nodes) { + maintenanceService.putNodesInMaintenanceMode(nodes); + } + + function removeNodeFromMaintenanceMode(node) { + maintenanceService.removeNodeFromMaintenanceMode(node); + } + + function removeNodesFromMaintenanceMode(nodes) { + maintenanceService.removeNodesFromMaintenanceMode(nodes); + } } })(); diff --git a/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.html b/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.html index cad6b6af..d1c2323d 100755 --- a/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.html +++ b/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.html @@ -32,13 +32,13 @@ {$ 'Power off' | translate $} {$ 'Maintenance on' | translate $} {$ 'Maintenance off' | translate $} @@ -129,13 +129,13 @@ {$ 'Power off' | translate $} {$ 'Maintenance on' | translate $} {$ 'Maintenance off' | translate $}