2015-08-26 23:40:50 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Joyent Inc.
|
|
|
|
*
|
|
|
|
* `triton networks ...`
|
|
|
|
*/
|
|
|
|
|
|
|
|
var tabula = require('tabula');
|
|
|
|
|
|
|
|
var common = require('./common');
|
|
|
|
|
|
|
|
// to be passed as query string args to /my/networks
|
|
|
|
var validFilters = [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'public',
|
|
|
|
'description'
|
|
|
|
];
|
|
|
|
|
|
|
|
// valid output fields to be printed
|
|
|
|
var validFields = [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'public',
|
|
|
|
'fabric',
|
|
|
|
'gateway',
|
|
|
|
'internet_nat',
|
|
|
|
'provision_end_ip',
|
|
|
|
'provision_start_ip',
|
|
|
|
'resolvers',
|
|
|
|
'subnet',
|
|
|
|
'vlan_id'
|
|
|
|
];
|
|
|
|
|
|
|
|
function do_networks(subcmd, opts, args, callback) {
|
|
|
|
if (opts.help) {
|
|
|
|
this.do_help('help', {}, [subcmd], callback);
|
|
|
|
return;
|
2015-08-27 00:09:50 +03:00
|
|
|
} else if (args.length !== 0) {
|
|
|
|
callback(new Error('invalid args: ' + args));
|
|
|
|
return;
|
2015-08-26 23:40:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var columns = opts.o.trim().split(',');
|
|
|
|
var sort = opts.s.trim().split(',');
|
|
|
|
|
2015-08-27 00:09:50 +03:00
|
|
|
/* not supported
|
2015-08-26 23:40:50 +03:00
|
|
|
var listOpts;
|
|
|
|
try {
|
|
|
|
listOpts = common.kvToObj(args, validFilters);
|
|
|
|
} catch (e) {
|
|
|
|
callback(e);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-27 00:09:50 +03:00
|
|
|
*/
|
2015-08-26 23:40:50 +03:00
|
|
|
|
|
|
|
this.triton.cloudapi.listNetworks(function (err, networks) {
|
|
|
|
if (err) {
|
|
|
|
callback(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.json) {
|
2015-08-26 23:53:23 +03:00
|
|
|
common.jsonStream(networks);
|
2015-08-26 23:40:50 +03:00
|
|
|
} else {
|
|
|
|
// pretty print
|
|
|
|
tabula(networks, {
|
|
|
|
skipHeader: opts.H,
|
|
|
|
columns: columns,
|
|
|
|
sort: sort,
|
|
|
|
validFields: validFields
|
|
|
|
});
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
do_networks.options = [
|
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Show this help.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['H'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Omit table header row.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['o'],
|
|
|
|
type: 'string',
|
|
|
|
default: 'id,name,subnet,public,vlan_id,gateway',
|
|
|
|
help: 'Specify fields (columns) to output.',
|
|
|
|
helpArg: 'field1,...'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['s'],
|
|
|
|
type: 'string',
|
|
|
|
default: 'name',
|
|
|
|
help: 'Sort on the given fields. Default is "name".',
|
|
|
|
helpArg: 'field1,...'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['json', 'j'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'JSON output.'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
do_networks.help = (
|
|
|
|
'Show networks.\n'
|
|
|
|
+ '\n'
|
|
|
|
+ 'Usage:\n'
|
|
|
|
+ ' {{name}} account\n'
|
|
|
|
+ '\n'
|
|
|
|
+ '{{options}}'
|
|
|
|
);
|
|
|
|
|
|
|
|
module.exports = do_networks;
|