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
50f8b2c1
Commit
50f8b2c1
authored
Dec 24, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: move outputdir stuff to common
parent
8bd3ca44
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
323 additions
and
9 deletions
+323
-9
builder/vmware/common/output_dir.go
builder/vmware/common/output_dir.go
+15
-0
builder/vmware/common/output_dir_local.go
builder/vmware/common/output_dir_local.go
+53
-0
builder/vmware/common/output_dir_local_test.go
builder/vmware/common/output_dir_local_test.go
+9
-0
builder/vmware/common/step_output_dir.go
builder/vmware/common/step_output_dir.go
+74
-0
builder/vmware/common/step_output_dir_test.go
builder/vmware/common/step_output_dir_test.go
+150
-0
builder/vmware/iso/builder.go
builder/vmware/iso/builder.go
+22
-9
No files found.
builder/vmware/common/output_dir.go
0 → 100644
View file @
50f8b2c1
package
common
// OutputDir is an interface type that abstracts the creation and handling
// of the output directory for VMware-based products. The abstraction is made
// so that the output directory can be properly made on remote (ESXi) based
// VMware products as well as local.
type
OutputDir
interface
{
DirExists
()
(
bool
,
error
)
ListFiles
()
([]
string
,
error
)
MkdirAll
()
error
Remove
(
string
)
error
RemoveAll
()
error
SetOutputDir
(
string
)
String
()
string
}
builder/vmware/common/output_dir_local.go
0 → 100644
View file @
50f8b2c1
package
common
import
(
"os"
"path/filepath"
)
// LocalOutputDir is an OutputDir implementation where the directory
// is on the local machine.
type
LocalOutputDir
struct
{
Dir
string
}
func
(
d
*
LocalOutputDir
)
DirExists
()
(
bool
,
error
)
{
_
,
err
:=
os
.
Stat
(
d
.
Dir
)
return
err
==
nil
,
nil
}
func
(
d
*
LocalOutputDir
)
ListFiles
()
([]
string
,
error
)
{
files
:=
make
([]
string
,
0
,
10
)
visit
:=
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
return
err
}
if
!
info
.
IsDir
()
{
files
=
append
(
files
,
path
)
}
return
nil
}
return
files
,
filepath
.
Walk
(
d
.
Dir
,
visit
)
}
func
(
d
*
LocalOutputDir
)
MkdirAll
()
error
{
return
os
.
MkdirAll
(
d
.
Dir
,
0755
)
}
func
(
d
*
LocalOutputDir
)
Remove
(
path
string
)
error
{
return
os
.
Remove
(
path
)
}
func
(
d
*
LocalOutputDir
)
RemoveAll
()
error
{
return
os
.
RemoveAll
(
d
.
Dir
)
}
func
(
d
*
LocalOutputDir
)
SetOutputDir
(
path
string
)
{
d
.
Dir
=
path
}
func
(
d
*
LocalOutputDir
)
String
()
string
{
return
d
.
Dir
}
builder/vmware/common/output_dir_local_test.go
0 → 100644
View file @
50f8b2c1
package
common
import
(
"testing"
)
func
TestLocalOuputDir_impl
(
t
*
testing
.
T
)
{
var
_
OutputDir
=
new
(
LocalOutputDir
)
}
builder/vmware/
iso/step_prepare
_output_dir.go
→
builder/vmware/
common/step
_output_dir.go
View file @
50f8b2c1
package
iso
package
common
import
(
import
(
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"log"
"time"
"time"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
)
type
stepPrepareOutputDir
struct
{
// StepOutputDir sets up the output directory by creating it if it does
dir
OutputDir
// not exist, deleting it if it does exist and we're forcing, and cleaning
// it up when we're done with it.
type
StepOutputDir
struct
{
Force
bool
success
bool
}
}
func
(
s
*
stepPrepare
OutputDir
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
Step
OutputDir
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
dir
:=
state
.
Get
(
"dir"
)
.
(
OutputDir
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
dir
:=
s
.
outputDir
(
state
)
dir
.
SetOutputDir
(
config
.
OutputDir
)
exists
,
err
:=
dir
.
DirExists
()
exists
,
err
:=
dir
.
DirExists
()
if
err
!=
nil
{
if
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
state
.
Put
(
"error"
,
err
)
...
@@ -26,12 +29,12 @@ func (s *stepPrepareOutputDir) Run(state multistep.StateBag) multistep.StepActio
...
@@ -26,12 +29,12 @@ func (s *stepPrepareOutputDir) Run(state multistep.StateBag) multistep.StepActio
}
}
if
exists
{
if
exists
{
if
config
.
Packer
Force
{
if
s
.
Force
{
ui
.
Say
(
"Deleting previous output directory..."
)
ui
.
Say
(
"Deleting previous output directory..."
)
dir
.
RemoveAll
()
dir
.
RemoveAll
()
}
else
{
}
else
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Output directory '%s' already exists."
,
config
.
OutputDir
))
"Output directory '%s' already exists."
,
dir
.
String
()
))
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
}
}
...
@@ -41,44 +44,31 @@ func (s *stepPrepareOutputDir) Run(state multistep.StateBag) multistep.StepActio
...
@@ -41,44 +44,31 @@ func (s *stepPrepareOutputDir) Run(state multistep.StateBag) multistep.StepActio
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
s
.
dir
=
dir
s
.
success
=
true
state
.
Put
(
"dir"
,
dir
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
func
(
s
*
stepPrepareOutputDir
)
Cleanup
(
state
multistep
.
StateBag
)
{
func
(
s
*
StepOutputDir
)
Cleanup
(
state
multistep
.
StateBag
)
{
if
!
s
.
success
{
return
}
_
,
cancelled
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
_
,
cancelled
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
_
,
halted
:=
state
.
GetOk
(
multistep
.
StateHalted
)
_
,
halted
:=
state
.
GetOk
(
multistep
.
StateHalted
)
if
cancelled
||
halted
{
if
cancelled
||
halted
{
dir
:=
state
.
Get
(
"dir"
)
.
(
OutputDir
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
s
.
dir
!=
nil
{
ui
.
Say
(
"Deleting output directory..."
)
ui
.
Say
(
"Deleting output directory..."
)
for
i
:=
0
;
i
<
5
;
i
++
{
for
i
:=
0
;
i
<
5
;
i
++
{
err
:=
dir
.
RemoveAll
()
err
:=
s
.
dir
.
RemoveAll
()
if
err
==
nil
{
if
err
==
nil
{
break
break
}
log
.
Printf
(
"Error removing output dir: %s"
,
err
)
time
.
Sleep
(
2
*
time
.
Second
)
}
}
}
}
}
func
(
s
*
stepPrepareOutputDir
)
outputDir
(
state
multistep
.
StateBag
)
(
dir
OutputDir
)
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
switch
d
:=
driver
.
(
type
)
{
log
.
Printf
(
"Error removing output dir: %s"
,
err
)
case
OutputDir
:
time
.
Sleep
(
2
*
time
.
Second
)
log
.
Printf
(
"Using driver as the OutputDir implementation"
)
}
dir
=
d
default
:
log
.
Printf
(
"Using localOutputDir implementation"
)
dir
=
new
(
localOutputDir
)
}
}
return
}
}
builder/vmware/common/step_output_dir_test.go
0 → 100644
View file @
50f8b2c1
package
common
import
(
"github.com/mitchellh/multistep"
"io/ioutil"
"os"
"testing"
)
func
testOutputDir
(
t
*
testing
.
T
)
*
LocalOutputDir
{
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
os
.
RemoveAll
(
td
)
return
&
LocalOutputDir
{
Dir
:
td
}
}
func
TestStepOutputDir_impl
(
t
*
testing
.
T
)
{
var
_
multistep
.
Step
=
new
(
StepOutputDir
)
}
func
TestStepOutputDir
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepOutputDir
)
dir
:=
testOutputDir
(
t
)
state
.
Put
(
"dir"
,
dir
)
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
ok
{
t
.
Fatal
(
"should NOT have error"
)
}
if
_
,
err
:=
os
.
Stat
(
dir
.
Dir
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Test the cleanup
step
.
Cleanup
(
state
)
if
_
,
err
:=
os
.
Stat
(
dir
.
Dir
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
func
TestStepOutputDir_existsNoForce
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepOutputDir
)
dir
:=
testOutputDir
(
t
)
state
.
Put
(
"dir"
,
dir
)
// Make sure the dir exists
if
err
:=
os
.
MkdirAll
(
dir
.
Dir
,
0755
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionHalt
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
!
ok
{
t
.
Fatal
(
"should have error"
)
}
// Test the cleanup
step
.
Cleanup
(
state
)
if
_
,
err
:=
os
.
Stat
(
dir
.
Dir
);
err
!=
nil
{
t
.
Fatal
(
"should not delete dir"
)
}
}
func
TestStepOutputDir_existsForce
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepOutputDir
)
step
.
Force
=
true
dir
:=
testOutputDir
(
t
)
state
.
Put
(
"dir"
,
dir
)
// Make sure the dir exists
if
err
:=
os
.
MkdirAll
(
dir
.
Dir
,
0755
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
ok
{
t
.
Fatal
(
"should NOT have error"
)
}
if
_
,
err
:=
os
.
Stat
(
dir
.
Dir
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
func
TestStepOutputDir_cancel
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepOutputDir
)
dir
:=
testOutputDir
(
t
)
state
.
Put
(
"dir"
,
dir
)
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
ok
{
t
.
Fatal
(
"should NOT have error"
)
}
if
_
,
err
:=
os
.
Stat
(
dir
.
Dir
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Test cancel/halt
state
.
Put
(
multistep
.
StateCancelled
,
true
)
step
.
Cleanup
(
state
)
if
_
,
err
:=
os
.
Stat
(
dir
.
Dir
);
err
==
nil
{
t
.
Fatal
(
"directory should not exist"
)
}
}
func
TestStepOutputDir_halt
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepOutputDir
)
dir
:=
testOutputDir
(
t
)
state
.
Put
(
"dir"
,
dir
)
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
ok
{
t
.
Fatal
(
"should NOT have error"
)
}
if
_
,
err
:=
os
.
Stat
(
dir
.
Dir
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Test cancel/halt
state
.
Put
(
multistep
.
StateHalted
,
true
)
step
.
Cleanup
(
state
)
if
_
,
err
:=
os
.
Stat
(
dir
.
Dir
);
err
==
nil
{
t
.
Fatal
(
"directory should not exist"
)
}
}
builder/vmware/iso/builder.go
View file @
50f8b2c1
...
@@ -346,6 +346,25 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -346,6 +346,25 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return
nil
,
fmt
.
Errorf
(
"Failed creating VMware driver: %s"
,
err
)
return
nil
,
fmt
.
Errorf
(
"Failed creating VMware driver: %s"
,
err
)
}
}
// Determine the output dir implementation
var
dir
OutputDir
switch
d
:=
driver
.
(
type
)
{
case
OutputDir
:
dir
=
d
default
:
dir
=
new
(
vmwcommon
.
LocalOutputDir
)
}
dir
.
SetOutputDir
(
b
.
config
.
OutputDir
)
// Setup the state bag
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"cache"
,
cache
)
state
.
Put
(
"config"
,
&
b
.
config
)
state
.
Put
(
"dir"
,
dir
)
state
.
Put
(
"driver"
,
driver
)
state
.
Put
(
"hook"
,
hook
)
state
.
Put
(
"ui"
,
ui
)
// Seed the random number generator
// Seed the random number generator
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
...
@@ -358,7 +377,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -358,7 +377,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ResultKey
:
"iso_path"
,
ResultKey
:
"iso_path"
,
Url
:
b
.
config
.
ISOUrls
,
Url
:
b
.
config
.
ISOUrls
,
},
},
&
stepPrepareOutputDir
{},
&
vmwcommon
.
StepOutputDir
{
Force
:
b
.
config
.
PackerForce
,
},
&
common
.
StepCreateFloppy
{
&
common
.
StepCreateFloppy
{
Files
:
b
.
config
.
FloppyFiles
,
Files
:
b
.
config
.
FloppyFiles
,
},
},
...
@@ -390,14 +411,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -390,14 +411,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
stepCompactDisk
{},
&
stepCompactDisk
{},
}
}
// Setup the state bag
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"cache"
,
cache
)
state
.
Put
(
"config"
,
&
b
.
config
)
state
.
Put
(
"driver"
,
driver
)
state
.
Put
(
"hook"
,
hook
)
state
.
Put
(
"ui"
,
ui
)
// Run!
// Run!
if
b
.
config
.
PackerDebug
{
if
b
.
config
.
PackerDebug
{
b
.
runner
=
&
multistep
.
DebugRunner
{
b
.
runner
=
&
multistep
.
DebugRunner
{
...
...
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