Merge "Adds support for editing portgroups"

This commit is contained in:
Jenkins 2017-07-28 17:11:35 +00:00 committed by Gerrit Code Review
commit 2c88c1b7d0
9 changed files with 245 additions and 3 deletions

View File

@ -359,6 +359,21 @@ def portgroup_delete(request, portgroup_id):
return ironicclient(request).portgroup.delete(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): def portgroup_get_ports(request, portgroup_id):
"""Get the ports associated with a specified portgroup. """Get the ports associated with a specified portgroup.

View File

@ -381,6 +381,23 @@ class Portgroups(generic.View):
request.DATA.get('portgroup_id')) request.DATA.get('portgroup_id'))
@urls.register
class Portgroup(generic.View):
url_regex = r'ironic/portgroups/(?P<portgroup_id>{})$'. \
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 @urls.register
class PortgroupPorts(generic.View): class PortgroupPorts(generic.View):
@ -392,7 +409,7 @@ class PortgroupPorts(generic.View):
"""Get the ports for a specified portgroup. """Get the ports for a specified portgroup.
:param request: HTTP request. :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. :return: List of port objects.
""" """
ports = ironic.portgroup_get_ports(request, portgroup_id) ports = ironic.portgroup_get_ports(request, portgroup_id)

View File

@ -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();
};
}
})();

View File

@ -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;
}
})();

View File

@ -60,6 +60,7 @@
setNodeProvisionState: setNodeProvisionState, setNodeProvisionState: setNodeProvisionState,
updateNode: updateNode, updateNode: updateNode,
updatePort: updatePort, updatePort: updatePort,
updatePortgroup: updatePortgroup,
validateNode: validateNode, validateNode: validateNode,
createPortgroup: createPortgroup, createPortgroup: createPortgroup,
getPortgroups: getPortgroups, 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. * @description Get the ports associated with a specified portgroup.
* *

View File

@ -41,6 +41,7 @@
'setNodeProvisionState', 'setNodeProvisionState',
'updateNode', 'updateNode',
'updatePort', 'updatePort',
'updatePortgroup',
'validateNode' 'validateNode'
]; ];

View File

@ -33,6 +33,7 @@
'horizon.dashboard.admin.ironic.create-port.service', 'horizon.dashboard.admin.ironic.create-port.service',
'horizon.dashboard.admin.ironic.create-portgroup.service', 'horizon.dashboard.admin.ironic.create-portgroup.service',
'horizon.dashboard.admin.ironic.edit-port.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.maintenance.service',
'horizon.dashboard.admin.ironic.bootdevice.service', 'horizon.dashboard.admin.ironic.bootdevice.service',
'horizon.dashboard.admin.ironic.node-state-transition.service', 'horizon.dashboard.admin.ironic.node-state-transition.service',
@ -49,6 +50,7 @@
createPortService, createPortService,
createPortgroupService, createPortgroupService,
editPortService, editPortService,
editPortgroupService,
maintenanceService, maintenanceService,
bootDeviceService, bootDeviceService,
nodeStateTransitionService, nodeStateTransitionService,
@ -95,6 +97,7 @@
ctrl.createPortgroup = createPortgroup; ctrl.createPortgroup = createPortgroup;
ctrl.deletePort = deletePort; ctrl.deletePort = deletePort;
ctrl.editPort = editPort; ctrl.editPort = editPort;
ctrl.editPortgroup = editPortgroup;
ctrl.refresh = refresh; ctrl.refresh = refresh;
ctrl.toggleConsoleMode = toggleConsoleMode; ctrl.toggleConsoleMode = toggleConsoleMode;
ctrl.deletePortgroups = deletePortgroups; ctrl.deletePortgroups = deletePortgroups;
@ -303,6 +306,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 * @name horizon.dashboard.admin.ironic.NodeDetailsController.portgroupDelete
* @description Delete a list of portgroups. * @description Delete a list of portgroups.

View File

@ -204,8 +204,8 @@
<action-list uib-dropdown class="pull-right"> <action-list uib-dropdown class="pull-right">
<action button-type="split-button" <action button-type="split-button"
action-classes="'btn btn-default btn-sm'" action-classes="'btn btn-default btn-sm'"
callback="" callback="ctrl.editPortgroup"
item="port"> item="portgroup">
{$ ::'Edit portgroup' | translate $} {$ ::'Edit portgroup' | translate $}
</action> </action>
<menu> <menu>

View File

@ -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.