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
115d583c
Commit
115d583c
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
helper/communicator: make host more generic
parent
68e4734c
Changes
30
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
113 additions
and
103 deletions
+113
-103
builder/amazon/common/ssh.go
builder/amazon/common/ssh.go
+3
-3
builder/amazon/ebs/builder.go
builder/amazon/ebs/builder.go
+1
-2
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+1
-2
builder/digitalocean/builder.go
builder/digitalocean/builder.go
+3
-3
builder/digitalocean/ssh.go
builder/digitalocean/ssh.go
+4
-4
builder/googlecompute/builder.go
builder/googlecompute/builder.go
+3
-3
builder/googlecompute/ssh.go
builder/googlecompute/ssh.go
+3
-4
builder/null/builder.go
builder/null/builder.go
+1
-2
builder/null/ssh.go
builder/null/ssh.go
+2
-4
builder/openstack/builder.go
builder/openstack/builder.go
+2
-3
builder/openstack/ssh.go
builder/openstack/ssh.go
+6
-7
builder/parallels/common/ssh.go
builder/parallels/common/ssh.go
+2
-4
builder/parallels/iso/builder.go
builder/parallels/iso/builder.go
+3
-3
builder/parallels/pvm/builder.go
builder/parallels/pvm/builder.go
+3
-3
builder/qemu/builder.go
builder/qemu/builder.go
+4
-3
builder/qemu/ssh.go
builder/qemu/ssh.go
+6
-4
builder/virtualbox/common/ssh.go
builder/virtualbox/common/ssh.go
+6
-4
builder/virtualbox/iso/builder.go
builder/virtualbox/iso/builder.go
+4
-3
builder/virtualbox/ovf/builder.go
builder/virtualbox/ovf/builder.go
+4
-3
builder/vmware/common/driver.go
builder/vmware/common/driver.go
+2
-2
builder/vmware/common/driver_fusion5.go
builder/vmware/common/driver_fusion5.go
+2
-2
builder/vmware/common/driver_mock.go
builder/vmware/common/driver_mock.go
+8
-8
builder/vmware/common/driver_player5.go
builder/vmware/common/driver_player5.go
+2
-2
builder/vmware/common/driver_workstation9.go
builder/vmware/common/driver_workstation9.go
+2
-2
builder/vmware/common/ssh.go
builder/vmware/common/ssh.go
+3
-3
builder/vmware/iso/builder.go
builder/vmware/iso/builder.go
+3
-3
builder/vmware/iso/driver_esx5.go
builder/vmware/iso/driver_esx5.go
+2
-2
builder/vmware/vmx/builder.go
builder/vmware/vmx/builder.go
+3
-3
helper/communicator/step_connect.go
helper/communicator/step_connect.go
+10
-8
helper/communicator/step_connect_ssh.go
helper/communicator/step_connect_ssh.go
+15
-4
No files found.
builder/amazon/common/ssh.go
View file @
115d583c
...
@@ -10,9 +10,9 @@ import (
...
@@ -10,9 +10,9 @@ import (
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh"
)
)
// SSH
Address
returns a function that can be given to the SSH communicator
// SSH
Host
returns a function that can be given to the SSH communicator
// for determining the SSH address based on the instance DNS name.
// for determining the SSH address based on the instance DNS name.
func
SSH
Address
(
e
*
ec2
.
EC2
,
port
int
,
private
bool
)
func
(
multistep
.
StateBag
)
(
string
,
error
)
{
func
SSH
Host
(
e
*
ec2
.
EC2
,
private
bool
)
func
(
multistep
.
StateBag
)
(
string
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
for
j
:=
0
;
j
<
2
;
j
++
{
for
j
:=
0
;
j
<
2
;
j
++
{
var
host
string
var
host
string
...
@@ -28,7 +28,7 @@ func SSHAddress(e *ec2.EC2, port int, private bool) func(multistep.StateBag) (st
...
@@ -28,7 +28,7 @@ func SSHAddress(e *ec2.EC2, port int, private bool) func(multistep.StateBag) (st
}
}
if
host
!=
""
{
if
host
!=
""
{
return
fmt
.
Sprintf
(
"%s:%d"
,
host
,
port
)
,
nil
return
host
,
nil
}
}
r
,
err
:=
e
.
DescribeInstances
(
&
ec2
.
DescribeInstancesInput
{
r
,
err
:=
e
.
DescribeInstances
(
&
ec2
.
DescribeInstancesInput
{
...
...
builder/amazon/ebs/builder.go
View file @
115d583c
...
@@ -115,9 +115,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -115,9 +115,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
RunConfig
.
Comm
,
Config
:
&
b
.
config
.
RunConfig
.
Comm
,
SSHAddress
:
awscommon
.
SSHAddress
(
Host
:
awscommon
.
SSHHost
(
ec2conn
,
ec2conn
,
b
.
config
.
RunConfig
.
Comm
.
SSHPort
,
b
.
config
.
SSHPrivateIp
),
b
.
config
.
SSHPrivateIp
),
SSHConfig
:
awscommon
.
SSHConfig
(
SSHConfig
:
awscommon
.
SSHConfig
(
b
.
config
.
RunConfig
.
Comm
.
SSHUsername
),
b
.
config
.
RunConfig
.
Comm
.
SSHUsername
),
...
...
builder/amazon/instance/builder.go
View file @
115d583c
...
@@ -200,9 +200,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -200,9 +200,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
RunConfig
.
Comm
,
Config
:
&
b
.
config
.
RunConfig
.
Comm
,
SSHAddress
:
awscommon
.
SSHAddress
(
Host
:
awscommon
.
SSHHost
(
ec2conn
,
ec2conn
,
b
.
config
.
RunConfig
.
Comm
.
SSHPort
,
b
.
config
.
SSHPrivateIp
),
b
.
config
.
SSHPrivateIp
),
SSHConfig
:
awscommon
.
SSHConfig
(
SSHConfig
:
awscommon
.
SSHConfig
(
b
.
config
.
RunConfig
.
Comm
.
SSHUsername
),
b
.
config
.
RunConfig
.
Comm
.
SSHUsername
),
...
...
builder/digitalocean/builder.go
View file @
115d583c
...
@@ -54,9 +54,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -54,9 +54,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new
(
stepCreateDroplet
),
new
(
stepCreateDroplet
),
new
(
stepDropletInfo
),
new
(
stepDropletInfo
),
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
Comm
,
Config
:
&
b
.
config
.
Comm
,
SSHAddress
:
sshAddress
,
Host
:
commHost
,
SSHConfig
:
sshConfig
,
SSHConfig
:
sshConfig
,
},
},
new
(
common
.
StepProvision
),
new
(
common
.
StepProvision
),
new
(
stepShutdown
),
new
(
stepShutdown
),
...
...
builder/digitalocean/ssh.go
View file @
115d583c
...
@@ -2,14 +2,14 @@ package digitalocean
...
@@ -2,14 +2,14 @@ package digitalocean
import
(
import
(
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh"
"github.com/mitchellh/multistep"
)
)
func
sshAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
commHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
config
:=
state
.
Get
(
"config"
)
.
(
Config
)
ipAddress
:=
state
.
Get
(
"droplet_ip"
)
.
(
string
)
ipAddress
:=
state
.
Get
(
"droplet_ip"
)
.
(
string
)
return
fmt
.
Sprintf
(
"%s:%d"
,
ipAddress
,
config
.
Comm
.
SSHPort
)
,
nil
return
ipAddress
,
nil
}
}
func
sshConfig
(
state
multistep
.
StateBag
)
(
*
ssh
.
ClientConfig
,
error
)
{
func
sshConfig
(
state
multistep
.
StateBag
)
(
*
ssh
.
ClientConfig
,
error
)
{
...
...
builder/googlecompute/builder.go
View file @
115d583c
...
@@ -62,9 +62,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -62,9 +62,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Debug
:
b
.
config
.
PackerDebug
,
Debug
:
b
.
config
.
PackerDebug
,
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
Comm
,
Config
:
&
b
.
config
.
Comm
,
SSHAddress
:
sshAddress
,
Host
:
commHost
,
SSHConfig
:
sshConfig
,
SSHConfig
:
sshConfig
,
},
},
new
(
common
.
StepProvision
),
new
(
common
.
StepProvision
),
new
(
StepTeardownInstance
),
new
(
StepTeardownInstance
),
...
...
builder/googlecompute/ssh.go
View file @
115d583c
...
@@ -2,15 +2,14 @@ package googlecompute
...
@@ -2,15 +2,14 @@ package googlecompute
import
(
import
(
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh"
)
)
// sshAddress returns the ssh address.
func
commHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
sshAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ipAddress
:=
state
.
Get
(
"instance_ip"
)
.
(
string
)
ipAddress
:=
state
.
Get
(
"instance_ip"
)
.
(
string
)
return
fmt
.
Sprintf
(
"%s:%d"
,
ipAddress
,
config
.
Comm
.
SSHPort
)
,
nil
return
ipAddress
,
nil
}
}
// sshConfig returns the ssh configuration.
// sshConfig returns the ssh configuration.
...
...
builder/null/builder.go
View file @
115d583c
...
@@ -30,8 +30,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -30,8 +30,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
steps
:=
[]
multistep
.
Step
{
steps
:=
[]
multistep
.
Step
{
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
CommConfig
,
Config
:
&
b
.
config
.
CommConfig
,
SSHAddress
:
SSHAddress
(
Host
:
CommHost
(
b
.
config
.
CommConfig
.
SSHHost
),
b
.
config
.
CommConfig
.
SSHHost
,
b
.
config
.
CommConfig
.
SSHPort
),
SSHConfig
:
SSHConfig
(
SSHConfig
:
SSHConfig
(
b
.
config
.
CommConfig
.
SSHUsername
,
b
.
config
.
CommConfig
.
SSHUsername
,
b
.
config
.
CommConfig
.
SSHPassword
,
b
.
config
.
CommConfig
.
SSHPassword
,
...
...
builder/null/ssh.go
View file @
115d583c
...
@@ -8,11 +8,9 @@ import (
...
@@ -8,11 +8,9 @@ import (
"io/ioutil"
"io/ioutil"
)
)
// SSHAddress returns a function that can be given to the SSH communicator
func
CommHost
(
host
string
)
func
(
multistep
.
StateBag
)
(
string
,
error
)
{
// for determining the SSH address
func
SSHAddress
(
host
string
,
port
int
)
func
(
multistep
.
StateBag
)
(
string
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
fmt
.
Sprintf
(
"%s:%d"
,
host
,
port
)
,
nil
return
host
,
nil
}
}
}
}
...
...
builder/openstack/builder.go
View file @
115d583c
...
@@ -92,10 +92,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -92,10 +92,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
RunConfig
.
Comm
,
Config
:
&
b
.
config
.
RunConfig
.
Comm
,
SSHAddress
:
SSHAddress
(
Host
:
CommHost
(
computeClient
,
computeClient
,
b
.
config
.
SSHInterface
,
b
.
config
.
SSHInterface
),
b
.
config
.
RunConfig
.
Comm
.
SSHPort
),
SSHConfig
:
SSHConfig
(
b
.
config
.
RunConfig
.
Comm
.
SSHUsername
),
SSHConfig
:
SSHConfig
(
b
.
config
.
RunConfig
.
Comm
.
SSHUsername
),
},
},
&
common
.
StepProvision
{},
&
common
.
StepProvision
{},
...
...
builder/openstack/ssh.go
View file @
115d583c
...
@@ -13,22 +13,21 @@ import (
...
@@ -13,22 +13,21 @@ import (
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh"
)
)
// SSHAddress returns a function that can be given to the SSH communicator
// CommHost looks up the host for the communicator.
// for determining the SSH address based on the server AccessIPv4 setting..
func
CommHost
(
func
SSHAddress
(
client
*
gophercloud
.
ServiceClient
,
client
*
gophercloud
.
ServiceClient
,
sshinterface
string
,
port
int
)
func
(
multistep
.
StateBag
)
(
string
,
error
)
{
sshinterface
string
)
func
(
multistep
.
StateBag
)
(
string
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
s
:=
state
.
Get
(
"server"
)
.
(
*
servers
.
Server
)
s
:=
state
.
Get
(
"server"
)
.
(
*
servers
.
Server
)
// If we have a floating IP, use that
// If we have a floating IP, use that
ip
:=
state
.
Get
(
"access_ip"
)
.
(
*
floatingip
.
FloatingIP
)
ip
:=
state
.
Get
(
"access_ip"
)
.
(
*
floatingip
.
FloatingIP
)
if
ip
!=
nil
&&
ip
.
IP
!=
""
{
if
ip
!=
nil
&&
ip
.
IP
!=
""
{
return
fmt
.
Sprintf
(
"%s:%d"
,
ip
.
IP
,
port
)
,
nil
return
ip
.
IP
,
nil
}
}
if
s
.
AccessIPv4
!=
""
{
if
s
.
AccessIPv4
!=
""
{
return
fmt
.
Sprintf
(
"%s:%d"
,
s
.
AccessIPv4
,
port
)
,
nil
return
s
.
AccessIPv4
,
nil
}
}
// Get all the addresses associated with this server. This
// Get all the addresses associated with this server. This
...
@@ -53,7 +52,7 @@ func SSHAddress(
...
@@ -53,7 +52,7 @@ func SSHAddress(
}
}
}
}
if
addr
!=
""
{
if
addr
!=
""
{
return
fmt
.
Sprintf
(
"%s:%d"
,
addr
,
port
)
,
nil
return
addr
,
nil
}
}
}
}
}
}
...
...
builder/parallels/common/ssh.go
View file @
115d583c
package
common
package
common
import
(
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
commonssh
"github.com/mitchellh/packer/common/ssh"
commonssh
"github.com/mitchellh/packer/common/ssh"
packerssh
"github.com/mitchellh/packer/communicator/ssh"
packerssh
"github.com/mitchellh/packer/communicator/ssh"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh"
)
)
func
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
CommHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
...
@@ -23,7 +21,7 @@ func SSHAddress(state multistep.StateBag) (string, error) {
...
@@ -23,7 +21,7 @@ func SSHAddress(state multistep.StateBag) (string, error) {
return
""
,
err
return
""
,
err
}
}
return
fmt
.
Sprintf
(
"%s:22"
,
ip
)
,
nil
return
ip
,
nil
}
}
func
SSHConfigFunc
(
config
SSHConfig
)
func
(
multistep
.
StateBag
)
(
*
ssh
.
ClientConfig
,
error
)
{
func
SSHConfigFunc
(
config
SSHConfig
)
func
(
multistep
.
StateBag
)
(
*
ssh
.
ClientConfig
,
error
)
{
...
...
builder/parallels/iso/builder.go
View file @
115d583c
...
@@ -247,9 +247,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -247,9 +247,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Ctx
:
b
.
config
.
ctx
,
Ctx
:
b
.
config
.
ctx
,
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
SSHAddress
:
parallelscommon
.
SSHAddress
,
Host
:
parallelscommon
.
CommHost
,
SSHConfig
:
parallelscommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
SSHConfig
:
parallelscommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
},
},
&
parallelscommon
.
StepUploadVersion
{
&
parallelscommon
.
StepUploadVersion
{
Path
:
b
.
config
.
PrlctlVersionFile
,
Path
:
b
.
config
.
PrlctlVersionFile
,
...
...
builder/parallels/pvm/builder.go
View file @
115d583c
...
@@ -83,9 +83,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -83,9 +83,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Ctx
:
b
.
config
.
ctx
,
Ctx
:
b
.
config
.
ctx
,
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
SSHAddress
:
parallelscommon
.
SSHAddress
,
Host
:
parallelscommon
.
CommHost
,
SSHConfig
:
parallelscommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
SSHConfig
:
parallelscommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
},
},
&
parallelscommon
.
StepUploadVersion
{
&
parallelscommon
.
StepUploadVersion
{
Path
:
b
.
config
.
PrlctlVersionFile
,
Path
:
b
.
config
.
PrlctlVersionFile
,
...
...
builder/qemu/builder.go
View file @
115d583c
...
@@ -393,9 +393,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -393,9 +393,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
stepBootWait
{},
&
stepBootWait
{},
&
stepTypeBootCommand
{},
&
stepTypeBootCommand
{},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
Comm
,
Config
:
&
b
.
config
.
Comm
,
SSHAddress
:
sshAddress
,
Host
:
commHost
,
SSHConfig
:
sshConfig
,
SSHConfig
:
sshConfig
,
SSHPort
:
commPort
,
},
},
new
(
common
.
StepProvision
),
new
(
common
.
StepProvision
),
new
(
stepShutdown
),
new
(
stepShutdown
),
...
...
builder/qemu/ssh.go
View file @
115d583c
package
qemu
package
qemu
import
(
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
commonssh
"github.com/mitchellh/packer/common/ssh"
commonssh
"github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/communicator/ssh"
"github.com/mitchellh/packer/communicator/ssh"
gossh
"golang.org/x/crypto/ssh"
gossh
"golang.org/x/crypto/ssh"
)
)
func
sshAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
commHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
"127.0.0.1"
,
nil
}
func
commPort
(
state
multistep
.
StateBag
)
(
int
,
error
)
{
sshHostPort
:=
state
.
Get
(
"sshHostPort"
)
.
(
uint
)
sshHostPort
:=
state
.
Get
(
"sshHostPort"
)
.
(
uint
)
return
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
sshHostPort
),
nil
return
int
(
sshHostPort
),
nil
}
}
func
sshConfig
(
state
multistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
{
func
sshConfig
(
state
multistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
{
...
...
builder/virtualbox/common/ssh.go
View file @
115d583c
package
common
package
common
import
(
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
commonssh
"github.com/mitchellh/packer/common/ssh"
commonssh
"github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/communicator/ssh"
"github.com/mitchellh/packer/communicator/ssh"
gossh
"golang.org/x/crypto/ssh"
gossh
"golang.org/x/crypto/ssh"
)
)
func
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
CommHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
"127.0.0.1"
,
nil
}
func
SSHPort
(
state
multistep
.
StateBag
)
(
int
,
error
)
{
sshHostPort
:=
state
.
Get
(
"sshHostPort"
)
.
(
uint
)
sshHostPort
:=
state
.
Get
(
"sshHostPort"
)
.
(
uint
)
return
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
sshHostPort
),
nil
return
int
(
sshHostPort
),
nil
}
}
func
SSHConfigFunc
(
config
SSHConfig
)
func
(
multistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
{
func
SSHConfigFunc
(
config
SSHConfig
)
func
(
multistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
{
...
...
builder/virtualbox/iso/builder.go
View file @
115d583c
...
@@ -273,9 +273,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -273,9 +273,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Ctx
:
b
.
config
.
ctx
,
Ctx
:
b
.
config
.
ctx
,
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
SSHAddress
:
vboxcommon
.
SSHAddress
,
Host
:
vboxcommon
.
CommHost
,
SSHConfig
:
vboxcommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
SSHConfig
:
vboxcommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
SSHPort
:
vboxcommon
.
SSHPort
,
},
},
&
vboxcommon
.
StepUploadVersion
{
&
vboxcommon
.
StepUploadVersion
{
Path
:
b
.
config
.
VBoxVersionFile
,
Path
:
b
.
config
.
VBoxVersionFile
,
...
...
builder/virtualbox/ovf/builder.go
View file @
115d583c
...
@@ -102,9 +102,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -102,9 +102,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Ctx
:
b
.
config
.
ctx
,
Ctx
:
b
.
config
.
ctx
,
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
SSHAddress
:
vboxcommon
.
SSHAddress
,
Host
:
vboxcommon
.
CommHost
,
SSHConfig
:
vboxcommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
SSHConfig
:
vboxcommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
SSHPort
:
vboxcommon
.
SSHPort
,
},
},
&
vboxcommon
.
StepUploadVersion
{
&
vboxcommon
.
StepUploadVersion
{
Path
:
b
.
config
.
VBoxVersionFile
,
Path
:
b
.
config
.
VBoxVersionFile
,
...
...
builder/vmware/common/driver.go
View file @
115d583c
...
@@ -29,9 +29,9 @@ type Driver interface {
...
@@ -29,9 +29,9 @@ type Driver interface {
// Checks if the VMX file at the given path is running.
// Checks if the VMX file at the given path is running.
IsRunning
(
string
)
(
bool
,
error
)
IsRunning
(
string
)
(
bool
,
error
)
//
SSHAddress returns the SSH
address for the VM that is being
//
CommHost returns the host
address for the VM that is being
// managed by this driver.
// managed by this driver.
SSHAddress
(
multistep
.
StateBag
)
(
string
,
error
)
CommHost
(
multistep
.
StateBag
)
(
string
,
error
)
// Start starts a VM specified by the path to the VMX given.
// Start starts a VM specified by the path to the VMX given.
Start
(
string
,
bool
)
error
Start
(
string
,
bool
)
error
...
...
builder/vmware/common/driver_fusion5.go
View file @
115d583c
...
@@ -69,8 +69,8 @@ func (d *Fusion5Driver) IsRunning(vmxPath string) (bool, error) {
...
@@ -69,8 +69,8 @@ func (d *Fusion5Driver) IsRunning(vmxPath string) (bool, error) {
return
false
,
nil
return
false
,
nil
}
}
func
(
d
*
Fusion5Driver
)
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
(
d
*
Fusion5Driver
)
CommHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
SSHAddressFunc
(
d
.
SSHConfig
)(
state
)
return
CommHost
(
d
.
SSHConfig
)(
state
)
}
}
func
(
d
*
Fusion5Driver
)
Start
(
vmxPath
string
,
headless
bool
)
error
{
func
(
d
*
Fusion5Driver
)
Start
(
vmxPath
string
,
headless
bool
)
error
{
...
...
builder/vmware/common/driver_mock.go
View file @
115d583c
...
@@ -29,10 +29,10 @@ type DriverMock struct {
...
@@ -29,10 +29,10 @@ type DriverMock struct {
IsRunningResult
bool
IsRunningResult
bool
IsRunningErr
error
IsRunningErr
error
SSHAddress
Called
bool
CommHost
Called
bool
SSHAddress
State
multistep
.
StateBag
CommHost
State
multistep
.
StateBag
SSHAddress
Result
string
CommHost
Result
string
SSHAddress
Err
error
CommHost
Err
error
StartCalled
bool
StartCalled
bool
StartPath
string
StartPath
string
...
@@ -92,10 +92,10 @@ func (d *DriverMock) IsRunning(path string) (bool, error) {
...
@@ -92,10 +92,10 @@ func (d *DriverMock) IsRunning(path string) (bool, error) {
return
d
.
IsRunningResult
,
d
.
IsRunningErr
return
d
.
IsRunningResult
,
d
.
IsRunningErr
}
}
func
(
d
*
DriverMock
)
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
(
d
*
DriverMock
)
CommHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
d
.
SSHAddress
Called
=
true
d
.
CommHost
Called
=
true
d
.
SSHAddress
State
=
state
d
.
CommHost
State
=
state
return
d
.
SSHAddressResult
,
d
.
SSHAddress
Err
return
d
.
CommHostResult
,
d
.
CommHost
Err
}
}
func
(
d
*
DriverMock
)
Start
(
path
string
,
headless
bool
)
error
{
func
(
d
*
DriverMock
)
Start
(
path
string
,
headless
bool
)
error
{
...
...
builder/vmware/common/driver_player5.go
View file @
115d583c
...
@@ -97,8 +97,8 @@ func (d *Player5Driver) IsRunning(vmxPath string) (bool, error) {
...
@@ -97,8 +97,8 @@ func (d *Player5Driver) IsRunning(vmxPath string) (bool, error) {
return
false
,
nil
return
false
,
nil
}
}
func
(
d
*
Player5Driver
)
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
(
d
*
Player5Driver
)
CommHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
SSHAddressFunc
(
d
.
SSHConfig
)(
state
)
return
CommHost
(
d
.
SSHConfig
)(
state
)
}
}
func
(
d
*
Player5Driver
)
Start
(
vmxPath
string
,
headless
bool
)
error
{
func
(
d
*
Player5Driver
)
Start
(
vmxPath
string
,
headless
bool
)
error
{
...
...
builder/vmware/common/driver_workstation9.go
View file @
115d583c
...
@@ -70,8 +70,8 @@ func (d *Workstation9Driver) IsRunning(vmxPath string) (bool, error) {
...
@@ -70,8 +70,8 @@ func (d *Workstation9Driver) IsRunning(vmxPath string) (bool, error) {
return
false
,
nil
return
false
,
nil
}
}
func
(
d
*
Workstation9Driver
)
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
(
d
*
Workstation9Driver
)
CommHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
SSHAddressFunc
(
d
.
SSHConfig
)(
state
)
return
CommHost
(
d
.
SSHConfig
)(
state
)
}
}
func
(
d
*
Workstation9Driver
)
Start
(
vmxPath
string
,
headless
bool
)
error
{
func
(
d
*
Workstation9Driver
)
Start
(
vmxPath
string
,
headless
bool
)
error
{
...
...
builder/vmware/common/ssh.go
View file @
115d583c
...
@@ -13,13 +13,13 @@ import (
...
@@ -13,13 +13,13 @@ import (
gossh
"golang.org/x/crypto/ssh"
gossh
"golang.org/x/crypto/ssh"
)
)
func
SSHAddressFunc
(
config
*
SSHConfig
)
func
(
multistep
.
StateBag
)
(
string
,
error
)
{
func
CommHost
(
config
*
SSHConfig
)
func
(
multistep
.
StateBag
)
(
string
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
vmxPath
:=
state
.
Get
(
"vmx_path"
)
.
(
string
)
vmxPath
:=
state
.
Get
(
"vmx_path"
)
.
(
string
)
if
config
.
Comm
.
SSHHost
!=
""
{
if
config
.
Comm
.
SSHHost
!=
""
{
return
fmt
.
Sprintf
(
"%s:%d"
,
config
.
Comm
.
SSHHost
,
config
.
Comm
.
SSHPort
)
,
nil
return
config
.
Comm
.
SSHHost
,
nil
}
}
log
.
Println
(
"Lookup up IP information..."
)
log
.
Println
(
"Lookup up IP information..."
)
...
@@ -62,7 +62,7 @@ func SSHAddressFunc(config *SSHConfig) func(multistep.StateBag) (string, error)
...
@@ -62,7 +62,7 @@ func SSHAddressFunc(config *SSHConfig) func(multistep.StateBag) (string, error)
}
}
log
.
Printf
(
"Detected IP: %s"
,
ipAddress
)
log
.
Printf
(
"Detected IP: %s"
,
ipAddress
)
return
fmt
.
Sprintf
(
"%s:%d"
,
ipAddress
,
config
.
Comm
.
SSHPort
)
,
nil
return
ipAddress
,
nil
}
}
}
}
...
...
builder/vmware/iso/builder.go
View file @
115d583c
...
@@ -300,9 +300,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -300,9 +300,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Ctx
:
b
.
config
.
ctx
,
Ctx
:
b
.
config
.
ctx
,
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
SSHAddress
:
driver
.
SSHAddress
,
Host
:
driver
.
CommHost
,
SSHConfig
:
vmwcommon
.
SSHConfigFunc
(
&
b
.
config
.
SSHConfig
),
SSHConfig
:
vmwcommon
.
SSHConfigFunc
(
&
b
.
config
.
SSHConfig
),
},
},
&
vmwcommon
.
StepUploadTools
{
&
vmwcommon
.
StepUploadTools
{
RemoteType
:
b
.
config
.
RemoteType
,
RemoteType
:
b
.
config
.
RemoteType
,
...
...
builder/vmware/iso/driver_esx5.go
View file @
115d583c
...
@@ -218,7 +218,7 @@ func (d *ESX5Driver) VNCAddress(portMin, portMax uint) (string, uint, error) {
...
@@ -218,7 +218,7 @@ func (d *ESX5Driver) VNCAddress(portMin, portMax uint) (string, uint, error) {
return
d
.
Host
,
vncPort
,
nil
return
d
.
Host
,
vncPort
,
nil
}
}
func
(
d
*
ESX5Driver
)
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
func
(
d
*
ESX5Driver
)
CommHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
if
address
,
ok
:=
state
.
GetOk
(
"vm_address"
);
ok
{
if
address
,
ok
:=
state
.
GetOk
(
"vm_address"
);
ok
{
...
@@ -253,7 +253,7 @@ func (d *ESX5Driver) SSHAddress(state multistep.StateBag) (string, error) {
...
@@ -253,7 +253,7 @@ func (d *ESX5Driver) SSHAddress(state multistep.StateBag) (string, error) {
return
""
,
errors
.
New
(
"VM network port found, but no IP address"
)
return
""
,
errors
.
New
(
"VM network port found, but no IP address"
)
}
}
address
:=
fmt
.
Sprintf
(
"%s:%d"
,
record
[
"IPAddress"
],
config
.
Comm
.
SSHPort
)
address
:=
record
[
"IPAddress"
]
state
.
Put
(
"vm_address"
,
address
)
state
.
Put
(
"vm_address"
,
address
)
return
address
,
nil
return
address
,
nil
}
}
...
...
builder/vmware/vmx/builder.go
View file @
115d583c
...
@@ -92,9 +92,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -92,9 +92,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Ctx
:
b
.
config
.
ctx
,
Ctx
:
b
.
config
.
ctx
,
},
},
&
communicator
.
StepConnect
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
SSHAddress
:
driver
.
SSHAddress
,
Host
:
driver
.
CommHost
,
SSHConfig
:
vmwcommon
.
SSHConfigFunc
(
&
b
.
config
.
SSHConfig
),
SSHConfig
:
vmwcommon
.
SSHConfigFunc
(
&
b
.
config
.
SSHConfig
),
},
},
&
vmwcommon
.
StepUploadTools
{
&
vmwcommon
.
StepUploadTools
{
RemoteType
:
b
.
config
.
RemoteType
,
RemoteType
:
b
.
config
.
RemoteType
,
...
...
helper/communicator/step_connect.go
View file @
115d583c
...
@@ -15,15 +15,16 @@ type StepConnect struct {
...
@@ -15,15 +15,16 @@ type StepConnect struct {
// Config is the communicator config struct
// Config is the communicator config struct
Config
*
Config
Config
*
Config
// Host should return a host that can be connected to for communicator
// connections.
Host
func
(
multistep
.
StateBag
)
(
string
,
error
)
// The fields below are callbacks to assist with connecting to SSH.
// The fields below are callbacks to assist with connecting to SSH.
//
//
// SSHAddress should return the default host to connect to for SSH.
// This is only called if ssh_host isn't specified in the config.
//
// SSHConfig should return the default configuration for
// SSHConfig should return the default configuration for
// connecting via SSH.
// connecting via SSH.
SSH
Address
func
(
multistep
.
StateBag
)
(
strin
g
,
error
)
SSH
Config
func
(
multistep
.
StateBag
)
(
*
gossh
.
ClientConfi
g
,
error
)
SSH
Config
func
(
multistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
SSH
Port
func
(
multistep
.
StateBag
)
(
int
,
error
)
substep
multistep
.
Step
substep
multistep
.
Step
}
}
...
@@ -32,9 +33,10 @@ func (s *StepConnect) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -32,9 +33,10 @@ func (s *StepConnect) Run(state multistep.StateBag) multistep.StepAction {
typeMap
:=
map
[
string
]
multistep
.
Step
{
typeMap
:=
map
[
string
]
multistep
.
Step
{
"none"
:
nil
,
"none"
:
nil
,
"ssh"
:
&
StepConnectSSH
{
"ssh"
:
&
StepConnectSSH
{
Config
:
s
.
Config
,
Config
:
s
.
Config
,
SSHAddress
:
s
.
SSHAddress
,
Host
:
s
.
Host
,
SSHConfig
:
s
.
SSHConfig
,
SSHConfig
:
s
.
SSHConfig
,
SSHPort
:
s
.
SSHPort
,
},
},
}
}
...
...
helper/communicator/step_connect_ssh.go
View file @
115d583c
...
@@ -18,9 +18,10 @@ import (
...
@@ -18,9 +18,10 @@ import (
// In general, you should use StepConnect.
// In general, you should use StepConnect.
type
StepConnectSSH
struct
{
type
StepConnectSSH
struct
{
// All the fields below are documented on StepConnect
// All the fields below are documented on StepConnect
Config
*
Config
Config
*
Config
SSHAddress
func
(
multistep
.
StateBag
)
(
string
,
error
)
Host
func
(
multistep
.
StateBag
)
(
string
,
error
)
SSHConfig
func
(
multistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
SSHConfig
func
(
multistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
SSHPort
func
(
multistep
.
StateBag
)
(
int
,
error
)
}
}
func
(
s
*
StepConnectSSH
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
StepConnectSSH
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
...
@@ -95,11 +96,19 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, cancel <-chan stru
...
@@ -95,11 +96,19 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, cancel <-chan stru
first
=
false
first
=
false
// First we request the TCP connection information
// First we request the TCP connection information
address
,
err
:=
s
.
SSHAddress
(
state
)
host
,
err
:=
s
.
Host
(
state
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"[DEBUG] Error getting SSH address: %s"
,
err
)
log
.
Printf
(
"[DEBUG] Error getting SSH address: %s"
,
err
)
continue
continue
}
}
port
:=
s
.
Config
.
SSHPort
if
s
.
SSHPort
!=
nil
{
port
,
err
=
s
.
SSHPort
(
state
)
if
err
!=
nil
{
log
.
Printf
(
"[DEBUG] Error getting SSH port: %s"
,
err
)
continue
}
}
// Retrieve the SSH configuration
// Retrieve the SSH configuration
sshConfig
,
err
:=
s
.
SSHConfig
(
state
)
sshConfig
,
err
:=
s
.
SSHConfig
(
state
)
...
@@ -108,6 +117,8 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, cancel <-chan stru
...
@@ -108,6 +117,8 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, cancel <-chan stru
continue
continue
}
}
address
:=
fmt
.
Sprintf
(
"%s:%d"
,
host
,
port
)
// Attempt to connect to SSH port
// Attempt to connect to SSH port
connFunc
:=
ssh
.
ConnectFunc
(
"tcp"
,
address
)
connFunc
:=
ssh
.
ConnectFunc
(
"tcp"
,
address
)
nc
,
err
:=
connFunc
()
nc
,
err
:=
connFunc
()
...
...
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