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