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
1d3038dd
Commit
1d3038dd
authored
Nov 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #619 from dougm/esx-paths
builder/vmware: Path related fixes in esx5 driver
parents
508cf7e8
4af1c7f1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
48 deletions
+89
-48
builder/vmware/builder.go
builder/vmware/builder.go
+2
-15
builder/vmware/driver_esx5.go
builder/vmware/driver_esx5.go
+31
-3
builder/vmware/output_dir.go
builder/vmware/output_dir.go
+23
-0
builder/vmware/step_clean_files.go
builder/vmware/step_clean_files.go
+22
-27
builder/vmware/step_prepare_output_dir.go
builder/vmware/step_prepare_output_dir.go
+11
-3
No files found.
builder/vmware/builder.go
View file @
1d3038dd
...
...
@@ -10,7 +10,6 @@ import (
"log"
"math/rand"
"os"
"path/filepath"
"strings"
"text/template"
"time"
...
...
@@ -459,20 +458,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}
// Compile the artifact list
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
}
if
err
:=
filepath
.
Walk
(
b
.
config
.
OutputDir
,
visit
);
err
!=
nil
{
files
,
err
:=
state
.
Get
(
"dir"
)
.
(
OutputDir
)
.
ListFiles
()
if
err
!=
nil
{
return
nil
,
err
}
...
...
builder/vmware/driver_esx5.go
View file @
1d3038dd
package
vmware
import
(
"bufio"
"bytes"
gossh
"code.google.com/p/go.crypto/ssh"
"encoding/csv"
...
...
@@ -42,7 +43,7 @@ func (d *ESX5Driver) CreateDisk(diskPathLocal string, size string, typeId string
}
func
(
d
*
ESX5Driver
)
IsRunning
(
vmxPathLocal
string
)
(
bool
,
error
)
{
vmxPath
:=
d
.
datastorePath
(
vmxPathLocal
)
vmxPath
:=
filepath
.
Join
(
d
.
outputDir
,
filepath
.
Base
(
vmxPathLocal
)
)
state
,
err
:=
d
.
run
(
nil
,
"vim-cmd"
,
"vmsvc/power.getstate"
,
vmxPath
)
if
err
!=
nil
{
return
false
,
err
...
...
@@ -84,11 +85,11 @@ func (d *ESX5Driver) UploadISO(localPath string) (string, error) {
return
""
,
err
}
if
err
:=
d
.
mkdir
(
filepath
.
Dir
(
targetFile
));
err
!=
nil
{
finalPath
:=
d
.
datastorePath
(
targetFile
)
if
err
:=
d
.
mkdir
(
filepath
.
Dir
(
finalPath
));
err
!=
nil
{
return
""
,
err
}
finalPath
:=
d
.
datastorePath
(
targetFile
)
if
err
:=
d
.
upload
(
finalPath
,
localPath
);
err
!=
nil
{
return
""
,
err
}
...
...
@@ -214,10 +215,37 @@ func (d *ESX5Driver) DirExists() (bool, error) {
return
err
==
nil
,
nil
}
func
(
d
*
ESX5Driver
)
ListFiles
()
([]
string
,
error
)
{
stdout
,
err
:=
d
.
ssh
(
"ls -1p "
+
d
.
outputDir
,
nil
)
if
err
!=
nil
{
return
nil
,
err
}
files
:=
make
([]
string
,
0
,
10
)
reader
:=
bufio
.
NewReader
(
stdout
)
for
{
line
,
_
,
err
:=
reader
.
ReadLine
()
if
err
==
io
.
EOF
{
break
}
if
line
[
len
(
line
)
-
1
]
==
'/'
{
continue
}
files
=
append
(
files
,
filepath
.
Join
(
d
.
outputDir
,
string
(
line
)))
}
return
files
,
nil
}
func
(
d
*
ESX5Driver
)
MkdirAll
()
error
{
return
d
.
mkdir
(
d
.
outputDir
)
}
func
(
d
*
ESX5Driver
)
Remove
(
path
string
)
error
{
return
d
.
sh
(
"rm"
,
path
)
}
func
(
d
*
ESX5Driver
)
RemoveAll
()
error
{
return
d
.
sh
(
"rm"
,
"-rf"
,
d
.
outputDir
)
}
...
...
builder/vmware/output_dir.go
View file @
1d3038dd
...
...
@@ -2,6 +2,7 @@ package vmware
import
(
"os"
"path/filepath"
)
// OutputDir is an interface type that abstracts the creation and handling
...
...
@@ -10,7 +11,9 @@ import (
// VMware products as well as local.
type
OutputDir
interface
{
DirExists
()
(
bool
,
error
)
ListFiles
()
([]
string
,
error
)
MkdirAll
()
error
Remove
(
string
)
error
RemoveAll
()
error
SetOutputDir
(
string
)
}
...
...
@@ -26,10 +29,30 @@ func (d *localOutputDir) DirExists() (bool, error) {
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
)
}
...
...
builder/vmware/step_clean_files.go
View file @
1d3038dd
...
...
@@ -4,7 +4,6 @@ import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os"
"path/filepath"
)
...
...
@@ -16,7 +15,7 @@ var KeepFileExtensions = []string{".nvram", ".vmdk", ".vmsd", ".vmx", ".vmxf"}
// This step removes unnecessary files from the final result.
//
// Uses:
//
config *config
//
dir OutputDir
// ui packer.Ui
//
// Produces:
...
...
@@ -24,39 +23,35 @@ var KeepFileExtensions = []string{".nvram", ".vmdk", ".vmsd", ".vmx", ".vmxf"}
type
stepCleanFiles
struct
{}
func
(
stepCleanFiles
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
dir
:=
state
.
Get
(
"dir"
)
.
(
OutputDir
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Deleting unnecessary VMware files..."
)
visit
:=
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
return
err
}
files
,
err
:=
dir
.
ListFiles
()
if
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
if
!
info
.
IsDir
()
{
// If the file isn't critical to the function of the
// virtual machine, we get rid of it.
keep
:=
false
ext
:=
filepath
.
Ext
(
path
)
for
_
,
goodExt
:=
range
KeepFileExtensions
{
if
goodExt
==
ext
{
keep
=
true
break
}
for
_
,
path
:=
range
files
{
// If the file isn't critical to the function of the
// virtual machine, we get rid of it.
keep
:=
false
ext
:=
filepath
.
Ext
(
path
)
for
_
,
goodExt
:=
range
KeepFileExtensions
{
if
goodExt
==
ext
{
keep
=
true
break
}
}
if
!
keep
{
ui
.
Message
(
fmt
.
Sprintf
(
"Deleting: %s"
,
path
))
return
os
.
Remove
(
path
)
if
!
keep
{
ui
.
Message
(
fmt
.
Sprintf
(
"Deleting: %s"
,
path
))
if
err
=
dir
.
Remove
(
path
);
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
}
return
nil
}
if
err
:=
filepath
.
Walk
(
config
.
OutputDir
,
visit
);
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
...
...
builder/vmware/step_prepare_output_dir.go
View file @
1d3038dd
package
vmware
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
...
...
@@ -24,9 +25,14 @@ func (s *stepPrepareOutputDir) Run(state multistep.StateBag) multistep.StepActio
return
multistep
.
ActionHalt
}
if
exists
&&
config
.
PackerForce
{
ui
.
Say
(
"Deleting previous output directory..."
)
dir
.
RemoveAll
()
if
exists
{
if
config
.
PackerForce
{
ui
.
Say
(
"Deleting previous output directory..."
)
dir
.
RemoveAll
()
}
else
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Output directory '%s' already exists."
,
config
.
OutputDir
))
return
multistep
.
ActionHalt
}
}
if
err
:=
dir
.
MkdirAll
();
err
!=
nil
{
...
...
@@ -36,6 +42,8 @@ func (s *stepPrepareOutputDir) Run(state multistep.StateBag) multistep.StepActio
s
.
dir
=
dir
state
.
Put
(
"dir"
,
dir
)
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