diff --git a/ironic_ui/static/dashboard/admin/ironic/ironic.service.js b/ironic_ui/static/dashboard/admin/ironic/ironic.service.js index ea04495a..f5ad61df 100755 --- a/ironic_ui/static/dashboard/admin/ironic/ironic.service.js +++ b/ironic_ui/static/dashboard/admin/ironic/ironic.service.js @@ -147,15 +147,14 @@ * @return {promise} Promise */ function putNodeInMaintenanceMode(uuid, reason) { - var data = { - maint_reason: reason ? reason : gettext("No maintenance reason given.") - }; return apiService.patch('/api/ironic/nodes/' + uuid + '/maintenance', - data) + {maint_reason: reason + ? reason + : gettext("No reason given.")}) .catch(function(response) { var msg = interpolate( - gettext('Unable to put the Ironic node in maintenance mode: %s'), - [response.data], + gettext('Unable to put the Ironic node %s in maintenance mode: %s'), + [uuid, response.data], false); toastService.add('error', msg); return $q.reject(msg); @@ -174,9 +173,9 @@ return apiService.delete('/api/ironic/nodes/' + uuid + '/maintenance') .catch(function(response) { var msg = interpolate( - gettext('Unable to remove the Ironic node ' + - 'from maintenance mode: %s'), - [response.data], + gettext( + 'Unable to remove the Ironic node %s from maintenance mode: %s'), + [uuid, response.data], false); toastService.add('error', msg); return $q.reject(msg); diff --git a/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.service.js b/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.service.js index 892ed63e..166ecbd8 100644 --- a/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.service.js +++ b/ironic_ui/static/dashboard/admin/ironic/maintenance/maintenance.service.js @@ -34,73 +34,37 @@ 'horizon.dashboard.admin.ironic.actions' ]; - function maintenanceService($uibModal, basePath, actions) { + function maintenanceService($uibModal, basePath, nodeActions) { var service = { putNodeInMaintenanceMode: putNodeInMaintenanceMode, - putNodesInMaintenanceMode: putNodesInMaintenanceMode, - removeNodeFromMaintenanceMode: removeNodeFromMaintenanceMode, - removeNodesFromMaintenanceMode: removeNodesFromMaintenanceMode + removeNodeFromMaintenanceMode: removeNodeFromMaintenanceMode }; return service; /* - * @name horizon.dashboard.admin.ironic.maintenance.service. - * putNodeInMaintenanceMode - * @description Put a specified node in maintenance mode - * @param {object} - Node + * @description Put a specified list of nodes into mainenance * - * @return {void} + * @param {object[]} nodes - List of node objects + * @return {promise} */ - function putNodeInMaintenanceMode(node) { + function putNodeInMaintenanceMode(nodes) { var options = { controller: "MaintenanceController as ctrl", templateUrl: basePath + '/maintenance/maintenance.html' }; - $uibModal.open(options).result.then(function(maintReason) { - actions.putNodeInMaintenanceMode(node, maintReason); + return $uibModal.open(options).result.then(function(reason) { + return nodeActions.putNodeInMaintenanceMode(nodes, reason); }); } /* - * @name horizon.dashboard.admin.ironic.maintenance.service. - * putNodesInMaintenanceMode - * @description Put the specified nodes in maintenance mode - * @param {Array} - Nodes + * @description Take a specified list of nodes out of mainenance * - * @return {void} + * @param {object[]} nodes - List of node objects + * @return {promise} */ - function putNodesInMaintenanceMode(nodes) { - var options = { - controller: "MaintenanceController as ctrl", - templateUrl: basePath + '/maintenance/maintenance.html' - }; - $uibModal.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); + function removeNodeFromMaintenanceMode(nodes) { + return nodeActions.removeNodeFromMaintenanceMode(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 605fa945..641b595f 100755 --- a/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js +++ b/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js @@ -49,10 +49,8 @@ powerOff: powerOff, powerOnAll: powerOnNodes, powerOffAll: powerOffNodes, - putNodeInMaintenanceMode: putInMaintenanceMode, - removeNodeFromMaintenanceMode: removeFromMaintenanceMode, - putAllInMaintenanceMode: putNodesInMaintenanceMode, - removeAllFromMaintenanceMode: removeNodesFromMaintenanceMode, + putNodeInMaintenanceMode: putNodeInMaintenanceMode, + removeNodeFromMaintenanceMode: removeNodeFromMaintenanceMode, setProvisionState: setProvisionState }; @@ -123,38 +121,41 @@ // maintenance - function putInMaintenanceMode(node, maintReason) { - if (node.maintenance !== false) { - var msg = gettext("Node %s is already in maintenance mode."); - return $q.reject(interpolate(msg, [node], false)); - } - return ironic.putNodeInMaintenanceMode(node.uuid, maintReason).then( - function () { - node.maintenance = true; - node.maintenance_reason = maintReason; - } - ); + function putNodeInMaintenanceMode(nodes, reason) { + return applyFuncToNodes( + function(node, reason) { + if (node.maintenance !== false) { + var msg = gettext("Node %s is already in maintenance mode."); + return $q.reject(interpolate(msg, [node.uuid], false)); + } + return ironic.putNodeInMaintenanceMode(node.uuid, reason).then( + function (result) { + node.maintenance = true; + node.maintenance_reason = reason; + return result; + } + ); + }, + nodes, + reason); } - function removeFromMaintenanceMode(node) { - if (node.maintenance !== true) { - var msg = gettext("Node %s is not in maintenance mode."); - return $q.reject(interpolate(msg, [node], false)); - } - return ironic.removeNodeFromMaintenanceMode(node.uuid).then( - function () { - node.maintenance = false; - node.maintenance_reason = ""; - } - ); - } - - function putNodesInMaintenanceMode(nodes, maintReason) { - return applyFuncToNodes(putInMaintenanceMode, nodes, maintReason); - } - - function removeNodesFromMaintenanceMode(nodes) { - return applyFuncToNodes(removeFromMaintenanceMode, nodes); + function removeNodeFromMaintenanceMode(nodes) { + return applyFuncToNodes( + function(node) { + if (node.maintenance !== true) { + var msg = gettext("Node %s is not in maintenance mode."); + return $q.reject(interpolate(msg, [node.uuid], false)); + } + return ironic.removeNodeFromMaintenanceMode(node.uuid).then( + function (result) { + node.maintenance = false; + node.maintenance_reason = ""; + return result; + } + ); + }, + nodes); } /* @@ -210,6 +211,7 @@ * @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. + * The function should return a promise. * @param {Array} nodes - Collection of nodes * @param {object} extra - Additional argument passed to the function * @return {promise} - Single promise that represents the combined 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 6ae588db..639afc8d 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 @@ -57,6 +57,7 @@ ctrl.noPortsText = gettext('No network ports have been defined'); ctrl.actions = actions; + ctrl.maintenanceService = maintenanceService; ctrl.sections = [ { @@ -78,8 +79,6 @@ ctrl.re_uuid = new RegExp(validUuidPattern); ctrl.isUuid = isUuid; ctrl.getVifPortId = getVifPortId; - ctrl.putNodeInMaintenanceMode = putNodeInMaintenanceMode; - ctrl.removeNodeFromMaintenanceMode = removeNodeFromMaintenanceMode; ctrl.editNode = editNode; ctrl.createPort = createPort; ctrl.deletePort = deletePort; @@ -203,14 +202,6 @@ ? port.extra.vif_port_id : ""; } - function putNodeInMaintenanceMode() { - maintenanceService.putNodeInMaintenanceMode(ctrl.node); - } - - function removeNodeFromMaintenanceMode() { - maintenanceService.removeNodeFromMaintenanceMode(ctrl.node); - } - function editNode() { editNodeService.modal(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 44b91a68..97105cd2 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 @@ -23,12 +23,14 @@ {$ '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 3a031266..05193808 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 @@ -51,11 +51,8 @@ ctrl.nodes = []; ctrl.nodesSrc = []; ctrl.actions = actions; + ctrl.maintenanceService = maintenanceService; - ctrl.putNodeInMaintenanceMode = putNodeInMaintenanceMode; - ctrl.putNodesInMaintenanceMode = putNodesInMaintenanceMode; - ctrl.removeNodeFromMaintenanceMode = removeNodeFromMaintenanceMode; - ctrl.removeNodesFromMaintenanceMode = removeNodesFromMaintenanceMode; ctrl.enrollNode = enrollNode; ctrl.editNode = editNode; ctrl.refresh = refresh; @@ -164,22 +161,6 @@ ); } - function putNodeInMaintenanceMode(node) { - maintenanceService.putNodeInMaintenanceMode(node); - } - - function putNodesInMaintenanceMode(nodes) { - maintenanceService.putNodesInMaintenanceMode(nodes); - } - - function removeNodeFromMaintenanceMode(node) { - maintenanceService.removeNodeFromMaintenanceMode(node); - } - - function removeNodesFromMaintenanceMode(nodes) { - maintenanceService.removeNodesFromMaintenanceMode(nodes); - } - function enrollNode() { enrollNodeService.enrollNode(); } 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 96b57537..cf82a277 100644 --- a/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.html +++ b/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.html @@ -45,13 +45,13 @@ {$ 'Power off' | translate $} {$ 'Maintenance on' | translate $} {$ 'Maintenance off' | translate $} @@ -149,15 +149,15 @@ {$ 'Power off' | translate $} + callback="table.maintenanceService.putNodeInMaintenanceMode" + item="[node]" + disabled="node.maintenance"> {$ 'Maintenance on' | translate $} + callback="table.maintenanceService.removeNodeFromMaintenanceMode" + item="[node]" + disabled="!node.maintenance"> {$ 'Maintenance off' | translate $}