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
64ced7ff
Commit
64ced7ff
authored
Jul 20, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon: extract StepRunSourceInstance
parent
30ab7038
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
20 deletions
+34
-20
builder/amazon/common/instance.go
builder/amazon/common/instance.go
+2
-2
builder/amazon/common/step_run_source_instance.go
builder/amazon/common/step_run_source_instance.go
+17
-13
builder/amazon/common/step_security_group.go
builder/amazon/common/step_security_group.go
+1
-1
builder/amazon/ebs/builder.go
builder/amazon/ebs/builder.go
+6
-2
builder/amazon/ebs/step_stop_instance.go
builder/amazon/ebs/step_stop_instance.go
+2
-1
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+6
-1
No files found.
builder/amazon/
ebs
/instance.go
→
builder/amazon/
common
/instance.go
View file @
64ced7ff
package
ebs
package
common
import
(
"fmt"
...
...
@@ -7,7 +7,7 @@ import (
"time"
)
func
w
aitForState
(
ec2conn
*
ec2
.
EC2
,
originalInstance
*
ec2
.
Instance
,
pending
[]
string
,
target
string
)
(
i
*
ec2
.
Instance
,
err
error
)
{
func
W
aitForState
(
ec2conn
*
ec2
.
EC2
,
originalInstance
*
ec2
.
Instance
,
pending
[]
string
,
target
string
)
(
i
*
ec2
.
Instance
,
err
error
)
{
log
.
Printf
(
"Waiting for instance state to become: %s"
,
target
)
i
=
originalInstance
...
...
builder/amazon/
ebs
/step_run_source_instance.go
→
builder/amazon/
common
/step_run_source_instance.go
View file @
64ced7ff
package
ebs
package
common
import
(
"fmt"
...
...
@@ -8,12 +8,15 @@ import (
"log"
)
type
stepRunSourceInstance
struct
{
type
StepRunSourceInstance
struct
{
ExpectedRootDevice
string
InstanceType
string
SourceAMI
string
instance
*
ec2
.
Instance
}
func
(
s
*
stepRunSourceInstance
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
config
)
func
(
s
*
StepRunSourceInstance
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
keyName
:=
state
[
"keyPair"
]
.
(
string
)
securityGroupId
:=
state
[
"securityGroupId"
]
.
(
string
)
...
...
@@ -21,8 +24,8 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
runOpts
:=
&
ec2
.
RunInstances
{
KeyName
:
keyName
,
ImageId
:
config
.
SourceAmi
,
InstanceType
:
config
.
InstanceType
,
ImageId
:
s
.
SourceAMI
,
InstanceType
:
s
.
InstanceType
,
MinCount
:
0
,
MaxCount
:
0
,
SecurityGroups
:
[]
ec2
.
SecurityGroup
{
ec2
.
SecurityGroup
{
Id
:
securityGroupId
}},
...
...
@@ -30,16 +33,17 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
}
ui
.
Say
(
"Launching a source AWS instance..."
)
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
config
.
SourceAmi
},
ec2
.
NewFilter
())
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
s
.
SourceAMI
},
ec2
.
NewFilter
())
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"There was a problem with the source AMI: %s"
,
err
)
return
multistep
.
ActionHalt
}
if
imageResp
.
Images
[
0
]
.
RootDeviceType
!=
"ebs"
{
if
s
.
ExpectedRootDevice
!=
""
&&
imageResp
.
Images
[
0
]
.
RootDeviceType
!=
s
.
ExpectedRootDevice
{
state
[
"error"
]
=
fmt
.
Errorf
(
"The provided source AMI is instance-store based. The
\n
"
+
"amazon-ebs bundler can only work with EBS based AMIs."
)
"The provided source AMI has an invalid root device type.
\n
"
+
"Expected '%s', got '%s'."
,
s
.
ExpectedRootDevice
,
imageResp
.
Images
[
0
]
.
RootDeviceType
)
return
multistep
.
ActionHalt
}
...
...
@@ -55,7 +59,7 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
log
.
Printf
(
"instance id: %s"
,
s
.
instance
.
InstanceId
)
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting for instance (%s) to become ready..."
,
s
.
instance
.
InstanceId
))
s
.
instance
,
err
=
w
aitForState
(
ec2conn
,
s
.
instance
,
[]
string
{
"pending"
},
"running"
)
s
.
instance
,
err
=
W
aitForState
(
ec2conn
,
s
.
instance
,
[]
string
{
"pending"
},
"running"
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for instance (%s) to become ready: %s"
,
s
.
instance
.
InstanceId
,
err
)
state
[
"error"
]
=
err
...
...
@@ -68,7 +72,7 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
return
multistep
.
ActionContinue
}
func
(
s
*
s
tepRunSourceInstance
)
Cleanup
(
state
map
[
string
]
interface
{})
{
func
(
s
*
S
tepRunSourceInstance
)
Cleanup
(
state
map
[
string
]
interface
{})
{
if
s
.
instance
==
nil
{
return
}
...
...
@@ -83,5 +87,5 @@ func (s *stepRunSourceInstance) Cleanup(state map[string]interface{}) {
}
pending
:=
[]
string
{
"pending"
,
"running"
,
"shutting-down"
,
"stopped"
,
"stopping"
}
w
aitForState
(
ec2conn
,
s
.
instance
,
pending
,
"terminated"
)
W
aitForState
(
ec2conn
,
s
.
instance
,
pending
,
"terminated"
)
}
builder/amazon/common/step_security_group.go
View file @
64ced7ff
...
...
@@ -12,7 +12,7 @@ import (
type
StepSecurityGroup
struct
{
SecurityGroupId
string
SSHPort
int
SSHPort
int
createdGroupId
string
}
...
...
builder/amazon/ebs/builder.go
View file @
64ced7ff
...
...
@@ -93,9 +93,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
awscommon
.
StepKeyPair
{},
&
awscommon
.
StepSecurityGroup
{
SecurityGroupId
:
b
.
config
.
SecurityGroupId
,
SSHPort
:
b
.
config
.
SSHPort
,
SSHPort
:
b
.
config
.
SSHPort
,
},
&
awscommon
.
StepRunSourceInstance
{
ExpectedRootDevice
:
"ebs"
,
InstanceType
:
b
.
config
.
InstanceType
,
SourceAMI
:
b
.
config
.
SourceAmi
,
},
&
stepRunSourceInstance
{},
&
common
.
StepConnectSSH
{
SSHAddress
:
sshAddress
,
SSHConfig
:
sshConfig
,
...
...
builder/amazon/ebs/step_stop_instance.go
View file @
64ced7ff
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/packer"
)
...
...
@@ -26,7 +27,7 @@ func (s *stepStopInstance) Run(state map[string]interface{}) multistep.StepActio
// Wait for the instance to actual stop
ui
.
Say
(
"Waiting for the instance to stop..."
)
instance
,
err
=
w
aitForState
(
ec2conn
,
instance
,
[]
string
{
"running"
,
"stopping"
},
"stopped"
)
instance
,
err
=
awscommon
.
W
aitForState
(
ec2conn
,
instance
,
[]
string
{
"running"
,
"stopping"
},
"stopped"
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for instance to stop: %s"
,
err
)
state
[
"error"
]
=
err
...
...
builder/amazon/instance/builder.go
View file @
64ced7ff
...
...
@@ -72,7 +72,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
awscommon
.
StepKeyPair
{},
&
awscommon
.
StepSecurityGroup
{
SecurityGroupId
:
b
.
config
.
SecurityGroupId
,
SSHPort
:
b
.
config
.
SSHPort
,
SSHPort
:
b
.
config
.
SSHPort
,
},
&
awscommon
.
StepRunSourceInstance
{
ExpectedRootDevice
:
"instance-store"
,
InstanceType
:
b
.
config
.
InstanceType
,
SourceAMI
:
b
.
config
.
SourceAmi
,
},
}
...
...
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