triton info cleanup, fixes #8

This commit is contained in:
Dave Eddy 2015-09-03 18:24:14 -04:00
parent edcc2a52ed
commit de2a462f16

View File

@ -37,35 +37,50 @@ function do_info(subcmd, opts, args, callback) {
}
function done() {
// parse name
var name;
if (out.account.firstName && out.account.lastName)
name = format('%s %s', out.account.firstName,
out.account.lastName);
else if (out.account.firstName)
name = out.account.firstName;
// parse machine states and accounting
var states = {};
var disk = 0;
var memory = 0;
out.machines.forEach(function (machine) {
var state = machine.state;
states[state] = states[state] || 0;
states[state]++;
memory += machine.memory;
disk += machine.disk;
});
disk *= 1000 * 1000;
memory *= 1000 * 1000;
var data = {};
data.login = out.account.login;
if (name)
data.name = name;
data.email = out.account.email;
data.url = self.triton.cloudapi.url;
data.totalInstances = out.machines.length;
data.totalDisk = disk;
data.totalMemory = memory;
if (opts.json) {
console.log(JSON.stringify(out));
data.machines = states;
console.log(JSON.stringify(data));
} else {
// pretty print
console.log('%s - %s %s <%s>',
out.account.login,
out.account.firstName,
out.account.lastName,
out.account.email);
console.log(self.triton.cloudapi.url);
console.log();
console.log('%d instance(s)', out.machines.length);
var states = {};
var disk = 0;
var memory = 0;
out.machines.forEach(function (machine) {
var state = machine.state;
states[state] = states[state] || 0;
states[state]++;
memory += machine.memory;
disk += machine.disk;
data.totalDisk = common.humanSizeFromBytes(disk);
data.totalMemory = common.humanSizeFromBytes(memory);
Object.keys(data).forEach(function (key) {
console.log('%s: %s', key, data[key]);
});
Object.keys(states).forEach(function (state) {
console.log('- %d %s', states[state], state);
Object.keys(states).forEach(function (key) {
console.log('machines.%s: %s', key, states[key]);
});
console.log('- %s RAM Total',
common.humanSizeFromBytes(memory * 1000 * 1000));
console.log('- %s Disk Total',
common.humanSizeFromBytes(disk * 1000 * 1000));
}
callback();
}