This commit is contained in:
Dave Eddy 2015-08-26 00:16:41 -04:00
parent 3bd22281e1
commit 6bd918eb81
4 changed files with 103 additions and 0 deletions

View File

@ -60,6 +60,7 @@ function CLI() {
'help',
{ group: 'Operator Commands' },
'account',
'info',
{ group: 'Instances (aka VMs/Machines/Containers)' },
'create-instance',
'instances',
@ -111,6 +112,7 @@ CLI.prototype.init = function (opts, args, callback) {
// Operator
CLI.prototype.do_account = require('./do_account');
CLI.prototype.do_info = require('./do_info');
// Images
CLI.prototype.do_images = require('./do_images');

View File

@ -449,6 +449,7 @@ CloudAPI.prototype.waitForMachineStates = function waitForMachineStates(opts, ca
CloudAPI.prototype.createListMachinesStream =
function createListMachinesStream(options) {
var self = this;
options = options || {};
// if the user specifies an offset we don't paginate
var once = options.limit !== undefined;
@ -481,6 +482,10 @@ function createListMachinesStream(options) {
* @param {Function} callback - called like `function (err, machines)`
*/
CloudAPI.prototype.listMachines = function listMachines(options, callback) {
if (typeof (options) === 'function') {
callback = options;
options = {};
}
var machines = [];
var s = this.createListMachinesStream(options);
s.on('error', function (e) {

95
lib/do_info.js Normal file
View File

@ -0,0 +1,95 @@
/*
* Copyright 2015 Joyent Inc.
*
* `triton info ...`
*/
var common = require('./common');
var f = require('util').format;
var prettybytes = require('pretty-bytes');
function do_info(subcmd, opts, args, callback) {
var self = this;
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return;
} else if (args.length !== 0) {
callback(new Error('invalid args: ' + args));
return;
}
var out = {};
var i = 0;
this.triton.cloudapi.getAccount(cb.bind('account')); i++;
this.triton.cloudapi.listMachines(cb.bind('machines')); i++;
function cb(err, data) {
if (err) {
callback(err);
return;
}
out[this.toString()] = data;
if (--i === 0)
done();
}
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);
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;
});
Object.keys(states).forEach(function (state) {
console.log('- %d %s', states[state], state);
});
console.log('- %s RAM Total', prettybytes(memory * 1000 * 1000));
console.log('- %s Disk Total', prettybytes(disk * 1000 * 1000));
}
callback();
}
}
do_info.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
},
{
names: ['json', 'j'],
type: 'bool',
help: 'JSON output.'
}
];
do_info.help = (
'Show account information\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} account\n'
+ '\n'
+ '{{options}}'
);
do_info.aliases = ['whoami'];
module.exports = do_info;

View File

@ -16,6 +16,7 @@
"mkdirp": "0.5.1",
"node-uuid": "1.4.3",
"once": "1.3.2",
"pretty-bytes": "2.0.1",
"restify-clients": "1.0.0",
"smartdc-auth": "git+ssh://git@github.com:joyent/node-smartdc-auth.git#9f21966",
"tabula": "1.4.2",