This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.
node-spearhead/lib/do_snapshot/do_list.js
Marsell Kukuljevic f3956df8ce PUBAPI-1233/PUBAPI-1234 - add support for triton fwrules and
`triton snapshots`; triton can work with machine snapshots and
firewall rules.
2016-02-05 00:39:50 +11:00

96 lines
1.9 KiB
JavaScript

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Copyright 2016 Joyent, Inc.
*
* `triton snapshot list ...`
*/
var assert = require('assert-plus');
var tabula = require('tabula');
var common = require('../common');
var errors = require('../errors');
var COLUMNS_DEFAULT = 'name,state';
var SORT_DEFAULT = 'name';
function do_list(subcmd, opts, args, cb) {
assert.func(cb, 'cb');
if (opts.help) {
this.do_help('help', {}, [subcmd], cb);
return;
}
if (args.length !== 1) {
cb(new errors.UsageError('incorrect number of arguments'));
return;
}
var cli = this.top;
var machineId = args[0];
cli.tritonapi.cloudapi.listMachineSnapshots({
id: machineId
}, function onSnapshots(err, snapshots) {
if (err) {
cb(err);
return;
}
if (opts.json) {
common.jsonStream(snapshots);
} else {
var columns = COLUMNS_DEFAULT;
if (opts.o) {
columns = opts.o;
} else if (opts.long) {
columns = COLUMNS_DEFAULT;
}
columns = columns.split(',');
var sort = opts.s.split(',');
tabula(snapshots, {
skipHeader: false,
columns: columns,
sort: sort
});
}
cb();
});
}
do_list.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
}
].concat(common.getCliTableOptions({
includeLong: true,
sortDefault: SORT_DEFAULT
}));
do_list.help = [
'Show all of a machines\'s snapshots.',
'',
'Usage:',
' {{name}} list [<options>]',
'',
'{{options}}'
].join('\n');
do_list.aliases = ['ls'];
module.exports = do_list;