From 8a58f3f0064e5c5089b606f817f589f624da7316 Mon Sep 17 00:00:00 2001 From: indexzero Date: Fri, 11 Jan 2013 03:27:42 -0500 Subject: [PATCH] [refactor breaking] Begin to use ssh2, but blocked by mscdex/ssh2#19 --- lib/pkgcloud/core/compute/bootstrapper.js | 24 ++++++++++++++++++++--- package.json | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/pkgcloud/core/compute/bootstrapper.js b/lib/pkgcloud/core/compute/bootstrapper.js index fbe92b9a5..ee2133ce3 100644 --- a/lib/pkgcloud/core/compute/bootstrapper.js +++ b/lib/pkgcloud/core/compute/bootstrapper.js @@ -12,6 +12,7 @@ var events = require('events'), spawn = require('child_process').spawn, async = require('async'), events2 = require('eventemitter2'), + Ssh2 = require('ssh2'), utile = require('utile'), pkgcloud = require('../../../pkgcloud'); @@ -503,21 +504,38 @@ Bootstrapper.prototype.scp = function (options) { // // ### function ssh (options) -// #### @options {Object} Options containing the commands to run remotely. +// #### @options {Object} Options for the SSH run. +// #### @options.server {Server} Server instance to run commands on. +// #### @options.keys {Object} SSH keys to use when authenticating. +// #### @options.commands {Array} Set of remote commands to run over SSH. +// #### @options.address {string} **Optional** Address to ssh into. +// #### @options.remoteUser {string} **Optional** Name of the account to use when authenticating. +// #### @options.tunnel {Object} **Optional** Enables SSH tunneling through the host. // Runs the commands specified by `options.commands` via ssh remotely on the // server supplied by `options.server`. // Bootstrapper.prototype.ssh = function (options) { var server = options.server, address = options.address || pkgcloud.compute.serverIp(options.server), - sshOptions; + sshOptions, + conn; this.emit(['run', 'ssh', 'begin'], { address: address, commands: options.commands, keyfile: path.basename(options.keys['private'].path) }); - + + conn = new Ssh2(); + + conn.connect({ + host: address, + port: 22, + username: options.remoteUser || this.remoteUser, + privateKey: options.keys['private'].path + }); + + return conn; sshOptions = [ '-i', options.keys['private'].path, diff --git a/package.json b/package.json index 2fa4f2c8e..9ecd0cd4a 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "morestreams": "0.1.x", "pkginfo": "0.2.x", "request": "2.x.x", + "ssh2": "0.1.9", "underscore": "1.4.x", "utile": "0.x.x" },