From 736c2dab5466a5187cea36732c35a5834d9978eb Mon Sep 17 00:00:00 2001 From: Peter Piela Date: Thu, 9 Feb 2017 11:36:18 -0500 Subject: [PATCH] Add support for manual cleaning of nodes - The action list associated with a node in manageable state will have a "Clean" item. - When the clean action is initiated the user is prompted with a modal dialog in which he or she enters or copies a set of cleaning steps in JSON format. - Basic validation is performed on the JSON. The user is able to submit the cleaning request only when validation is successful. - Cleaning is not currently available as a batch action. Change-Id: I2af9385e2d9532a9ec46993d65f8c510e419b6c9 Closes-Bug: #1648559 --- ironic_ui/api/ironic.py | 8 ++- ironic_ui/api/ironic_rest_api.py | 6 +- .../clean-node/clean-node.controller.js | 69 +++++++++++++++++++ .../admin/ironic/clean-node/clean-node.html | 41 +++++++++++ .../ironic/clean-node/clean-node.service.js | 64 +++++++++++++++++ .../dashboard/admin/ironic/ironic.service.js | 10 +-- .../admin/ironic/node-actions.service.js | 8 ++- .../ironic/node-state-transition.service.js | 5 +- 8 files changed, 201 insertions(+), 10 deletions(-) create mode 100644 ironic_ui/static/dashboard/admin/ironic/clean-node/clean-node.controller.js create mode 100644 ironic_ui/static/dashboard/admin/ironic/clean-node/clean-node.html create mode 100644 ironic_ui/static/dashboard/admin/ironic/clean-node/clean-node.service.js diff --git a/ironic_ui/api/ironic.py b/ironic_ui/api/ironic.py index 8763072f..bc115d3b 100755 --- a/ironic_ui/api/ironic.py +++ b/ironic_ui/api/ironic.py @@ -100,17 +100,21 @@ def node_set_power_state(request, node_id, state): return ironicclient(request).node.set_power_state(node_id, state) -def node_set_provision_state(request, node_uuid, state): +def node_set_provision_state(request, node_uuid, state, cleansteps=None): """Set the target provision state for a given node. :param request: HTTP request. :param node_uuid: The UUID of the node. :param state: the target provision state to set. + :param cleansteps: Optional list of cleaning steps :return: node. http://docs.openstack.org/developer/python-ironicclient/api/ironicclient.v1.node.html#ironicclient.v1.node.NodeManager.set_provision_state """ - return ironicclient(request).node.set_provision_state(node_uuid, state) + node_manager = ironicclient(request).node + return node_manager.set_provision_state(node_uuid, + state, + cleansteps=cleansteps) def node_set_maintenance(request, node_id, state, maint_reason=None): diff --git a/ironic_ui/api/ironic_rest_api.py b/ironic_ui/api/ironic_rest_api.py index 8ae5c73d..9d24efbc 100755 --- a/ironic_ui/api/ironic_rest_api.py +++ b/ironic_ui/api/ironic_rest_api.py @@ -170,7 +170,11 @@ class StatesProvision(generic.View): :return: Return code """ verb = request.DATA.get('verb') - return ironic.node_set_provision_state(request, node_uuid, verb) + clean_steps = request.DATA.get('clean_steps') + return ironic.node_set_provision_state(request, + node_uuid, + verb, + clean_steps) @urls.register diff --git a/ironic_ui/static/dashboard/admin/ironic/clean-node/clean-node.controller.js b/ironic_ui/static/dashboard/admin/ironic/clean-node/clean-node.controller.js new file mode 100644 index 00000000..247e129a --- /dev/null +++ b/ironic_ui/static/dashboard/admin/ironic/clean-node/clean-node.controller.js @@ -0,0 +1,69 @@ +/* + * Copyright 2017 Cray Inc. + * + * 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:CleanNodeController + * @ngController + * + * @description + * Controller used to prompt the user for a list of clean-steps + * in JSON format that will be applied a node + */ + angular + .module('horizon.dashboard.admin.ironic') + .controller('CleanNodeController', CleanNodeController); + + CleanNodeController.$inject = [ + '$uibModalInstance' + ]; + + function CleanNodeController($uibModalInstance) { + var ctrl = this; + + ctrl.errMsg = ''; + + ctrl.cancel = function() { + $uibModalInstance.dismiss('cancel'); + }; + + ctrl.clean = function(cleanSteps) { + try { + var steps = JSON.parse(cleanSteps); + if (angular.isArray(steps) && steps.length > 0) { + var valid = true; + angular.forEach(steps, function(step) { + if (angular.isUndefined(step.interface) || + angular.isUndefined(step.step)) { + valid = false; + } + }); + if (valid) { + $uibModalInstance.close(steps); + } else { + ctrl.errMsg = gettext('Each cleaning step must be an object that contains "interface" and "step" properties'); // eslint-disable-line max-len + } + } else { + ctrl.errMsg = gettext('Clean steps should be an non-empty array'); + } + } catch (e) { + ctrl.errMsg = gettext('Unable to validate the JSON input'); + } + }; + } +})(); diff --git a/ironic_ui/static/dashboard/admin/ironic/clean-node/clean-node.html b/ironic_ui/static/dashboard/admin/ironic/clean-node/clean-node.html new file mode 100644 index 00000000..ffd1029c --- /dev/null +++ b/ironic_ui/static/dashboard/admin/ironic/clean-node/clean-node.html @@ -0,0 +1,41 @@ + +