Merge "Cleanup code associated with the ironic REST api"

This commit is contained in:
Jenkins 2017-03-04 14:33:20 +00:00 committed by Gerrit Code Review
commit 8145749dda
7 changed files with 75 additions and 54 deletions

View File

@ -35,9 +35,9 @@ class Nodes(generic.View):
:param request: HTTP request.
:return: nodes.
"""
items = ironic.node_list(request)
nodes = ironic.node_list(request)
return {
'items': [i.to_dict() for i in items],
'nodes': [i.to_dict() for i in nodes]
}
@rest_utils.ajax(data_required=True)
@ -98,9 +98,9 @@ class Ports(generic.View):
:return: List of ports.
"""
node_id = request.GET.get('node_id')
items = ironic.node_list_ports(request, node_id)
ports = ironic.node_list_ports(request, node_id)
return {
'items': [i.to_dict() for i in items],
'ports': [i.to_dict() for i in ports]
}
@rest_utils.ajax(data_required=True)
@ -236,9 +236,9 @@ class Drivers(generic.View):
:param request: HTTP request
:return: drivers
"""
items = ironic.driver_list(request)
drivers = ironic.driver_list(request)
return {
'items': [i.to_dict() for i in items]
'drivers': [i.to_dict() for i in drivers]
}

View File

@ -85,8 +85,8 @@
* @return {void}
*/
ctrl._loadDrivers = function() {
return ironic.getDrivers().then(function(response) {
ctrl.drivers = response.data.items;
return ironic.getDrivers().then(function(drivers) {
ctrl.drivers = drivers;
});
};
@ -241,9 +241,9 @@
ctrl.driverProperties = null;
ctrl.driverPropertyGroups = null;
return ironic.getDriverProperties(driverName).then(function(response) {
return ironic.getDriverProperties(driverName).then(function(properties) {
ctrl.driverProperties = {};
angular.forEach(response.data, function(desc, property) {
angular.forEach(properties, function(desc, property) {
ctrl.driverProperties[property] =
new baseNodeService.DriverProperty(property,
desc,

View File

@ -74,9 +74,7 @@
}
function _loadNodeData(nodeId) {
ironic.getNode(nodeId).then(function(response) {
var node = response.data;
ironic.getNode(nodeId).then(function(node) {
ctrl.baseNode = node;
ctrl.node.name = node.name;
@ -132,8 +130,6 @@
}
ctrl.submit = function() {
$uibModalInstance.close();
angular.forEach(ctrl.driverProperties, function(property, name) {
$log.debug(name +
", required = " + property.isRequired() +
@ -155,13 +151,13 @@
var patch = buildPatch(ctrl.baseNode, ctrl.node);
$log.info("patch = " + JSON.stringify(patch.patch));
if (patch.status === updatePatchService.UpdatePatch.status.OK) {
ironic.updateNode(ctrl.baseNode.uuid, patch.patch).then(function() {
ironic.updateNode(ctrl.baseNode.uuid, patch.patch).then(function(node) {
$rootScope.$emit(ironicEvents.EDIT_NODE_SUCCESS);
$uibModalInstance.close(node);
});
} else {
toastService.add('error',
gettext('Unable to create node update patch.'));
}
};
}

View File

@ -71,10 +71,10 @@
function getNodes() {
return apiService.get('/api/ironic/nodes/')
.then(function(response) {
angular.forEach(response.data.items, function(node) {
angular.forEach(response.data.nodes, function(node) {
nodeErrorService.checkNodeError(node);
});
return response;
return response.data.nodes;
})
.catch(function(response) {
var msg = interpolate(
@ -99,7 +99,7 @@
return apiService.get('/api/ironic/nodes/' + uuid)
.then(function(response) {
nodeErrorService.checkNodeError(response.data);
return response;
return response.data; // The node
})
.catch(function(response) {
var msg = interpolate(
@ -126,6 +126,15 @@
}
};
return apiService.get('/api/ironic/ports/', config)
.then(function(response) {
// Add id and name properties to support delete operations
// using the deleteModalService
angular.forEach(response.data.ports, function(port) {
port.id = port.uuid;
port.name = port.address;
});
return response.data.ports;
})
.catch(function(response) {
var msg = interpolate(
gettext('Unable to retrieve the Ironic node ports: %s'),
@ -303,11 +312,9 @@
node: nodeIdent
};
return apiService.delete('/api/ironic/nodes/', data)
.then(function() {
})
.catch(function(response) {
var msg = interpolate(gettext('Unable to delete node %s: %s'),
[nodeId, response.data],
[nodeIdent, response.data],
false);
toastService.add('error', msg);
return $q.reject(msg);
@ -328,10 +335,10 @@
patch: patch
};
return apiService.patch('/api/ironic/nodes/' + uuid, data)
.then(function() {
var msg = gettext(
'Successfully updated node %s');
.then(function(response) {
var msg = gettext('Successfully updated node %s');
toastService.add('success', interpolate(msg, [uuid], false));
return response.data; // The updated node
})
.catch(function(response) {
var msg = interpolate(gettext('Unable to update node %s: %s'),
@ -372,6 +379,9 @@
*/
function getDrivers() {
return apiService.get('/api/ironic/drivers/')
.then(function(response) {
return response.data.drivers;
})
.catch(function(response) {
var msg = interpolate(
gettext('Unable to retrieve Ironic drivers: %s'),
@ -393,6 +403,9 @@
function getDriverProperties(driverName) {
return apiService.get(
'/api/ironic/drivers/' + driverName + '/properties')
.then(function(response) {
return response.data; // Driver properties
})
.catch(function(response) {
var msg = interpolate(
gettext('Unable to retrieve driver properties: %s'),
@ -417,9 +430,10 @@
port: port
};
return apiService.post('/api/ironic/ports/', data)
.then(function() {
.then(function(response) {
toastService.add('success',
gettext('Port successfully created'));
return response.data; // The newly created port
})
.catch(function(response) {
var msg = interpolate(gettext('Unable to create port: %s'),

View File

@ -90,7 +90,7 @@
function powerOn(node) {
if (node.power_state !== POWER_STATE_OFF) {
var msg = gettext("Node %s is not powered off.");
return $q.reject(interpolate(msg, [node], false));
return $q.reject(interpolate(msg, [node.uuid], false));
}
return ironic.powerOnNode(node.uuid).then(
function() {
@ -103,7 +103,7 @@
function powerOff(node) {
if (node.power_state !== POWER_STATE_ON) {
var msg = gettext("Node %s is not powered on.");
return $q.reject(interpolate(msg, [node], false));
return $q.reject(interpolate(msg, [node.uuid], false));
}
return ironic.powerOffNode(node.uuid).then(
function() {

View File

@ -131,15 +131,8 @@
retrieveNode(uuid).then(function () {
ctrl.nodeStateTransitions =
nodeStateTransitionService.getTransitions(ctrl.node.provision_state);
retrievePorts(uuid);
ironic.validateNode(uuid).then(function(response) {
var nodeValidation = [];
angular.forEach(response.data, function(status) {
status.id = status.interface;
nodeValidation.push(status);
});
ctrl.nodeValidation = nodeValidation;
});
retrievePorts();
validateNode();
});
}
@ -152,27 +145,40 @@
* @return {promise} promise
*/
function retrieveNode(uuid) {
return ironic.getNode(uuid).then(function (response) {
ctrl.node = response.data;
ctrl.node.id = uuid;
return ironic.getNode(uuid).then(function (node) {
ctrl.node = node;
ctrl.node.id = ctrl.node.uuid;
});
}
/**
* @name horizon.dashboard.admin.ironic.NodeDetailsController.retrievePorts
* @description Retrieve the ports associated with a specified node,
* @description Retrieve the ports associated with the current node,
* and store them in the controller instance.
*
* @param {string} nodeId Node name or UUID
* @return {void}
*/
function retrievePorts(nodeId) {
ironic.getPortsWithNode(nodeId).then(function (response) {
ctrl.portsSrc = response.data.items;
ctrl.portsSrc.forEach(function(port) {
port.id = port.uuid;
port.name = port.address;
function retrievePorts() {
ironic.getPortsWithNode(ctrl.node.uuid).then(function (ports) {
ctrl.portsSrc = ports;
});
}
/**
* @name horizon.dashboard.admin.ironic.NodeDetailsController.validateNode
* @description Retrieve the ports associated with the current node,
* and store them in the controller instance.
*
* @return {void}
*/
function validateNode() {
ironic.validateNode(ctrl.node.uuid).then(function(response) {
var nodeValidation = [];
angular.forEach(response.data, function(status) {
status.id = status.interface;
nodeValidation.push(status);
});
ctrl.nodeValidation = nodeValidation;
});
}
@ -202,6 +208,11 @@
? port.extra.vif_port_id : "";
}
/**
* @description: Edit the current node
*
* @return {void}
*/
function editNode() {
editNodeService.modal(ctrl.node);
}

View File

@ -142,21 +142,21 @@
ironic.getNodes().then(onGetNodes);
}
function onGetNodes(response) {
function onGetNodes(nodes) {
var promises = [];
angular.forEach(response.data.items, function (node) {
angular.forEach(nodes, function (node) {
node.id = node.uuid;
promises.push(retrievePorts(node));
});
$q.all(promises).then(function() {
ctrl.nodesSrc = response.data.items;
ctrl.nodesSrc = nodes;
});
}
function retrievePorts(node) {
return ironic.getPortsWithNode(node.uuid).then(
function (response) {
node.ports = response.data.items;
function (ports) {
node.ports = ports;
}
);
}