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() {
if (opts.json) {
console.log(JSON.stringify(out));
} 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);
// 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;
@ -59,13 +56,31 @@ function do_info(subcmd, opts, args, callback) {
memory += machine.memory;
disk += machine.disk;
});
Object.keys(states).forEach(function (state) {
console.log('- %d %s', states[state], state);
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) {
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();
}