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
d545431f
Commit
d545431f
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/null: adopt helper/communicator
parent
4b3ed5d7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
30 deletions
+27
-30
builder/null/builder.go
builder/null/builder.go
+11
-6
builder/null/config.go
builder/null/config.go
+11
-19
builder/null/config_test.go
builder/null/config_test.go
+5
-5
No files found.
builder/null/builder.go
View file @
d545431f
package
null
package
null
import
(
import
(
"log"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"log"
"time"
)
)
const
BuilderId
=
"fnoeding.null"
const
BuilderId
=
"fnoeding.null"
...
@@ -27,10 +28,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
...
@@ -27,10 +28,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
steps
:=
[]
multistep
.
Step
{
steps
:=
[]
multistep
.
Step
{
&
common
.
StepConnectSSH
{
&
communicator
.
StepConnect
{
SSHAddress
:
SSHAddress
(
b
.
config
.
Host
,
b
.
config
.
Port
),
Config
:
&
b
.
config
.
CommConfig
,
SSHConfig
:
SSHConfig
(
b
.
config
.
SSHUsername
,
b
.
config
.
SSHPassword
,
b
.
config
.
SSHPrivateKeyFile
),
SSHAddress
:
SSHAddress
(
SSHWaitTimeout
:
1
*
time
.
Minute
,
b
.
config
.
CommConfig
.
SSHHost
,
b
.
config
.
CommConfig
.
SSHPort
),
SSHConfig
:
SSHConfig
(
b
.
config
.
CommConfig
.
SSHUsername
,
b
.
config
.
CommConfig
.
SSHPassword
,
b
.
config
.
CommConfig
.
SSHPrivateKey
),
},
},
&
common
.
StepProvision
{},
&
common
.
StepProvision
{},
}
}
...
...
builder/null/config.go
View file @
d545431f
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"fmt"
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/template/interpolate"
...
@@ -12,49 +13,40 @@ import (
...
@@ -12,49 +13,40 @@ import (
type
Config
struct
{
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
Host
string
`mapstructure:"host"`
CommConfig
communicator
.
Config
`mapstructure:",squash"`
Port
int
`mapstructure:"port"`
SSHUsername
string
`mapstructure:"ssh_username"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHPrivateKeyFile
string
`mapstructure:"ssh_private_key_file"`
}
}
func
NewConfig
(
raws
...
interface
{})
(
*
Config
,
[]
string
,
error
)
{
func
NewConfig
(
raws
...
interface
{})
(
*
Config
,
[]
string
,
error
)
{
var
c
Config
var
c
Config
err
:=
config
.
Decode
(
&
c
,
&
config
.
DecodeOpts
{
err
:=
config
.
Decode
(
&
c
,
&
config
.
DecodeOpts
{
Interpolate
:
true
,
Interpolate
:
true
,
InterpolateFilter
:
&
interpolate
.
RenderFilter
{
InterpolateFilter
:
&
interpolate
.
RenderFilter
{},
Exclude
:
[]
string
{
"run_command"
,
},
},
},
raws
...
)
},
raws
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
if
c
.
Port
==
0
{
c
.
Port
=
22
}
var
errs
*
packer
.
MultiError
var
errs
*
packer
.
MultiError
if
c
.
Host
==
""
{
if
es
:=
c
.
CommConfig
.
Prepare
(
nil
);
len
(
es
)
>
0
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
es
...
)
}
if
c
.
CommConfig
.
SSHHost
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"host must be specified"
))
fmt
.
Errorf
(
"host must be specified"
))
}
}
if
c
.
SSHUsername
==
""
{
if
c
.
CommConfig
.
SSHUsername
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"ssh_username must be specified"
))
fmt
.
Errorf
(
"ssh_username must be specified"
))
}
}
if
c
.
SSHPassword
==
""
&&
c
.
SSHPrivateKeyFile
==
""
{
if
c
.
CommConfig
.
SSHPassword
==
""
&&
c
.
CommConfig
.
SSHPrivateKey
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"one of ssh_password and ssh_private_key_file must be specified"
))
fmt
.
Errorf
(
"one of ssh_password and ssh_private_key_file must be specified"
))
}
}
if
c
.
SSHPassword
!=
""
&&
c
.
SSHPrivateKeyFile
!=
""
{
if
c
.
CommConfig
.
SSHPassword
!=
""
&&
c
.
CommConfig
.
SSHPrivateKey
!=
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"only one of ssh_password and ssh_private_key_file must be specified"
))
fmt
.
Errorf
(
"only one of ssh_password and ssh_private_key_file must be specified"
))
}
}
...
...
builder/null/config_test.go
View file @
d545431f
...
@@ -6,7 +6,7 @@ import (
...
@@ -6,7 +6,7 @@ import (
func
testConfig
()
map
[
string
]
interface
{}
{
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
return
map
[
string
]
interface
{}{
"
host"
:
"foo"
,
"
ssh_host"
:
"foo"
,
"ssh_username"
:
"bar"
,
"ssh_username"
:
"bar"
,
"ssh_password"
:
"baz"
,
"ssh_password"
:
"baz"
,
}
}
...
@@ -48,8 +48,8 @@ func TestConfigPrepare_port(t *testing.T) {
...
@@ -48,8 +48,8 @@ func TestConfigPrepare_port(t *testing.T) {
// default port should be 22
// default port should be 22
delete
(
raw
,
"port"
)
delete
(
raw
,
"port"
)
c
,
warns
,
errs
:=
NewConfig
(
raw
)
c
,
warns
,
errs
:=
NewConfig
(
raw
)
if
c
.
Port
!=
22
{
if
c
.
CommConfig
.
SSH
Port
!=
22
{
t
.
Fatalf
(
"bad: port should default to 22, not %d"
,
c
.
Port
)
t
.
Fatalf
(
"bad: port should default to 22, not %d"
,
c
.
CommConfig
.
SSH
Port
)
}
}
testConfigOk
(
t
,
warns
,
errs
)
testConfigOk
(
t
,
warns
,
errs
)
}
}
...
@@ -58,12 +58,12 @@ func TestConfigPrepare_host(t *testing.T) {
...
@@ -58,12 +58,12 @@ func TestConfigPrepare_host(t *testing.T) {
raw
:=
testConfig
()
raw
:=
testConfig
()
// No host
// No host
delete
(
raw
,
"host"
)
delete
(
raw
,
"
ssh_
host"
)
_
,
warns
,
errs
:=
NewConfig
(
raw
)
_
,
warns
,
errs
:=
NewConfig
(
raw
)
testConfigErr
(
t
,
warns
,
errs
)
testConfigErr
(
t
,
warns
,
errs
)
// Good host
// Good host
raw
[
"host"
]
=
"good"
raw
[
"
ssh_
host"
]
=
"good"
_
,
warns
,
errs
=
NewConfig
(
raw
)
_
,
warns
,
errs
=
NewConfig
(
raw
)
testConfigOk
(
t
,
warns
,
errs
)
testConfigOk
(
t
,
warns
,
errs
)
}
}
...
...
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