This commit is contained in:
Julien Fontanet 2013-09-13 11:12:21 +02:00
parent 4c902c5da5
commit 6988a3250b
1 changed files with 15 additions and 6 deletions

View File

@ -536,32 +536,41 @@ Api.fn.xo = {
var xo = this.xo; var xo = this.xo;
return Q.all([ return Q.all([
xo.hosts.count(), xo.hosts.get(),
xo.vms.get({ xo.vms.get({
'is_a_template': false, 'is_a_template': false,
'is_control_domain': false, 'is_control_domain': false,
}), }),
xo.srs.count(), xo.srs.count(),
]).spread(function (n_hosts, vms, n_srs) { ]).spread(function (hosts, vms, n_srs) {
var running_vms = _.where(vms, { var running_vms = _.where(vms, {
'power_state': 'Running', 'power_state': 'Running',
}); });
var n_cpus = 0;
var total_memory = 0;
_.each(hosts, function (host) {
n_cpus += host.host_CPUs.length;
total_memory += host.metrics.memory_total;
});
var n_vifs = 0; var n_vifs = 0;
var n_vcpus = 0; var n_vcpus = 0;
var memory = 0; var used_memory = 0;
_.each(vms, function (vm) { _.each(vms, function (vm) {
n_vifs += vm.VIFs.length; n_vifs += vm.VIFs.length;
n_vcpus += +vm.metrics.VCPUs_number; n_vcpus += +vm.metrics.VCPUs_number;
memory += +vm.metrics.memory_actual; used_memory += +vm.metrics.memory_actual;
}); });
return { return {
'hosts': n_hosts, 'hosts': hosts.length,
'vms': vms.length, 'vms': vms.length,
'running_vms': running_vms.length, 'running_vms': running_vms.length,
'memory': memory, 'used_memory': used_memory,
'total_memory': total_memory,
'vcpus': n_vcpus, 'vcpus': n_vcpus,
'cpus': n_cpus,
'vifs': n_vifs, 'vifs': n_vifs,
'srs': n_srs, 'srs': n_srs,
}; };