rubiojr / knife-esx

@maintux's FORK IS NOW OFFICIAL: https://github.com/maintux/knife-esx
https://github.com/maintux/knife-esx
Apache License 2.0
35 stars 10 forks source link

connecting to esxi over ssh tunnel #5

Open ifeatu opened 12 years ago

ifeatu commented 12 years ago

I'd like to connect to my esxi server over an ssh tunnel. I tried changing the port (from 22 to 2002) in the esx_vm_create.rb file and declaring "localhost" in my command like so:

knife esx vm create --esx-host localhost --esx-username root --esx-password password --vm-disk mac.vmdk --vm-name test1

but I get:

Connecting to ESX host 127.0.0.1... 
ERROR: Network Error: Connection refused - connect(2)
Check your knife configuration and network settings

Here is the ssh tunnel I established:

ssh -f root@outside_host -L 2002:192.168.1.1:22 -N

Here is proof that the tunnel was established:

root@localhost:# netstat -ant | grep LISTEN | grep 2002
tcp        0      0 127.0.0.1:2002          0.0.0.0:*               LISTEN     

Here is the connection in esx_vm_create.rb (2002 being the localhost port I have the esxi server tunneled through):

def tcp_test_ssh(hostname)
    tcp_socket = TCPSocket.new(hostname, 2002)
    readable = IO.select([tcp_socket], nil, nil, 5)
    if readable
      Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")

Any suggestions?