Admin dashboard update

Use new API call to list capacities, ordered by usage and limited to
the top 5 capacites.

--Note that, due to API limitations, the UI cannot display what
particular pod/cluster the capacity belongs to anymore, as that
information is not returned in the response. This can be added again
if relevant API changes are made.
This commit is contained in:
bfederle 2012-02-07 15:54:54 -08:00
parent 81e878eaa9
commit 9c7abbc95d
1 changed files with 9 additions and 61 deletions

View File

@ -223,73 +223,21 @@
zoneCapacity: function(data) {
$.ajax({
url: createURL('listZones'),
url: createURL('listCapacity'),
data: {
showCapacities: true
sortBy: 'usage',
page: 1,
pageSize: 5
},
success: function(json) {
var zones = json.listzonesresponse.zone ?
json.listzonesresponse.zone : [];
var zoneCapacities = [];
$(zones).each(function() {
var zone = this;
var clusters;
// Get cluster-level data
$.ajax({
url: createURL('listClusters'),
data: {
zoneId: zone.id,
showCapacities: true
},
async: false,
success: function(json) {
var cluster = json.listclustersresponse.cluster;
// Get cluster-level data
$(cluster).each(function() {
var cluster = this;
$(cluster.capacity).each(function() {
var capacity = this;
zoneCapacities.push($.extend(capacity, {
zoneName: zone.name +
'<br/>Pod: ' + cluster.podname +
'<br/>Cluster: ' + cluster.name
}));
});
});
// Get zone-level data
$(zone.capacity).each(function() {
var capacity = this;
var existingCapacityTypes = $.map(zoneCapacities, function(capacity) {
return capacity.type;
});
var isExistingCapacity = $.inArray(capacity.type, existingCapacityTypes) > -1;
if (!isExistingCapacity) {
zoneCapacities.push($.extend(capacity, {
zoneName: zone.name
}));
}
});
}
});
});
var sortFn = function(a, b) {
return parseInt(a.percentused) < parseInt(b.percentused);
};
var capacities = json.listcapacityresponse.capacity ?
json.listcapacityresponse.capacity : [];
complete($.extend(data, {
zoneCapacities: $.map(zoneCapacities.sort(sortFn), function(capacity) {
zoneCapacities: $.map(capacities, function(capacity) {
return {
zoneID: zones[0].id, // Temporary fix for dashboard
zoneName: capacity.zoneName,
zoneID: capacity.zoneid, // Temporary fix for dashboard
zoneName: capacity.zonename,
type: cloudStack.converters.toAlertType(capacity.type),
percent: parseInt(capacity.percentused),
used: cloudStack.converters.convertByType(capacity.type, capacity.capacityused),