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
033218df
Commit
033218df
authored
Jul 29, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/chroot: Attach volume
parent
12e7042c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
1 deletion
+117
-1
builder/amazon/chroot/builder.go
builder/amazon/chroot/builder.go
+1
-1
builder/amazon/chroot/step_attach_volume.go
builder/amazon/chroot/step_attach_volume.go
+115
-0
builder/amazon/chroot/step_create_volume.go
builder/amazon/chroot/step_create_volume.go
+1
-0
No files found.
builder/amazon/chroot/builder.go
View file @
033218df
...
...
@@ -75,7 +75,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
StepInstanceInfo
{},
&
StepSourceAMIInfo
{},
&
StepCreateVolume
{},
//
&StepAttachVolume{},
&
StepAttachVolume
{},
}
// Run!
...
...
builder/amazon/chroot/step_attach_volume.go
0 → 100644
View file @
033218df
package
chroot
import
(
"errors"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/packer"
)
// StepAttachVolume attaches the previously created volume to an
// available device location.
//
// Produces:
// volume_id string - The ID of the created volume
type
StepAttachVolume
struct
{
attached
bool
volumeId
string
}
func
(
s
*
StepAttachVolume
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
instance
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
volumeId
:=
state
[
"volume_id"
]
.
(
string
)
device
:=
"/dev/sdh"
ui
.
Say
(
"Attaching the root volume..."
)
_
,
err
:=
ec2conn
.
AttachVolume
(
volumeId
,
instance
.
InstanceId
,
device
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error attaching volume: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// Mark that we attached it so we can detach it later
s
.
attached
=
true
s
.
volumeId
=
volumeId
// Wait for the volume to become attached
stateChange
:=
awscommon
.
StateChangeConf
{
Conn
:
ec2conn
,
Pending
:
[]
string
{
"attaching"
},
StepState
:
state
,
Target
:
"attached"
,
Refresh
:
func
()
(
interface
{},
string
,
error
)
{
resp
,
err
:=
ec2conn
.
Volumes
([]
string
{
volumeId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
return
nil
,
""
,
err
}
if
len
(
resp
.
Volumes
[
0
]
.
Attachments
)
==
0
{
return
nil
,
""
,
errors
.
New
(
"No attachments on volume."
)
}
return
nil
,
resp
.
Volumes
[
0
]
.
Attachments
[
0
]
.
Status
,
nil
},
}
_
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for volume: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
s
*
StepAttachVolume
)
Cleanup
(
state
map
[
string
]
interface
{})
{
if
!
s
.
attached
{
return
}
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
.
Say
(
"Detaching EBS volume..."
)
_
,
err
:=
ec2conn
.
DetachVolume
(
s
.
volumeId
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error detaching EBS volume: %s"
,
err
))
return
}
// Wait for the volume to detach
stateChange
:=
awscommon
.
StateChangeConf
{
Conn
:
ec2conn
,
Pending
:
[]
string
{
"detaching"
},
StepState
:
state
,
Target
:
"detached"
,
Refresh
:
func
()
(
interface
{},
string
,
error
)
{
resp
,
err
:=
ec2conn
.
Volumes
([]
string
{
s
.
volumeId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
return
nil
,
""
,
err
}
state
:=
"detached"
if
len
(
resp
.
Volumes
[
0
]
.
Attachments
)
>
0
{
state
=
resp
.
Volumes
[
0
]
.
Attachments
[
0
]
.
Status
}
return
nil
,
state
,
nil
},
}
_
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error waiting for volume: %s"
,
err
))
return
}
}
builder/amazon/chroot/step_create_volume.go
View file @
033218df
...
...
@@ -86,6 +86,7 @@ func (s *StepCreateVolume) Run(state map[string]interface{}) multistep.StepActio
return
multistep
.
ActionHalt
}
state
[
"volume_id"
]
=
s
.
volumeId
return
multistep
.
ActionContinue
}
...
...
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