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
e5579281
Commit
e5579281
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon: use helper/communicator
parent
a1ceb5a7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
65 deletions
+38
-65
builder/amazon/common/run_config.go
builder/amazon/common/run_config.go
+5
-32
builder/amazon/common/run_config_test.go
builder/amazon/common/run_config_test.go
+13
-21
builder/amazon/ebs/builder.go
builder/amazon/ebs/builder.go
+10
-6
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+10
-6
No files found.
builder/amazon/common/run_config.go
View file @
e5579281
...
...
@@ -4,9 +4,9 @@ import (
"errors"
"fmt"
"os"
"time"
"github.com/mitchellh/packer/common/uuid"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/template/interpolate"
)
...
...
@@ -21,11 +21,6 @@ type RunConfig struct {
SourceAmi
string
`mapstructure:"source_ami"`
SpotPrice
string
`mapstructure:"spot_price"`
SpotPriceAutoProduct
string
`mapstructure:"spot_price_auto_product"`
RawSSHTimeout
string
`mapstructure:"ssh_timeout"`
SSHUsername
string
`mapstructure:"ssh_username"`
SSHPrivateKeyFile
string
`mapstructure:"ssh_private_key_file"`
SSHPrivateIp
bool
`mapstructure:"ssh_private_ip"`
SSHPort
int
`mapstructure:"ssh_port"`
SecurityGroupId
string
`mapstructure:"security_group_id"`
SecurityGroupIds
[]
string
`mapstructure:"security_group_ids"`
SubnetId
string
`mapstructure:"subnet_id"`
...
...
@@ -34,27 +29,19 @@ type RunConfig struct {
UserDataFile
string
`mapstructure:"user_data_file"`
VpcId
string
`mapstructure:"vpc_id"`
// Unexported fields that are calculated from others
sshTimeout
time
.
Duration
// Communicator settings
Comm
communicator
.
Config
`mapstructure:",squash"`
SSHPrivateIp
bool
`mapstructure:"ssh_private_ip"`
}
func
(
c
*
RunConfig
)
Prepare
(
ctx
*
interpolate
.
Context
)
[]
error
{
// Defaults
if
c
.
SSHPort
==
0
{
c
.
SSHPort
=
22
}
if
c
.
RawSSHTimeout
==
""
{
c
.
RawSSHTimeout
=
"5m"
}
if
c
.
TemporaryKeyPairName
==
""
{
c
.
TemporaryKeyPairName
=
fmt
.
Sprintf
(
"packer %s"
,
uuid
.
TimeOrderedUUID
())
}
// Validation
var
errs
[]
error
errs
:=
c
.
Comm
.
Prepare
(
ctx
)
if
c
.
SourceAmi
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"A source_ami must be specified"
))
}
...
...
@@ -70,10 +57,6 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
}
}
if
c
.
SSHUsername
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"An ssh_username must be specified"
))
}
if
c
.
UserData
!=
""
&&
c
.
UserDataFile
!=
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Only one of user_data or user_data_file can be specified."
))
}
else
if
c
.
UserDataFile
!=
""
{
...
...
@@ -91,15 +74,5 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
}
}
var
err
error
c
.
sshTimeout
,
err
=
time
.
ParseDuration
(
c
.
RawSSHTimeout
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_timeout: %s"
,
err
))
}
return
errs
}
func
(
c
*
RunConfig
)
SSHTimeout
()
time
.
Duration
{
return
c
.
sshTimeout
}
builder/amazon/common/run_config_test.go
View file @
e5579281
...
...
@@ -4,6 +4,8 @@ import (
"io/ioutil"
"os"
"testing"
"github.com/mitchellh/packer/helper/communicator"
)
func
init
()
{
...
...
@@ -19,7 +21,10 @@ func testConfig() *RunConfig {
return
&
RunConfig
{
SourceAmi
:
"abcd"
,
InstanceType
:
"m1.small"
,
SSHUsername
:
"root"
,
Comm
:
communicator
.
Config
{
SSHUsername
:
"foo"
,
},
}
}
...
...
@@ -62,41 +67,28 @@ func TestRunConfigPrepare_SpotAuto(t *testing.T) {
func
TestRunConfigPrepare_SSHPort
(
t
*
testing
.
T
)
{
c
:=
testConfig
()
c
.
SSHPort
=
0
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
0
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
c
.
SSHPort
!=
22
{
t
.
Fatalf
(
"invalid value: %d"
,
c
.
SSHPort
)
}
c
.
SSHPort
=
44
c
.
Comm
.
SSHPort
=
0
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
0
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
c
.
SSHPort
!=
44
{
t
.
Fatalf
(
"invalid value: %d"
,
c
.
SSHPort
)
if
c
.
Comm
.
SSHPort
!=
22
{
t
.
Fatalf
(
"invalid value: %d"
,
c
.
Comm
.
SSHPort
)
}
}
func
TestRunConfigPrepare_SSHTimeout
(
t
*
testing
.
T
)
{
c
:=
testConfig
()
c
.
RawSSHTimeout
=
""
c
.
Comm
.
SSHPort
=
44
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
0
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
c
.
RawSSHTimeout
=
"bad"
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
1
{
t
.
Fatalf
(
"err: %s"
,
err
)
if
c
.
Comm
.
SSHPort
!=
44
{
t
.
Fatalf
(
"invalid value: %d"
,
c
.
Comm
.
SSHPort
)
}
}
func
TestRunConfigPrepare_SSHUsername
(
t
*
testing
.
T
)
{
c
:=
testConfig
()
c
.
SSHUsername
=
""
c
.
Comm
.
SSHUsername
=
""
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
1
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
...
...
builder/amazon/ebs/builder.go
View file @
e5579281
...
...
@@ -13,6 +13,7 @@ import (
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/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"
...
...
@@ -89,11 +90,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Debug
:
b
.
config
.
PackerDebug
,
DebugKeyPath
:
fmt
.
Sprintf
(
"ec2_%s.pem"
,
b
.
config
.
PackerBuildName
),
KeyPairName
:
b
.
config
.
TemporaryKeyPairName
,
PrivateKeyFile
:
b
.
config
.
SSHPrivateKeyFile
,
PrivateKeyFile
:
b
.
config
.
RunConfig
.
Comm
.
SSHPrivateKey
,
},
&
awscommon
.
StepSecurityGroup
{
SecurityGroupIds
:
b
.
config
.
SecurityGroupIds
,
SSHPort
:
b
.
config
.
SSHPort
,
SSHPort
:
b
.
config
.
RunConfig
.
Comm
.
SSHPort
,
VpcId
:
b
.
config
.
VpcId
,
},
&
awscommon
.
StepRunSourceInstance
{
...
...
@@ -112,11 +113,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDevices
:
b
.
config
.
BlockDevices
,
Tags
:
b
.
config
.
RunTags
,
},
&
common
.
StepConnectSSH
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
RunConfig
.
Comm
,
SSHAddress
:
awscommon
.
SSHAddress
(
ec2conn
,
b
.
config
.
SSHPort
,
b
.
config
.
SSHPrivateIp
),
SSHConfig
:
awscommon
.
SSHConfig
(
b
.
config
.
SSHUsername
),
SSHWaitTimeout
:
b
.
config
.
SSHTimeout
(),
ec2conn
,
b
.
config
.
RunConfig
.
Comm
.
SSHPort
,
b
.
config
.
SSHPrivateIp
),
SSHConfig
:
awscommon
.
SSHConfig
(
b
.
config
.
RunConfig
.
Comm
.
SSHUsername
),
},
&
common
.
StepProvision
{},
&
stepStopInstance
{
SpotPrice
:
b
.
config
.
SpotPrice
},
...
...
builder/amazon/instance/builder.go
View file @
e5579281
...
...
@@ -13,6 +13,7 @@ import (
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/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"
...
...
@@ -175,11 +176,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Debug
:
b
.
config
.
PackerDebug
,
DebugKeyPath
:
fmt
.
Sprintf
(
"ec2_%s.pem"
,
b
.
config
.
PackerBuildName
),
KeyPairName
:
b
.
config
.
TemporaryKeyPairName
,
PrivateKeyFile
:
b
.
config
.
SSHPrivateKeyFile
,
PrivateKeyFile
:
b
.
config
.
RunConfig
.
Comm
.
SSHPrivateKey
,
},
&
awscommon
.
StepSecurityGroup
{
SecurityGroupIds
:
b
.
config
.
SecurityGroupIds
,
SSHPort
:
b
.
config
.
SSHPort
,
SSHPort
:
b
.
config
.
RunConfig
.
Comm
.
SSHPort
,
VpcId
:
b
.
config
.
VpcId
,
},
&
awscommon
.
StepRunSourceInstance
{
...
...
@@ -197,11 +198,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BlockDevices
:
b
.
config
.
BlockDevices
,
Tags
:
b
.
config
.
RunTags
,
},
&
common
.
StepConnectSSH
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
RunConfig
.
Comm
,
SSHAddress
:
awscommon
.
SSHAddress
(
ec2conn
,
b
.
config
.
SSHPort
,
b
.
config
.
SSHPrivateIp
),
SSHConfig
:
awscommon
.
SSHConfig
(
b
.
config
.
SSHUsername
),
SSHWaitTimeout
:
b
.
config
.
SSHTimeout
(),
ec2conn
,
b
.
config
.
RunConfig
.
Comm
.
SSHPort
,
b
.
config
.
SSHPrivateIp
),
SSHConfig
:
awscommon
.
SSHConfig
(
b
.
config
.
RunConfig
.
Comm
.
SSHUsername
),
},
&
common
.
StepProvision
{},
&
StepUploadX509Cert
{},
...
...
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