2015-08-26 01:10:13 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Joyent Inc. All rights reserved.
|
|
|
|
*
|
2015-08-26 01:15:02 +03:00
|
|
|
* `triton instances ...`
|
2015-08-26 01:10:13 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
var format = require('util').format;
|
|
|
|
var tabula = require('tabula');
|
|
|
|
|
|
|
|
var errors = require('./errors');
|
|
|
|
|
|
|
|
|
2015-08-26 01:15:02 +03:00
|
|
|
function do_instances(subcmd, opts, args, callback) {
|
2015-08-26 01:10:13 +03:00
|
|
|
var self = this;
|
|
|
|
if (opts.help) {
|
|
|
|
this.do_help('help', {}, [subcmd], callback);
|
|
|
|
return;
|
|
|
|
} else if (args.length > 1) {
|
|
|
|
return callback(new Error('too many args: ' + args));
|
|
|
|
}
|
|
|
|
|
|
|
|
var machines = [];
|
|
|
|
var errs = [];
|
|
|
|
var res = this.sdc.listMachines();
|
|
|
|
res.on('data', function (dc, dcMachines) {
|
|
|
|
for (var i = 0; i < dcMachines.length; i++) {
|
|
|
|
dcMachines[i].dc = dc;
|
|
|
|
machines.push(dcMachines[i]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
res.on('dcError', function (dc, dcErr) {
|
|
|
|
dcErr.dc = dc;
|
|
|
|
errs.push(dcErr);
|
|
|
|
});
|
|
|
|
res.on('end', function () {
|
|
|
|
if (opts.json) {
|
|
|
|
p(JSON.stringify(machines, null, 4));
|
|
|
|
} else {
|
|
|
|
/* BEGIN JSSTYLED */
|
|
|
|
// TODO: get short output down to something like
|
|
|
|
// 'us-west-1 e91897cf testforyunong2 linux running 2013-11-08'
|
|
|
|
// 'us-west-1 e91897cf testforyunong2 ubuntu/13.3.0 running 2013-11-08'
|
|
|
|
/* END JSSTYLED */
|
|
|
|
common.tabulate(machines, {
|
|
|
|
columns: 'dc,id,name,image,state,created',
|
|
|
|
sort: 'created',
|
|
|
|
validFields: 'dc,id,name,type,state,image,package,memory,'
|
|
|
|
+ 'disk,created,updated,compute_node,primaryIp'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
var err;
|
|
|
|
if (errs.length === 1) {
|
|
|
|
err = errs[0];
|
|
|
|
} else if (errs.length > 1) {
|
|
|
|
err = new errors.MultiError(errs);
|
|
|
|
}
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
};
|
2015-08-26 01:15:02 +03:00
|
|
|
do_instances.options = [
|
2015-08-26 01:10:13 +03:00
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Show this help.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['json', 'j'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'JSON output.'
|
|
|
|
}
|
|
|
|
];
|
2015-08-26 01:15:02 +03:00
|
|
|
do_instances.help = (
|
|
|
|
'List instances.\n'
|
2015-08-26 01:10:13 +03:00
|
|
|
+ '\n'
|
|
|
|
+ 'Usage:\n'
|
2015-08-26 01:15:02 +03:00
|
|
|
+ ' {{name}} instances [<filters>...]\n'
|
2015-08-26 01:10:13 +03:00
|
|
|
+ '\n'
|
|
|
|
+ '{{options}}'
|
|
|
|
);
|
2015-08-26 01:15:02 +03:00
|
|
|
do_instances.aliases = ['insts'];
|
2015-08-26 01:10:13 +03:00
|
|
|
|
|
|
|
|
2015-08-26 01:15:02 +03:00
|
|
|
module.exports = do_instances;
|