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
0b830c92
Commit
0b830c92
authored
Aug 31, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: Use new multistep API
parent
1a2af970
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
38 deletions
+39
-38
common/multistep_debug.go
common/multistep_debug.go
+2
-2
common/step_connect_ssh.go
common/step_connect_ssh.go
+8
-8
common/step_create_floppy.go
common/step_create_floppy.go
+12
-11
common/step_download.go
common/step_download.go
+10
-10
common/step_provision.go
common/step_provision.go
+7
-7
No files found.
common/multistep_debug.go
View file @
0b830c92
...
...
@@ -11,7 +11,7 @@ import (
// MultistepDebugFn will return a proper multistep.DebugPauseFn to
// use for debugging if you're using multistep in your builder.
func
MultistepDebugFn
(
ui
packer
.
Ui
)
multistep
.
DebugPauseFn
{
return
func
(
loc
multistep
.
DebugLocation
,
name
string
,
state
m
ap
[
string
]
interface
{}
)
{
return
func
(
loc
multistep
.
DebugLocation
,
name
string
,
state
m
ultistep
.
StateBag
)
{
var
locationString
string
switch
loc
{
case
multistep
.
DebugLocationAfterRun
:
...
...
@@ -41,7 +41,7 @@ func MultistepDebugFn(ui packer.Ui) multistep.DebugPauseFn {
case
<-
result
:
return
case
<-
time
.
After
(
100
*
time
.
Millisecond
)
:
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
;
ok
{
return
}
}
...
...
common/step_connect_ssh.go
View file @
0b830c92
...
...
@@ -25,11 +25,11 @@ type StepConnectSSH struct {
// SSHAddress is a function that returns the TCP address to connect to
// for SSH. This is a function so that you can query information
// if necessary for this address.
SSHAddress
func
(
m
ap
[
string
]
interface
{}
)
(
string
,
error
)
SSHAddress
func
(
m
ultistep
.
StateBag
)
(
string
,
error
)
// SSHConfig is a function that returns the proper client configuration
// for SSH access.
SSHConfig
func
(
m
ap
[
string
]
interface
{}
)
(
*
gossh
.
ClientConfig
,
error
)
SSHConfig
func
(
m
ultistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
// SSHWaitTimeout is the total timeout to wait for SSH to become available.
SSHWaitTimeout
time
.
Duration
...
...
@@ -40,8 +40,8 @@ type StepConnectSSH struct {
comm
packer
.
Communicator
}
func
(
s
*
StepConnectSSH
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
StepConnectSSH
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
var
comm
packer
.
Communicator
var
err
error
...
...
@@ -69,14 +69,14 @@ WaitLoop:
ui
.
Say
(
"Connected to SSH!"
)
s
.
comm
=
comm
state
[
"communicator"
]
=
comm
state
.
Put
(
"communicator"
,
comm
)
break
WaitLoop
case
<-
timeout
:
ui
.
Error
(
"Timeout waiting for SSH."
)
close
(
cancel
)
return
multistep
.
ActionHalt
case
<-
time
.
After
(
1
*
time
.
Second
)
:
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
;
ok
{
// The step sequence was cancelled, so cancel waiting for SSH
// and just start the halting process.
close
(
cancel
)
...
...
@@ -89,10 +89,10 @@ WaitLoop:
return
multistep
.
ActionContinue
}
func
(
s
*
StepConnectSSH
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepConnectSSH
)
Cleanup
(
m
ultistep
.
StateBag
)
{
}
func
(
s
*
StepConnectSSH
)
waitForSSH
(
state
m
ap
[
string
]
interface
{}
,
cancel
<-
chan
struct
{})
(
packer
.
Communicator
,
error
)
{
func
(
s
*
StepConnectSSH
)
waitForSSH
(
state
m
ultistep
.
StateBag
,
cancel
<-
chan
struct
{})
(
packer
.
Communicator
,
error
)
{
handshakeAttempts
:=
0
var
comm
packer
.
Communicator
...
...
common/step_create_floppy.go
View file @
0b830c92
...
...
@@ -22,19 +22,20 @@ type StepCreateFloppy struct {
floppyPath
string
}
func
(
s
*
StepCreateFloppy
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
StepCreateFloppy
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
if
len
(
s
.
Files
)
==
0
{
log
.
Println
(
"No floppy files specified. Floppy disk will not be made."
)
return
multistep
.
ActionContinue
}
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Creating floppy disk..."
)
// Create a temporary file to be our floppy drive
floppyF
,
err
:=
ioutil
.
TempFile
(
""
,
"packer"
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error creating temporary file for floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error creating temporary file for floppy: %s"
,
err
))
return
multistep
.
ActionHalt
}
defer
floppyF
.
Close
()
...
...
@@ -46,7 +47,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
// Set the size of the file to be a floppy sized
if
err
:=
floppyF
.
Truncate
(
1440
*
1024
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -54,7 +55,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
log
.
Println
(
"Initializing block device backed by temporary file"
)
device
,
err
:=
fs
.
NewFileDisk
(
floppyF
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -66,7 +67,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
OEMName
:
"packer"
,
}
if
fat
.
FormatSuperFloppy
(
device
,
formatConfig
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -74,7 +75,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
log
.
Println
(
"Initializing FAT filesystem on block device"
)
fatFs
,
err
:=
fat
.
New
(
device
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -82,7 +83,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
log
.
Println
(
"Reading the root directory from the filesystem"
)
rootDir
,
err
:=
fatFs
.
RootDir
()
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error creating floppy: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -90,18 +91,18 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
for
_
,
filename
:=
range
s
.
Files
{
ui
.
Message
(
fmt
.
Sprintf
(
"Copying: %s"
,
filepath
.
Base
(
filename
)))
if
s
.
addSingleFile
(
rootDir
,
filename
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error adding file to floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error adding file to floppy: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
}
// Set the path to the floppy so it can be used later
state
[
"floppy_path"
]
=
s
.
floppyPath
state
.
Put
(
"floppy_path"
,
s
.
floppyPath
)
return
multistep
.
ActionContinue
}
func
(
s
*
StepCreateFloppy
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
StepCreateFloppy
)
Cleanup
(
m
ultistep
.
StateBag
)
{
if
s
.
floppyPath
!=
""
{
log
.
Printf
(
"Deleting floppy disk: %s"
,
s
.
floppyPath
)
os
.
Remove
(
s
.
floppyPath
)
...
...
common/step_download.go
View file @
0b830c92
...
...
@@ -37,16 +37,16 @@ type StepDownload struct {
Url
[]
string
}
func
(
s
*
StepDownload
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
cache
:=
state
[
"cache"
]
.
(
packer
.
Cache
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
StepDownload
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
cache
:=
state
.
Get
(
"cache"
)
.
(
packer
.
Cache
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
var
checksum
[]
byte
if
s
.
Checksum
!=
""
{
var
err
error
checksum
,
err
=
hex
.
DecodeString
(
s
.
Checksum
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error parsing checksum: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error parsing checksum: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
}
...
...
@@ -89,20 +89,20 @@ func (s *StepDownload) Run(state map[string]interface{}) multistep.StepAction {
if
finalPath
==
""
{
err
:=
fmt
.
Errorf
(
"%s download failed."
,
s
.
Description
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
state
[
s
.
ResultKey
]
=
finalPath
state
.
Put
(
s
.
ResultKey
,
finalPath
)
return
multistep
.
ActionContinue
}
func
(
s
*
StepDownload
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
StepDownload
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
func
(
s
*
StepDownload
)
download
(
config
*
DownloadConfig
,
state
m
ap
[
string
]
interface
{}
)
(
string
,
error
,
bool
)
{
func
(
s
*
StepDownload
)
download
(
config
*
DownloadConfig
,
state
m
ultistep
.
StateBag
)
(
string
,
error
,
bool
)
{
var
path
string
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
download
:=
NewDownloadClient
(
config
)
downloadCompleteCh
:=
make
(
chan
error
,
1
)
...
...
@@ -129,7 +129,7 @@ func (s *StepDownload) download(config *DownloadConfig, state map[string]interfa
ui
.
Message
(
fmt
.
Sprintf
(
"Download progress: %d%%"
,
progress
))
}
case
<-
time
.
After
(
1
*
time
.
Second
)
:
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
;
ok
{
ui
.
Say
(
"Interrupt received. Cancelling download..."
)
return
""
,
nil
,
false
}
...
...
common/step_provision.go
View file @
0b830c92
...
...
@@ -18,10 +18,10 @@ import (
// <nothing>
type
StepProvision
struct
{}
func
(
*
StepProvision
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
hook
:=
state
[
"hook"
]
.
(
packer
.
Hook
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
*
StepProvision
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
hook
:=
state
.
Get
(
"hook"
)
.
(
packer
.
Hook
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// Run the provisioner in a goroutine so we can continually check
// for cancellations...
...
...
@@ -35,13 +35,13 @@ func (*StepProvision) Run(state map[string]interface{}) multistep.StepAction {
select
{
case
err
:=
<-
errCh
:
if
err
!=
nil
{
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
case
<-
time
.
After
(
1
*
time
.
Second
)
:
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
;
ok
{
log
.
Println
(
"Cancelling provisioning due to interrupt..."
)
hook
.
Cancel
()
return
multistep
.
ActionHalt
...
...
@@ -50,4 +50,4 @@ func (*StepProvision) Run(state map[string]interface{}) multistep.StepAction {
}
}
func
(
*
StepProvision
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
*
StepProvision
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
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