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 instance-audit ...`
|
2015-08-26 01:10:13 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
var format = require('util').format;
|
|
|
|
var tabula = require('tabula');
|
|
|
|
|
2015-09-01 19:00:45 +03:00
|
|
|
var common = require('./common');
|
2015-08-26 01:10:13 +03:00
|
|
|
var errors = require('./errors');
|
|
|
|
|
|
|
|
|
2015-08-26 01:15:02 +03:00
|
|
|
function do_instance_audit(subcmd, opts, args, callback) {
|
2015-08-26 01:10:13 +03:00
|
|
|
if (opts.help) {
|
|
|
|
this.do_help('help', {}, [subcmd], callback);
|
|
|
|
return;
|
|
|
|
} else if (args.length > 1) {
|
|
|
|
//XXX Support multiple machines.
|
|
|
|
return callback(new Error('too many args: ' + args));
|
|
|
|
}
|
|
|
|
|
|
|
|
var id = args[0];
|
|
|
|
this.sdc.machineAudit({machine: id}, function (err, audit, dc) {
|
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < audit.length; i++) {
|
|
|
|
audit[i].dc = dc;
|
|
|
|
}
|
|
|
|
if (opts.json) {
|
2015-09-01 19:00:45 +03:00
|
|
|
common.jsonStream(audit);
|
2015-08-26 01:10:13 +03:00
|
|
|
} else {
|
2015-09-02 20:47:06 +03:00
|
|
|
// XXX what to tabulate here?
|
|
|
|
return callback(
|
|
|
|
new errors.InternalError('tabular output for audit NYI'));
|
|
|
|
// common.tabulate(audit, {
|
2015-08-26 01:10:13 +03:00
|
|
|
// columns: 'dc,id,name,state,created',
|
|
|
|
// sort: 'created',
|
|
|
|
// validFields: 'dc,id,name,type,state,image,package,memory,'
|
|
|
|
// + 'disk,created,updated,compute_node,primaryIp'
|
2015-09-02 20:47:06 +03:00
|
|
|
// });
|
2015-08-26 01:10:13 +03:00
|
|
|
}
|
|
|
|
callback();
|
|
|
|
});
|
2015-09-01 19:00:45 +03:00
|
|
|
}
|
|
|
|
|
2015-08-26 01:15:02 +03:00
|
|
|
do_instance_audit.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_instance_audit.help = (
|
2015-08-26 01:10:13 +03:00
|
|
|
'List instance actions.\n'
|
|
|
|
+ '\n'
|
|
|
|
+ 'Usage:\n'
|
2015-08-26 01:15:02 +03:00
|
|
|
+ ' {{name}} instance-audit <machine>\n'
|
2015-08-26 01:10:13 +03:00
|
|
|
+ '\n'
|
|
|
|
+ '{{options}}'
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-26 01:15:02 +03:00
|
|
|
module.exports = do_instance_audit;
|