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
820bad69
Commit
820bad69
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/parallels: convert to new comm type
parent
f55e2d2c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
84 deletions
+36
-84
builder/parallels/common/ssh.go
builder/parallels/common/ssh.go
+4
-4
builder/parallels/common/ssh_config.go
builder/parallels/common/ssh_config.go
+11
-34
builder/parallels/common/ssh_config_test.go
builder/parallels/common/ssh_config_test.go
+9
-37
builder/parallels/iso/builder.go
builder/parallels/iso/builder.go
+5
-4
builder/parallels/pvm/builder.go
builder/parallels/pvm/builder.go
+7
-5
No files found.
builder/parallels/common/ssh.go
View file @
820bad69
...
...
@@ -29,13 +29,13 @@ func SSHAddress(state multistep.StateBag) (string, error) {
func
SSHConfigFunc
(
config
SSHConfig
)
func
(
multistep
.
StateBag
)
(
*
ssh
.
ClientConfig
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
*
ssh
.
ClientConfig
,
error
)
{
auth
:=
[]
ssh
.
AuthMethod
{
ssh
.
Password
(
config
.
SSHPassword
),
ssh
.
Password
(
config
.
Comm
.
SSHPassword
),
ssh
.
KeyboardInteractive
(
packerssh
.
PasswordKeyboardInteractive
(
config
.
SSHPassword
)),
packerssh
.
PasswordKeyboardInteractive
(
config
.
Comm
.
SSHPassword
)),
}
if
config
.
SSHKeyPath
!=
""
{
signer
,
err
:=
commonssh
.
FileSigner
(
config
.
SSHKeyPath
)
signer
,
err
:=
commonssh
.
FileSigner
(
config
.
Comm
.
SSHPrivateKey
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -44,7 +44,7 @@ func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*ssh.ClientConfig
}
return
&
ssh
.
ClientConfig
{
User
:
config
.
SSHUser
,
User
:
config
.
Comm
.
SSHUsername
,
Auth
:
auth
,
},
nil
}
...
...
builder/parallels/common/ssh_config.go
View file @
820bad69
package
common
import
(
"errors"
"fmt"
"os"
"time"
commonssh
"github.com/mitchellh/packer/common/ssh
"
"github.com/mitchellh/packer/helper/communicator
"
"github.com/mitchellh/packer/template/interpolate"
)
type
SSHConfig
struct
{
SSHKeyPath
string
`mapstructure:"ssh_key_path"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHUser
string
`mapstructure:"ssh_username"`
RawSSHWaitTimeout
string
`mapstructure:"ssh_wait_timeout"`
Comm
communicator
.
Config
`mapstructure:",squash"`
SSHWaitTimeout
time
.
Duration
// These are deprecated, but we keep them around for BC
// TODO(@mitchellh): remove
SSHKeyPath
string
`mapstructure:"ssh_key_path"`
SSHWaitTimeout
time
.
Duration
`mapstructure:"ssh_wait_timeout"`
}
func
(
c
*
SSHConfig
)
Prepare
(
ctx
*
interpolate
.
Context
)
[]
error
{
if
c
.
SSHPort
==
0
{
c
.
SSHPort
=
22
}
if
c
.
RawSSHWaitTimeout
==
""
{
c
.
RawSSHWaitTimeout
=
"20m"
}
var
errs
[]
error
// TODO: backwards compatibility, write fixer instead
if
c
.
SSHKeyPath
!=
""
{
if
_
,
err
:=
os
.
Stat
(
c
.
SSHKeyPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
else
if
_
,
err
:=
commonssh
.
FileSigner
(
c
.
SSHKeyPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
c
.
Comm
.
SSHPrivateKey
=
c
.
SSHKeyPath
}
if
c
.
SSHUser
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"An ssh_username must be specified."
))
}
var
err
error
c
.
SSHWaitTimeout
,
err
=
time
.
ParseDuration
(
c
.
RawSSHWaitTimeout
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_wait_timeout: %s"
,
err
))
if
c
.
SSHWaitTimeout
!=
0
{
c
.
Comm
.
SSHTimeout
=
c
.
SSHWaitTimeout
}
return
errs
return
c
.
Comm
.
Prepare
(
ctx
)
}
builder/parallels/common/ssh_config_test.go
View file @
820bad69
...
...
@@ -4,11 +4,15 @@ import (
"io/ioutil"
"os"
"testing"
"github.com/mitchellh/packer/helper/communicator"
)
func
testSSHConfig
()
*
SSHConfig
{
return
&
SSHConfig
{
SSHUser
:
"foo"
,
Comm
:
communicator
.
Config
{
SSHUsername
:
"foo"
,
},
}
}
...
...
@@ -19,8 +23,8 @@ func TestSSHConfigPrepare(t *testing.T) {
t
.
Fatalf
(
"err: %#v"
,
errs
)
}
if
c
.
SSHPort
!=
22
{
t
.
Errorf
(
"bad ssh port: %d"
,
c
.
SSHPort
)
if
c
.
Comm
.
SSHPort
!=
22
{
t
.
Errorf
(
"bad ssh port: %d"
,
c
.
Comm
.
SSHPort
)
}
}
...
...
@@ -78,46 +82,14 @@ func TestSSHConfigPrepare_SSHUser(t *testing.T) {
var
errs
[]
error
c
=
testSSHConfig
()
c
.
SSHUser
=
""
c
.
Comm
.
SSHUsername
=
""
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
==
0
{
t
.
Fatalf
(
"should have error"
)
}
c
=
testSSHConfig
()
c
.
SSHUser
=
"exists"
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"should not have error: %#v"
,
errs
)
}
}
func
TestSSHConfigPrepare_SSHWaitTimeout
(
t
*
testing
.
T
)
{
var
c
*
SSHConfig
var
errs
[]
error
// Defaults
c
=
testSSHConfig
()
c
.
RawSSHWaitTimeout
=
""
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"should not have error: %#v"
,
errs
)
}
if
c
.
RawSSHWaitTimeout
!=
"20m"
{
t
.
Fatalf
(
"bad value: %s"
,
c
.
RawSSHWaitTimeout
)
}
// Test with a bad value
c
=
testSSHConfig
()
c
.
RawSSHWaitTimeout
=
"this is not good"
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
==
0
{
t
.
Fatal
(
"should have error"
)
}
// Test with a good one
c
=
testSSHConfig
()
c
.
RawSSHWaitTimeout
=
"5s"
c
.
Comm
.
SSHUsername
=
"exists"
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"should not have error: %#v"
,
errs
)
...
...
builder/parallels/iso/builder.go
View file @
820bad69
...
...
@@ -9,6 +9,7 @@ import (
"github.com/mitchellh/multistep"
parallelscommon
"github.com/mitchellh/packer/builder/parallels/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
...
...
@@ -245,10 +246,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
VMName
:
b
.
config
.
VMName
,
Ctx
:
b
.
config
.
ctx
,
},
&
comm
on
.
StepConnectSSH
{
SSHAddress
:
parallelscommon
.
SSHAddress
,
SSH
Config
:
parallelscommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
)
,
SSH
WaitTimeout
:
b
.
config
.
SSHWaitTimeout
,
&
comm
unicator
.
StepConnect
{
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
SSH
Address
:
parallelscommon
.
SSHAddress
,
SSH
Config
:
parallelscommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
)
,
},
&
parallelscommon
.
StepUploadVersion
{
Path
:
b
.
config
.
PrlctlVersionFile
,
...
...
builder/parallels/pvm/builder.go
View file @
820bad69
...
...
@@ -3,11 +3,13 @@ package pvm
import
(
"errors"
"fmt"
"log"
"github.com/mitchellh/multistep"
parallelscommon
"github.com/mitchellh/packer/builder/parallels/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/packer"
"log"
)
// Builder implements packer.Builder and builds the actual Parallels
...
...
@@ -80,10 +82,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
VMName
:
b
.
config
.
VMName
,
Ctx
:
b
.
config
.
ctx
,
},
&
comm
on
.
StepConnectSSH
{
SSHAddress
:
parallelscommon
.
SSHAddress
,
SSH
Config
:
parallelscommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
)
,
SSH
WaitTimeout
:
b
.
config
.
SSHWaitTimeout
,
&
comm
unicator
.
StepConnect
{
Config
:
&
b
.
config
.
SSHConfig
.
Comm
,
SSH
Address
:
parallelscommon
.
SSHAddress
,
SSH
Config
:
parallelscommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
)
,
},
&
parallelscommon
.
StepUploadVersion
{
Path
:
b
.
config
.
PrlctlVersionFile
,
...
...
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