Maintenance processing code cleanup
Made the following changes: - Eliminate separate functions for single node processing. Functions that set node maintenance mode now accept a list of nodes - Eliminate service thin wrapper functions inside controllers that dont manipulate controller state. Change-Id: I148f965618ab43f93732ac82cd5663a76bef1b9e
This commit is contained in:
parent
8e94b781c3
commit
d92d573f54
@ -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);
|
||||
|
@ -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<object>} - 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<object>} - Nodes
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function removeNodesFromMaintenanceMode(nodes) {
|
||||
actions.removeAllFromMaintenanceMode(nodes);
|
||||
function removeNodeFromMaintenanceMode(nodes) {
|
||||
return nodeActions.removeNodeFromMaintenanceMode(nodes);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
@ -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<node>} nodes - Collection of nodes
|
||||
* @param {object} extra - Additional argument passed to the function
|
||||
* @return {promise} - Single promise that represents the combined
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -23,12 +23,14 @@
|
||||
{$ 'Power off' | translate $}
|
||||
</action>
|
||||
<action button-type="menu-item"
|
||||
callback="ctrl.putNodeInMaintenanceMode"
|
||||
callback="ctrl.maintenanceService.putNodeInMaintenanceMode"
|
||||
item="[ctrl.node]"
|
||||
disabled="ctrl.node.maintenance">
|
||||
{$ 'Maintenance on' | translate $}
|
||||
</action>
|
||||
<action button-type="menu-item"
|
||||
callback="ctrl.removeNodeFromMaintenanceMode"
|
||||
callback="ctrl.maintenanceService.removeNodeFromMaintenanceMode"
|
||||
item="[ctrl.node]"
|
||||
disabled="!ctrl.node.maintenance">
|
||||
{$ 'Maintenance off' | translate $}
|
||||
</action>
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -45,13 +45,13 @@
|
||||
{$ 'Power off' | translate $}
|
||||
</action>
|
||||
<action button-type="menu-item"
|
||||
callback="table.putNodesInMaintenanceMode"
|
||||
callback="table.maintenanceService.putNodeInMaintenanceMode"
|
||||
item="tCtrl.selected"
|
||||
disabled="tCtrl.selected.length === 0">
|
||||
{$ 'Maintenance on' | translate $}
|
||||
</action>
|
||||
<action button-type="menu-item"
|
||||
callback="table.removeNodesFromMaintenanceMode"
|
||||
callback="table.maintenanceService.removeNodeFromMaintenanceMode"
|
||||
item="tCtrl.selected"
|
||||
disabled="tCtrl.selected.length === 0">
|
||||
{$ 'Maintenance off' | translate $}
|
||||
@ -149,15 +149,15 @@
|
||||
{$ 'Power off' | translate $}
|
||||
</action>
|
||||
<action button-type="menu-item"
|
||||
callback="table.putNodeInMaintenanceMode"
|
||||
disabled="node.maintenance"
|
||||
item="node">
|
||||
callback="table.maintenanceService.putNodeInMaintenanceMode"
|
||||
item="[node]"
|
||||
disabled="node.maintenance">
|
||||
{$ 'Maintenance on' | translate $}
|
||||
</action>
|
||||
<action button-type="menu-item"
|
||||
callback="table.removeNodeFromMaintenanceMode"
|
||||
disabled="!node.maintenance"
|
||||
item="node">
|
||||
callback="table.maintenanceService.removeNodeFromMaintenanceMode"
|
||||
item="[node]"
|
||||
disabled="!node.maintenance">
|
||||
{$ 'Maintenance off' | translate $}
|
||||
</action>
|
||||
<action button-type="menu-item"
|
||||
|
Loading…
Reference in New Issue
Block a user