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,18 +37,15 @@ function do_info(subcmd, opts, args, callback) {
} }
function done() { function done() {
if (opts.json) { // parse name
console.log(JSON.stringify(out)); var name;
} else { if (out.account.firstName && out.account.lastName)
// pretty print name = format('%s %s', out.account.firstName,
console.log('%s - %s %s <%s>', out.account.lastName);
out.account.login, else if (out.account.firstName)
out.account.firstName, name = out.account.firstName;
out.account.lastName,
out.account.email); // parse machine states and accounting
console.log(self.triton.cloudapi.url);
console.log();
console.log('%d instance(s)', out.machines.length);
var states = {}; var states = {};
var disk = 0; var disk = 0;
var memory = 0; var memory = 0;
@ -59,13 +56,31 @@ function do_info(subcmd, opts, args, callback) {
memory += machine.memory; memory += machine.memory;
disk += machine.disk; disk += machine.disk;
}); });
Object.keys(states).forEach(function (state) { disk *= 1000 * 1000;
console.log('- %d %s', states[state], state); 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) {
data.machines = states;
console.log(JSON.stringify(data));
} else {
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 (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(); callback();
} }