From b6eb3eba1d6a64ad9c3c071fca2429affd939d33 Mon Sep 17 00:00:00 2001 From: "Jason A. Beranek" Date: Wed, 10 Sep 2014 00:10:06 -0500 Subject: [PATCH 1/3] 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. --- builder/vmware/iso/builder.go | 48 +++++++++++++++++++------------ builder/vmware/iso/driver.go | 12 ++++---- builder/vmware/iso/driver_esx5.go | 14 ++++----- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 693d97e9b..00876293a 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -45,12 +45,14 @@ type config struct { SkipCompaction bool `mapstructure:"skip_compaction"` VMXTemplatePath string `mapstructure:"vmx_template_path"` - RemoteType string `mapstructure:"remote_type"` - RemoteDatastore string `mapstructure:"remote_datastore"` - RemoteHost string `mapstructure:"remote_host"` - RemotePort uint `mapstructure:"remote_port"` - RemoteUser string `mapstructure:"remote_username"` - RemotePassword string `mapstructure:"remote_password"` + RemoteType string `mapstructure:"remote_type"` + RemoteDatastore string `mapstructure:"remote_datastore"` + RemoteCacheDatastore string `mapstructure:"remote_cache_datastore"` + RemoteCacheDirectory string `mapstructure:"remote_cache_directory"` + RemoteHost string `mapstructure:"remote_host"` + RemotePort uint `mapstructure:"remote_port"` + RemoteUser string `mapstructure:"remote_username"` + RemotePassword string `mapstructure:"remote_password"` RawSingleISOUrl string `mapstructure:"iso_url"` @@ -118,24 +120,34 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { 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 { b.config.RemotePort = 22 } // Errors templates := map[string]*string{ - "disk_name": &b.config.DiskName, - "guest_os_type": &b.config.GuestOSType, - "iso_checksum": &b.config.ISOChecksum, - "iso_checksum_type": &b.config.ISOChecksumType, - "iso_url": &b.config.RawSingleISOUrl, - "vm_name": &b.config.VMName, - "vmx_template_path": &b.config.VMXTemplatePath, - "remote_type": &b.config.RemoteType, - "remote_host": &b.config.RemoteHost, - "remote_datastore": &b.config.RemoteDatastore, - "remote_user": &b.config.RemoteUser, - "remote_password": &b.config.RemotePassword, + "disk_name": &b.config.DiskName, + "guest_os_type": &b.config.GuestOSType, + "iso_checksum": &b.config.ISOChecksum, + "iso_checksum_type": &b.config.ISOChecksumType, + "iso_url": &b.config.RawSingleISOUrl, + "vm_name": &b.config.VMName, + "vmx_template_path": &b.config.VMXTemplatePath, + "remote_type": &b.config.RemoteType, + "remote_host": &b.config.RemoteHost, + "remote_datastore": &b.config.RemoteDatastore, + "remote_cache_datastore": &b.config.RemoteCacheDatastore, + "remote_cache_directory": &b.config.RemoteCacheDirectory, + "remote_user": &b.config.RemoteUser, + "remote_password": &b.config.RemotePassword, } for n, ptr := range templates { diff --git a/builder/vmware/iso/driver.go b/builder/vmware/iso/driver.go index ebe8d126b..e98019a7e 100644 --- a/builder/vmware/iso/driver.go +++ b/builder/vmware/iso/driver.go @@ -17,11 +17,13 @@ func NewDriver(config *config) (vmwcommon.Driver, error) { drivers = []vmwcommon.Driver{ &ESX5Driver{ - Host: config.RemoteHost, - Port: config.RemotePort, - Username: config.RemoteUser, - Password: config.RemotePassword, - Datastore: config.RemoteDatastore, + Host: config.RemoteHost, + Port: config.RemotePort, + Username: config.RemoteUser, + Password: config.RemotePassword, + Datastore: config.RemoteDatastore, + CacheDatastore: config.RemoteCacheDatastore, + CacheDirectory: config.RemoteCacheDirectory, }, } diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go index 6f35f5272..ee2b78106 100644 --- a/builder/vmware/iso/driver_esx5.go +++ b/builder/vmware/iso/driver_esx5.go @@ -27,6 +27,8 @@ type ESX5Driver struct { Username string Password string Datastore string + CacheDatastore string + CacheDirectory string comm packer.Communicator outputDir string @@ -84,13 +86,7 @@ func (d *ESX5Driver) Unregister(vmxPathLocal string) error { } func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType string) (string, error) { - cacheRoot, _ := filepath.Abs(".") - targetFile, err := filepath.Rel(cacheRoot, localPath) - if err != nil { - return "", err - } - - finalPath := d.datastorePath(targetFile) + finalPath := d.cachePath(localPath) if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil { return "", err } @@ -297,6 +293,10 @@ func (d *ESX5Driver) datastorePath(path string) string { 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 { address := fmt.Sprintf("%s:%d", d.Host, d.Port) From 241398d53eb8456111309bcfda98fa87d659314c Mon Sep 17 00:00:00 2001 From: "Jason A. Beranek" Date: Tue, 14 Oct 2014 21:25:15 -0500 Subject: [PATCH 2/3] website: document vmware-iso remote cache path --- .../docs/builders/vmware-iso.html.markdown | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/website/source/docs/builders/vmware-iso.html.markdown b/website/source/docs/builders/vmware-iso.html.markdown index aeb4c4335..ee17c7dd1 100644 --- a/website/source/docs/builders/vmware-iso.html.markdown +++ b/website/source/docs/builders/vmware-iso.html.markdown @@ -149,6 +149,16 @@ each category, the available options are alphabetized and described. By default this is "output-BUILDNAME" where "BUILDNAME" is the name of the build. +* `remote_cache_datastore` (string) - The path to the datastore where + supporting files will be stored during the build on the remote machine. + By default this is the same as the `remote_datastore` option. This only + has an effect if `remote_type` is enabled. + +* `remote_cache_directory` (string) - The path where the ISO and/or floppy + files will be stored during the build on the remote machine. The path is + relative to the `remote_cache_datastore` on the remote machine. By default + this is "packer_cache". This only has an effect if `remote_type` is enabled. + * `remote_datastore` (string) - The path to the datastore where the resulting VM will be stored when it is built on the remote machine. By default this is "datastore1". This only has an effect if `remote_type` is enabled. @@ -355,6 +365,13 @@ have to modify as well: * `remote_datastore` - The path to the datastore where the VM will be stored on the ESXi machine. +* `remote_cache_datastore` (string) - The path to the datastore where + supporting files will be stored during the build on the remote machine. + +* `remote_cache_directory` (string) - The path where the ISO and/or floppy + files will be stored during the build on the remote machine. The path is + relative to the `remote_cache_datastore` on the remote machine. + * `remote_username` - The SSH username used to access the remote machine. * `remote_password` - The SSH password for access to the remote machine. From 8d398d159db02f669f6445d339b60752a785b3de Mon Sep 17 00:00:00 2001 From: "Jason A. Beranek" Date: Tue, 14 Oct 2014 21:30:17 -0500 Subject: [PATCH 3/3] website: make remote vmware docs consistent --- website/source/docs/builders/vmware-iso.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/source/docs/builders/vmware-iso.html.markdown b/website/source/docs/builders/vmware-iso.html.markdown index ee17c7dd1..a04b586cb 100644 --- a/website/source/docs/builders/vmware-iso.html.markdown +++ b/website/source/docs/builders/vmware-iso.html.markdown @@ -365,10 +365,10 @@ have to modify as well: * `remote_datastore` - The path to the datastore where the VM will be stored on the ESXi machine. -* `remote_cache_datastore` (string) - The path to the datastore where +* `remote_cache_datastore` - The path to the datastore where supporting files will be stored during the build on the remote machine. -* `remote_cache_directory` (string) - The path where the ISO and/or floppy +* `remote_cache_directory` - The path where the ISO and/or floppy files will be stored during the build on the remote machine. The path is relative to the `remote_cache_datastore` on the remote machine.