2016-03-12 01:21:19 +02:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2016-12-13 20:04:41 +02:00
|
|
|
var common = require('../common');
|
2016-03-12 01:21:19 +02:00
|
|
|
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) {
|
2016-06-09 00:13:16 +03:00
|
|
|
cb(new errors.UsageError('missing INST argument'));
|
2016-03-12 01:21:19 +02:00
|
|
|
return;
|
|
|
|
} else if (args.length > 1) {
|
2016-06-09 00:13:16 +03:00
|
|
|
cb(new errors.UsageError('too many arguments: ' + args.join(' ')));
|
2016-03-12 01:21:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cli = this.top;
|
|
|
|
|
2016-12-13 20:04:41 +02:00
|
|
|
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
|
|
|
|
if (setupErr) {
|
|
|
|
cb(setupErr);
|
2016-03-12 01:21:19 +02:00
|
|
|
}
|
2016-12-13 20:04:41 +02:00
|
|
|
cli.tritonapi.getInstance(args[0], function (err, inst) {
|
|
|
|
if (err) {
|
|
|
|
cb(err);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-12 01:21:19 +02:00
|
|
|
|
2016-12-13 20:04:41 +02:00
|
|
|
if (!inst.primaryIp) {
|
|
|
|
cb(new errors.TritonError(format(
|
|
|
|
'primaryIp not found for instance "%s"', args[0])));
|
|
|
|
return;
|
|
|
|
}
|
2016-03-12 01:21:19 +02:00
|
|
|
|
2016-12-13 20:04:41 +02:00
|
|
|
console.log(inst.primaryIp);
|
|
|
|
cb();
|
|
|
|
});
|
2016-03-12 01:21:19 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
do_ip.options = [
|
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Show this help.'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-06-09 00:13:16 +03:00
|
|
|
do_ip.synopses = ['{{name}} {{cmd}} INST'];
|
|
|
|
|
2016-03-12 01:21:19 +02:00
|
|
|
do_ip.help = [
|
|
|
|
/* BEGIN JSSTYLED */
|
2016-06-09 00:13:16 +03:00
|
|
|
'Print the primary IP of the given instance.',
|
2016-03-12 01:21:19 +02:00
|
|
|
'',
|
2016-06-09 00:13:16 +03:00
|
|
|
'{{usage}}',
|
2016-03-12 01:21:19 +02:00
|
|
|
'',
|
|
|
|
'{{options}}',
|
2016-06-09 00:13:16 +03:00
|
|
|
'Where "INST" is an instance name, id, or short id.',
|
2016-03-12 01:21:19 +02:00
|
|
|
'For example: ssh root@$(triton ip my-instance)'
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
|
|
|
|
do_ip.completionArgtypes = ['tritoninstance', 'none'];
|
|
|
|
|
|
|
|
module.exports = do_ip;
|