joyent/node-triton#103 `triton ip <inst>` to output the instance's primaryIp

This commit is contained in:
Trent Mick 2016-03-11 15:21:19 -08:00
parent 4f778f696e
commit 1e2b19c0e6
6 changed files with 106 additions and 0 deletions

View File

@ -7,6 +7,7 @@ Known issues:
## 4.7.1 (not yet released)
- #103 `triton ip <inst>` to output the instance's primaryIp
- #52 Workaround for `triton ssh ...`. In version 4.6.0, `triton ssh ...`
interactive sessions were broken. This version reverts that change and adds
a workaround for #52 (by disabling ControlMaster when spawning `ssh`).

View File

@ -218,6 +218,7 @@ function CLI() {
'stop',
'reboot',
'ssh',
'ip',
{ group: 'Images, Packages, Networks, Firewall Rules' },
'image',
'package',
@ -569,6 +570,7 @@ CLI.prototype.do_start = require('./do_start');
CLI.prototype.do_stop = require('./do_stop');
CLI.prototype.do_reboot = require('./do_reboot');
CLI.prototype.do_ssh = require('./do_ssh');
CLI.prototype.do_ip = require('./do_ip');
// Packages
CLI.prototype.do_packages = require('./do_packages');

71
lib/do_instance/do_ip.js Normal file
View File

@ -0,0 +1,71 @@
/*
* 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 instance ip ...`
*/
var format = require('util').format;
var errors = require('../errors');
function do_ip(subcmd, opts, args, cb) {
if (opts.help) {
this.do_help('help', {}, [subcmd], cb);
return;
} else if (args.length === 0) {
cb(new errors.UsageError('missing <inst> argument'));
return;
} else if (args.length > 1) {
cb(new errors.UsageError('too many arguments: ' + args));
return;
}
var cli = this.top;
cli.tritonapi.getInstance(args[0], function (err, inst) {
if (err) {
cb(err);
return;
}
if (!inst.primaryIp) {
cb(new errors.TritonError(format(
'primaryIp not found for instance "%s"', args[0])));
return;
}
console.log(inst.primaryIp);
cb();
});
}
do_ip.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
}
];
do_ip.help = [
/* BEGIN JSSTYLED */
'Print the primaryIp of the given instance.',
'',
'Usage:',
' {{name}} ip <inst>',
'',
'{{options}}',
'For example: ssh root@$(triton ip my-instance)'
].join('\n');
do_ip.completionArgtypes = ['tritoninstance', 'none'];
module.exports = do_ip;

View File

@ -44,6 +44,7 @@ function InstanceCLI(top) {
'disable-firewall',
{ group: '' },
'ssh',
'ip',
'wait',
'audit',
'snapshot',
@ -72,6 +73,7 @@ InstanceCLI.prototype.do_enable_firewall = require('./do_enable_firewall');
InstanceCLI.prototype.do_disable_firewall = require('./do_disable_firewall');
InstanceCLI.prototype.do_ssh = require('./do_ssh');
InstanceCLI.prototype.do_ip = require('./do_ip');
InstanceCLI.prototype.do_wait = require('./do_wait');
InstanceCLI.prototype.do_audit = require('./do_audit');
InstanceCLI.prototype.do_snapshot = require('./do_snapshot');

27
lib/do_ip.js Normal file
View File

@ -0,0 +1,27 @@
/*
* 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 ip ...` shortcut for `triton instance ip ...`.
*/
var targ = require('./do_instance/do_ip');
function do_ip(subcmd, opts, args, callback) {
this.handlerFromSubcmd('instance').dispatch({
subcmd: 'ip',
opts: opts,
args: args
}, callback);
}
do_ip.help = 'A shortcut for "triton instance ip".';
do_ip.options = targ.options;
do_ip.completionArgtypes = targ.completionArgtypes;
module.exports = do_ip;

View File

@ -43,6 +43,8 @@ var subs = [
['instance delete', 'instance rm', 'delete', 'rm'],
['instance enable-firewall'],
['instance disable-firewall'],
['instance ssh'],
['instance ip'],
['instance wait'],
['instance audit'],
['instance fwrules'],
@ -51,6 +53,7 @@ var subs = [
['instance snapshot list', 'instance snapshot ls', 'instance snapshots'],
['instance snapshot get'],
['instance snapshot delete', 'instance snapshot rm'],
['ip'],
['ssh'],
['network'],
['network list', 'networks'],