Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
c0e6fbd8
Commit
c0e6fbd8
authored
Jun 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: Connect to SSH
parent
a23897f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
2 deletions
+34
-2
builder/vmware/step_wait_for_ssh.go
builder/vmware/step_wait_for_ssh.go
+34
-2
No files found.
builder/vmware/step_wait_for_ssh.go
View file @
c0e6fbd8
package
vmware
import
(
gossh
"code.google.com/p/go.crypto/ssh"
"errors"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/communicator/ssh"
"github.com/mitchellh/packer/packer"
"io/ioutil"
"log"
"net"
"os"
"time"
)
...
...
@@ -19,19 +23,21 @@ import (
// vmx_path string
//
// Produces:
//
<nothing>
//
communicator packer.Communicator
type
stepWaitForSSH
struct
{}
func
(
s
*
stepWaitForSSH
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmxPath
:=
state
[
"vmx_path"
]
.
(
string
)
ui
.
Say
(
"Waiting for SSH to become available..."
)
var
comm
packer
.
Communicator
for
{
time
.
Sleep
(
5
*
time
.
Second
)
log
.
Println
(
"Lookup up IP information..."
)
// First we wait for the IP to become available...
log
.
Println
(
"Lookup up IP information..."
)
ipLookup
,
err
:=
s
.
dhcpLeaseLookup
(
vmxPath
)
if
err
!=
nil
{
log
.
Printf
(
"Can't lookup via DHCP lease: %s"
,
err
)
...
...
@@ -44,8 +50,34 @@ func (s *stepWaitForSSH) Run(state map[string]interface{}) multistep.StepAction
}
log
.
Printf
(
"Detected IP: %s"
,
ip
)
// Attempt to connect to SSH port
nc
,
err
:=
net
.
Dial
(
"tcp"
,
fmt
.
Sprintf
(
"%s:22"
,
ip
))
if
err
!=
nil
{
log
.
Printf
(
"TCP connection to SSH ip/port failed: %s"
,
err
)
continue
}
// Then we attempt to connect via SSH
sshConfig
:=
&
gossh
.
ClientConfig
{
User
:
config
.
SSHUser
,
Auth
:
[]
gossh
.
ClientAuth
{
gossh
.
ClientAuthPassword
(
ssh
.
Password
(
config
.
SSHPassword
)),
},
}
comm
,
err
=
ssh
.
New
(
nc
,
sshConfig
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error connecting via SSH: %s"
,
err
))
return
multistep
.
ActionHalt
}
ui
.
Say
(
"Connected via SSH!"
)
break
}
state
[
"communicator"
]
=
comm
return
multistep
.
ActionContinue
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment