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_ssh.js

63 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-08-26 06:25:00 +03:00
/*
* Copyright 2015 Joyent Inc.
*
* `triton ssh ...`
*/
var common = require('./common');
var spawn = require('child_process').spawn;
function do_ssh(subcmd, opts, args, callback) {
var self = this;
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return;
} else if (args.length === 0) {
callback(new Error('invalid args: ' + args));
return;
}
var id = args.shift();
this.triton.getInstance(id, function (err, inst) {
2015-08-26 06:25:00 +03:00
if (err) {
callback(err);
return;
}
var ip = inst.primaryIp;
2015-08-26 06:25:00 +03:00
if (!ip) {
callback(new Error('primaryIp not found for instance'));
2015-08-26 06:25:00 +03:00
return;
}
args = ['-l', 'root'].concat(ip).concat(args);
self.triton.log.info({args: args}, 'forking ssh');
var child = spawn('ssh', args, {stdio: 'inherit'});
child.on('close', function (code) {
process.exit(code);
});
});
2015-08-26 06:25:00 +03:00
}
do_ssh.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
}
];
do_ssh.help = (
'SSH to the primary IP of an instance\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} ssh <alias|id> [arguments]\n'
+ '\n'
+ '{{options}}'
);
do_ssh.interspersedOptions = false;
module.exports = do_ssh;