Commit b6eb3eba authored by Jason A. Beranek's avatar Jason A. Beranek

builder/vmware-esxi: Add configuration options for remote cache path

  Add configuration option to explicitly control where Packer uploads
  ISO and floppy files to on ESXi hosts. The `remote_cache_datastore`
  defaults to the `remote_datastore` value. The 'remote_cache_directory'
  defaults to 'packer_cache', similar to the local caching capabilities.

  Addresses issues with [GH-1218] and [GH-1221] where paths for uploaded
  ISO and floppy files are not written to a valid location in the
  datastore.
parent 0bf293f1
...@@ -47,6 +47,8 @@ type config struct { ...@@ -47,6 +47,8 @@ type config struct {
RemoteType string `mapstructure:"remote_type"` RemoteType string `mapstructure:"remote_type"`
RemoteDatastore string `mapstructure:"remote_datastore"` RemoteDatastore string `mapstructure:"remote_datastore"`
RemoteCacheDatastore string `mapstructure:"remote_cache_datastore"`
RemoteCacheDirectory string `mapstructure:"remote_cache_directory"`
RemoteHost string `mapstructure:"remote_host"` RemoteHost string `mapstructure:"remote_host"`
RemotePort uint `mapstructure:"remote_port"` RemotePort uint `mapstructure:"remote_port"`
RemoteUser string `mapstructure:"remote_username"` RemoteUser string `mapstructure:"remote_username"`
...@@ -118,6 +120,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -118,6 +120,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.RemoteDatastore = "datastore1" b.config.RemoteDatastore = "datastore1"
} }
if b.config.RemoteCacheDatastore == "" {
b.config.RemoteCacheDatastore = b.config.RemoteDatastore
}
if b.config.RemoteCacheDirectory == "" {
b.config.RemoteCacheDirectory = "packer_cache"
}
if b.config.RemotePort == 0 { if b.config.RemotePort == 0 {
b.config.RemotePort = 22 b.config.RemotePort = 22
} }
...@@ -134,6 +144,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -134,6 +144,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
"remote_type": &b.config.RemoteType, "remote_type": &b.config.RemoteType,
"remote_host": &b.config.RemoteHost, "remote_host": &b.config.RemoteHost,
"remote_datastore": &b.config.RemoteDatastore, "remote_datastore": &b.config.RemoteDatastore,
"remote_cache_datastore": &b.config.RemoteCacheDatastore,
"remote_cache_directory": &b.config.RemoteCacheDirectory,
"remote_user": &b.config.RemoteUser, "remote_user": &b.config.RemoteUser,
"remote_password": &b.config.RemotePassword, "remote_password": &b.config.RemotePassword,
} }
......
...@@ -22,6 +22,8 @@ func NewDriver(config *config) (vmwcommon.Driver, error) { ...@@ -22,6 +22,8 @@ func NewDriver(config *config) (vmwcommon.Driver, error) {
Username: config.RemoteUser, Username: config.RemoteUser,
Password: config.RemotePassword, Password: config.RemotePassword,
Datastore: config.RemoteDatastore, Datastore: config.RemoteDatastore,
CacheDatastore: config.RemoteCacheDatastore,
CacheDirectory: config.RemoteCacheDirectory,
}, },
} }
......
...@@ -27,6 +27,8 @@ type ESX5Driver struct { ...@@ -27,6 +27,8 @@ type ESX5Driver struct {
Username string Username string
Password string Password string
Datastore string Datastore string
CacheDatastore string
CacheDirectory string
comm packer.Communicator comm packer.Communicator
outputDir string outputDir string
...@@ -84,13 +86,7 @@ func (d *ESX5Driver) Unregister(vmxPathLocal string) error { ...@@ -84,13 +86,7 @@ func (d *ESX5Driver) Unregister(vmxPathLocal string) error {
} }
func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType string) (string, error) { func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType string) (string, error) {
cacheRoot, _ := filepath.Abs(".") finalPath := d.cachePath(localPath)
targetFile, err := filepath.Rel(cacheRoot, localPath)
if err != nil {
return "", err
}
finalPath := d.datastorePath(targetFile)
if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil { if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil {
return "", err return "", err
} }
...@@ -297,6 +293,10 @@ func (d *ESX5Driver) datastorePath(path string) string { ...@@ -297,6 +293,10 @@ func (d *ESX5Driver) datastorePath(path string) string {
return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.Datastore, baseDir, filepath.Base(path))) return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.Datastore, baseDir, filepath.Base(path)))
} }
func (d *ESX5Driver) cachePath(path string) string {
return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.CacheDatastore, d.CacheDirectory, filepath.Base(path)))
}
func (d *ESX5Driver) connect() error { func (d *ESX5Driver) connect() error {
address := fmt.Sprintf("%s:%d", d.Host, d.Port) address := fmt.Sprintf("%s:%d", d.Host, d.Port)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment