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
89af447c
Commit
89af447c
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/qemu: convert to helper/comm
parent
820bad69
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
54 deletions
+33
-54
builder/qemu/builder.go
builder/qemu/builder.go
+26
-43
builder/qemu/builder_test.go
builder/qemu/builder_test.go
+2
-6
builder/qemu/ssh.go
builder/qemu/ssh.go
+5
-5
No files found.
builder/qemu/builder.go
View file @
89af447c
...
...
@@ -12,7 +12,7 @@ import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
commonssh
"github.com/mitchellh/packer/common/ssh
"
"github.com/mitchellh/packer/helper/communicator
"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
...
...
@@ -78,6 +78,7 @@ type Builder struct {
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
Comm
communicator
.
Config
`mapstructure:",squash"`
Accelerator
string
`mapstructure:"accelerator"`
BootCommand
[]
string
`mapstructure:"boot_command"`
...
...
@@ -103,25 +104,24 @@ type Config struct {
ShutdownCommand
string
`mapstructure:"shutdown_command"`
SSHHostPortMin
uint
`mapstructure:"ssh_host_port_min"`
SSHHostPortMax
uint
`mapstructure:"ssh_host_port_max"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHUser
string
`mapstructure:"ssh_username"`
SSHKeyPath
string
`mapstructure:"ssh_key_path"`
VNCPortMin
uint
`mapstructure:"vnc_port_min"`
VNCPortMax
uint
`mapstructure:"vnc_port_max"`
VMName
string
`mapstructure:"vm_name"`
// 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"`
// TODO(mitchellh): deprecate
RunOnce
bool
`mapstructure:"run_once"`
RawBootWait
string
`mapstructure:"boot_wait"`
RawSingleISOUrl
string
`mapstructure:"iso_url"`
RawShutdownTimeout
string
`mapstructure:"shutdown_timeout"`
RawSSHWaitTimeout
string
`mapstructure:"ssh_wait_timeout"`
bootWait
time
.
Duration
``
shutdownTimeout
time
.
Duration
``
sshWaitTimeout
time
.
Duration
``
ctx
interpolate
.
Context
}
...
...
@@ -139,9 +139,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return
nil
,
err
}
var
errs
*
packer
.
MultiError
warnings
:=
make
([]
string
,
0
)
if
b
.
config
.
DiskSize
==
0
{
b
.
config
.
DiskSize
=
40000
}
...
...
@@ -190,10 +187,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
SSHHostPortMax
=
4444
}
if
b
.
config
.
SSHPort
==
0
{
b
.
config
.
SSHPort
=
22
}
if
b
.
config
.
VNCPortMin
==
0
{
b
.
config
.
VNCPortMin
=
5900
}
...
...
@@ -222,6 +215,21 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
DiskInterface
=
"virtio"
}
// TODO: backwards compatibility, write fixer instead
if
b
.
config
.
SSHKeyPath
!=
""
{
b
.
config
.
Comm
.
SSHPrivateKey
=
b
.
config
.
SSHKeyPath
}
if
b
.
config
.
SSHWaitTimeout
!=
0
{
b
.
config
.
Comm
.
SSHTimeout
=
b
.
config
.
SSHWaitTimeout
}
var
errs
*
packer
.
MultiError
warnings
:=
make
([]
string
,
0
)
if
es
:=
b
.
config
.
Comm
.
Prepare
(
&
b
.
config
.
ctx
);
len
(
es
)
>
0
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
es
...
)
}
if
!
(
b
.
config
.
Format
==
"qcow2"
||
b
.
config
.
Format
==
"raw"
)
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"invalid format, only 'qcow2' or 'raw' are allowed"
))
...
...
@@ -314,42 +322,17 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
RawShutdownTimeout
=
"5m"
}
if
b
.
config
.
RawSSHWaitTimeout
==
""
{
b
.
config
.
RawSSHWaitTimeout
=
"20m"
}
b
.
config
.
shutdownTimeout
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawShutdownTimeout
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Failed parsing shutdown_timeout: %s"
,
err
))
}
if
b
.
config
.
SSHKeyPath
!=
""
{
if
_
,
err
:=
os
.
Stat
(
b
.
config
.
SSHKeyPath
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
else
if
_
,
err
:=
commonssh
.
FileSigner
(
b
.
config
.
SSHKeyPath
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
}
if
b
.
config
.
SSHHostPortMin
>
b
.
config
.
SSHHostPortMax
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"ssh_host_port_min must be less than ssh_host_port_max"
))
}
if
b
.
config
.
SSHUser
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"An ssh_username must be specified."
))
}
b
.
config
.
sshWaitTimeout
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawSSHWaitTimeout
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_wait_timeout: %s"
,
err
))
}
if
b
.
config
.
VNCPortMin
>
b
.
config
.
VNCPortMax
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"vnc_port_min must be less than vnc_port_max"
))
...
...
@@ -409,10 +392,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
steprun
,
&
stepBootWait
{},
&
stepTypeBootCommand
{},
&
comm
on
.
StepConnectSSH
{
SSHAddress
:
sshAddress
,
SSH
Config
:
sshConfig
,
SSH
WaitTimeout
:
b
.
config
.
sshWaitTimeout
,
&
comm
unicator
.
StepConnect
{
Config
:
&
b
.
config
.
Comm
,
SSH
Address
:
sshAddress
,
SSH
Config
:
sshConfig
,
},
new
(
common
.
StepProvision
),
new
(
stepShutdown
),
...
...
builder/qemu/builder_test.go
View file @
89af447c
...
...
@@ -79,8 +79,8 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
t
.
Errorf
(
"bad max ssh host port: %d"
,
b
.
config
.
SSHHostPortMax
)
}
if
b
.
config
.
SSHPort
!=
22
{
t
.
Errorf
(
"bad ssh port: %d"
,
b
.
config
.
SSHPort
)
if
b
.
config
.
Comm
.
SSHPort
!=
22
{
t
.
Errorf
(
"bad ssh port: %d"
,
b
.
config
.
Comm
.
SSHPort
)
}
if
b
.
config
.
VMName
!=
"packer-foo"
{
...
...
@@ -595,10 +595,6 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
b
.
config
.
RawSSHWaitTimeout
!=
"20m"
{
t
.
Fatalf
(
"bad value: %s"
,
b
.
config
.
RawSSHWaitTimeout
)
}
// Test with a bad value
config
[
"ssh_wait_timeout"
]
=
"this is not good"
b
=
Builder
{}
...
...
builder/qemu/ssh.go
View file @
89af447c
...
...
@@ -18,13 +18,13 @@ func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
auth
:=
[]
gossh
.
AuthMethod
{
gossh
.
Password
(
config
.
SSHPassword
),
gossh
.
Password
(
config
.
Comm
.
SSHPassword
),
gossh
.
KeyboardInteractive
(
ssh
.
PasswordKeyboardInteractive
(
config
.
SSHPassword
)),
ssh
.
PasswordKeyboardInteractive
(
config
.
Comm
.
SSHPassword
)),
}
if
config
.
SSHKeyPath
!=
""
{
signer
,
err
:=
commonssh
.
FileSigner
(
config
.
SSHKeyPath
)
if
config
.
Comm
.
SSHPrivateKey
!=
""
{
signer
,
err
:=
commonssh
.
FileSigner
(
config
.
Comm
.
SSHPrivateKey
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -33,7 +33,7 @@ func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
}
return
&
gossh
.
ClientConfig
{
User
:
config
.
SSHUser
,
User
:
config
.
Comm
.
SSHUsername
,
Auth
:
auth
,
},
nil
}
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