From 00a09331cb273d3c5640d3ef7251ae8facc808e0 Mon Sep 17 00:00:00 2001 From: Peter Piela Date: Thu, 27 Jul 2017 10:17:46 -0400 Subject: [PATCH] Adds support for editing portgroups Adds support for editing portgroups from the node-details/configuration page. Each entry in the portgroups table has an associated ``Edit portgroup`` button that when clicked will launch a modal dialog that guides the user in making changes. Unit tests will follow. Change-Id: I8907800f23cc42c301fc8f077fb00a9a6cb18821 --- ironic_ui/api/ironic.py | 15 +++ ironic_ui/api/ironic_rest_api.py | 19 +++- .../edit-portgroup.controller.js | 104 ++++++++++++++++++ .../edit-portgroup/edit-portgroup.service.js | 56 ++++++++++ .../dashboard/admin/ironic/ironic.service.js | 27 +++++ .../admin/ironic/ironic.service.spec.js | 1 + .../node-details/node-details.controller.js | 15 +++ .../node-details/sections/configuration.html | 4 +- .../edit-portgroup-92c62b1ae0cf5e54.yaml | 7 ++ 9 files changed, 245 insertions(+), 3 deletions(-) create mode 100644 ironic_ui/static/dashboard/admin/ironic/edit-portgroup/edit-portgroup.controller.js create mode 100644 ironic_ui/static/dashboard/admin/ironic/edit-portgroup/edit-portgroup.service.js create mode 100644 releasenotes/notes/edit-portgroup-92c62b1ae0cf5e54.yaml diff --git a/ironic_ui/api/ironic.py b/ironic_ui/api/ironic.py index 8a1a0ba4..c4ab39a2 100755 --- a/ironic_ui/api/ironic.py +++ b/ironic_ui/api/ironic.py @@ -359,6 +359,21 @@ def portgroup_delete(request, portgroup_id): return ironicclient(request).portgroup.delete(portgroup_id) +def portgroup_update(request, portgroup_id, patch): + """Update a specified portgroup. + + :param request: HTTP request. + :param portgroup_id: The UUID or name of the portgroup. + :param patch: Sequence of update operations + :return: Portgroup. + + http://docs.openstack.org/developer/python-ironicclient/api/ironicclient.v1.port.html#ironicclient.v1.portgroup.PortgroupManager.update + """ + portgroup = ironicclient(request).portgroup.update(portgroup_id, patch) + return dict([(f, getattr(portgroup, f, '')) + for f in res_fields.PORTGROUP_DETAILED_RESOURCE.fields]) + + def portgroup_get_ports(request, portgroup_id): """Get the ports associated with a specified portgroup. diff --git a/ironic_ui/api/ironic_rest_api.py b/ironic_ui/api/ironic_rest_api.py index c31669af..fac9f7e5 100755 --- a/ironic_ui/api/ironic_rest_api.py +++ b/ironic_ui/api/ironic_rest_api.py @@ -381,6 +381,23 @@ class Portgroups(generic.View): request.DATA.get('portgroup_id')) +@urls.register +class Portgroup(generic.View): + + url_regex = r'ironic/portgroups/(?P{})$'. \ + format(LOGICAL_NAME_PATTERN) + + @rest_utils.ajax(data_required=True) + def patch(self, request, portgroup_id): + """Update an Ironic portgroup + + :param request: HTTP request + :param portgroup_id: UUID or name of portgroup. + """ + patch = request.DATA.get('patch') + return ironic.portgroup_update(request, portgroup_id, patch) + + @urls.register class PortgroupPorts(generic.View): @@ -392,7 +409,7 @@ class PortgroupPorts(generic.View): """Get the ports for a specified portgroup. :param request: HTTP request. - :param node_id: UUID or name of portgroup. + :param portgroup_id: UUID or name of portgroup. :return: List of port objects. """ ports = ironic.portgroup_get_ports(request, portgroup_id) diff --git a/ironic_ui/static/dashboard/admin/ironic/edit-portgroup/edit-portgroup.controller.js b/ironic_ui/static/dashboard/admin/ironic/edit-portgroup/edit-portgroup.controller.js new file mode 100644 index 00000000..c909f3cf --- /dev/null +++ b/ironic_ui/static/dashboard/admin/ironic/edit-portgroup/edit-portgroup.controller.js @@ -0,0 +1,104 @@ +/* + * 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'; + + /** + * Controller used to edit a specified node portgroup + */ + angular + .module('horizon.dashboard.admin.ironic') + .controller('EditPortgroupController', EditPortgroupController); + + EditPortgroupController.$inject = [ + '$controller', + '$uibModalInstance', + '$log', + 'horizon.app.core.openstack-service-api.ironic', + 'horizon.dashboard.admin.ironic.update-patch.service', + 'portgroup' + ]; + + function EditPortgroupController($controller, + $uibModalInstance, + $log, + ironic, + updatePatchService, + portgroup) { + var ctrl = this; + $controller('BasePortgroupController', + {ctrl: ctrl, + $uibModalInstance: $uibModalInstance}); + + ctrl.modalTitle = gettext("Edit Portgroup"); + ctrl.submitButtonTitle = gettext("Update Portgroup"); + + // Initialize form fields + ctrl.address.value = portgroup.address; + + ctrl.name.value = portgroup.name; + + ctrl.standalone_ports_supported.value = + portgroup.standalone_ports_supported ? 'True' : 'False'; + + ctrl.mode.value = portgroup.mode; + + ctrl.properties.properties = angular.copy(portgroup.properties); + + ctrl.extra.properties = angular.copy(portgroup.extra); + + /** + * Apply updates to the portgroup being edited + * + * @return {void} + */ + ctrl.updatePortgroup = function() { + var patcher = new updatePatchService.UpdatePatch(); + + $log.info("Updating portgroup " + JSON.stringify(portgroup)); + + patcher.buildPatch(portgroup.address, ctrl.address.value, "/address"); + patcher.buildPatch(portgroup.name, ctrl.name.value, "/name"); + patcher.buildPatch(portgroup.standalone_ports_supported + ? 'True' : 'False', + ctrl.standalone_ports_supported.value, + "/standalone_ports_supported"); + patcher.buildPatch(portgroup.mode, + ctrl.mode.value, + "/mode"); + patcher.buildPatch(portgroup.properties, + ctrl.properties.properties, + "/properties"); + patcher.buildPatch(portgroup.extra, ctrl.extra.properties, "/extra"); + + var patch = patcher.getPatch(); + $log.info("patch = " + JSON.stringify(patch.patch)); + if (patch.status === updatePatchService.UpdatePatch.status.OK) { + ironic.updatePortgroup(portgroup.uuid, patch.patch) + .then(function(portgroup) { + $uibModalInstance.close(portgroup); + }); + } else { + toastService.add('error', + gettext('Unable to create portgroup update patch.')); + } + }; + + ctrl.submit = function() { + ctrl.updatePortgroup(); + }; + } +})(); diff --git a/ironic_ui/static/dashboard/admin/ironic/edit-portgroup/edit-portgroup.service.js b/ironic_ui/static/dashboard/admin/ironic/edit-portgroup/edit-portgroup.service.js new file mode 100644 index 00000000..ce25c816 --- /dev/null +++ b/ironic_ui/static/dashboard/admin/ironic/edit-portgroup/edit-portgroup.service.js @@ -0,0 +1,56 @@ +/* + * 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'; + + angular + .module('horizon.dashboard.admin.ironic') + .factory('horizon.dashboard.admin.ironic.edit-portgroup.service', + editPortgroupService); + + editPortgroupService.$inject = [ + '$uibModal', + 'horizon.dashboard.admin.ironic.basePath' + ]; + + function editPortgroupService($uibModal, basePath) { + var service = { + editPortgroup: editPortgroup + }; + + /** + * @description: Edit a specified portgroup + * + * @param {object} portgroup - Portgroup to be edited + * @return {promise} Promise containing the updated portgroup + */ + function editPortgroup(portgroup) { + var options = { + controller: 'EditPortgroupController as ctrl', + backdrop: 'static', + resolve: { + portgroup: function() { + return portgroup; + } + }, + templateUrl: basePath + '/base-portgroup/base-portgroup.html' + }; + return $uibModal.open(options).result; + } + + return service; + } +})(); diff --git a/ironic_ui/static/dashboard/admin/ironic/ironic.service.js b/ironic_ui/static/dashboard/admin/ironic/ironic.service.js index b9bacde6..6ad1e306 100755 --- a/ironic_ui/static/dashboard/admin/ironic/ironic.service.js +++ b/ironic_ui/static/dashboard/admin/ironic/ironic.service.js @@ -60,6 +60,7 @@ setNodeProvisionState: setNodeProvisionState, updateNode: updateNode, updatePort: updatePort, + updatePortgroup: updatePortgroup, validateNode: validateNode, createPortgroup: createPortgroup, getPortgroups: getPortgroups, @@ -646,6 +647,32 @@ }); } + /** + * @description Update the definition of a specified portgroup. + * + * http://developer.openstack.org/api-ref/baremetal/#update-a-portgroup + * + * @param {string} portgroupId – UUID or name of a portgroup. + * @param {object[]} patch – Sequence of update operations + * @return {promise} Promise + */ + function updatePortgroup(portgroupId, patch) { + return apiService.patch('/api/ironic/portgroups/' + portgroupId, + {patch: patch}) + .then(function(response) { + var msg = gettext('Successfully updated portgroup %s'); + toastService.add('success', interpolate(msg, [portgroupId], false)); + return response.data; // The updated portgroup + }) + .catch(function(response) { + var msg = interpolate(gettext('Unable to update portgroup %s: %s'), + [portgroupId, response.data], + false); + toastService.add('error', msg); + return $q.reject(msg); + }); + } + /** * @description Get the ports associated with a specified portgroup. * diff --git a/ironic_ui/static/dashboard/admin/ironic/ironic.service.spec.js b/ironic_ui/static/dashboard/admin/ironic/ironic.service.spec.js index 8cec8a8a..1e6f18ca 100644 --- a/ironic_ui/static/dashboard/admin/ironic/ironic.service.spec.js +++ b/ironic_ui/static/dashboard/admin/ironic/ironic.service.spec.js @@ -41,6 +41,7 @@ 'setNodeProvisionState', 'updateNode', 'updatePort', + 'updatePortgroup', 'validateNode' ]; 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 5f6fb016..9381be18 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 @@ -33,6 +33,7 @@ 'horizon.dashboard.admin.ironic.create-port.service', 'horizon.dashboard.admin.ironic.create-portgroup.service', 'horizon.dashboard.admin.ironic.edit-port.service', + 'horizon.dashboard.admin.ironic.edit-portgroup.service', 'horizon.dashboard.admin.ironic.maintenance.service', 'horizon.dashboard.admin.ironic.bootdevice.service', 'horizon.dashboard.admin.ironic.node-state-transition.service', @@ -49,6 +50,7 @@ createPortService, createPortgroupService, editPortService, + editPortgroupService, maintenanceService, bootDeviceService, nodeStateTransitionService, @@ -95,6 +97,7 @@ ctrl.createPortgroup = createPortgroup; ctrl.deletePort = deletePort; ctrl.editPort = editPort; + ctrl.editPortgroup = editPortgroup; ctrl.refresh = refresh; ctrl.toggleConsoleMode = toggleConsoleMode; ctrl.deletePortgroups = deletePortgroups; @@ -289,6 +292,18 @@ }); } + /** + * @description: Edit a specified portgroup + * + * @param {portgroup} portgroup - Portgroup to be edited + * @return {void} + */ + function editPortgroup(portgroup) { + editPortgroupService.editPortgroup(portgroup).then(function() { + ctrl.refresh(); + }); + } + /** * @name horizon.dashboard.admin.ironic.NodeDetailsController.portgroupDelete * @description Delete a list of portgroups. diff --git a/ironic_ui/static/dashboard/admin/ironic/node-details/sections/configuration.html b/ironic_ui/static/dashboard/admin/ironic/node-details/sections/configuration.html index 90a89d0d..93343176 100644 --- a/ironic_ui/static/dashboard/admin/ironic/node-details/sections/configuration.html +++ b/ironic_ui/static/dashboard/admin/ironic/node-details/sections/configuration.html @@ -204,8 +204,8 @@ + callback="ctrl.editPortgroup" + item="portgroup"> {$ ::'Edit portgroup' | translate $} diff --git a/releasenotes/notes/edit-portgroup-92c62b1ae0cf5e54.yaml b/releasenotes/notes/edit-portgroup-92c62b1ae0cf5e54.yaml new file mode 100644 index 00000000..4129b9bf --- /dev/null +++ b/releasenotes/notes/edit-portgroup-92c62b1ae0cf5e54.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Adds support for editing portgroups from the node-details/configuration + page. Each entry in the portgroups table has an associated + ``Edit portgroup`` button that when clicked will launch a modal dialog + that guides the user in making changes.